Applying for PR in Germany depends on your status, and the period you spent in Germany:
if you are a skilled worker, you can apply after four years.
if you are a researcher, you can apply after four years.
if you are a skilled worker, and has vocational training, or a German university degree, you can apply after two years.
if you are an EU Blue Cardholder, you can apply after 33 months.
If you are an adequate speaker of the German language, you can apply after 21 months.
if you are self-employed, you can apply after three years.
if you are a freelancer, you can apply after five years.
if you are the family member of a German national, you can apply after three years.
if you are a refugee, you can apply after five years, and if you are fluent in German and can able to earn your own living you can apply after three years.