Search code examples
airflow

How to edit airflow.cfg before running airflow db init?


When setting up Airflow, do I have to run airflow db init twice?

  • Once with the default settings (SQL Lite etc.) in airflow.cfg
  • Second time with my changes in airflow.cfg

It seems to cause errors when starting the services (webserver and scheduler).

I set up AIRFLOW_HOME folder

Running airflow db init will populate my AIRFLOW_HOME folder with a clean setup for Airflow, including airflow.cfg file.

Since I will use PostgreSQL instead of SQL Lite (default), I'm instructed to do the following changes in airflow.cfg

executor = LocalExecutor

# under [database]
sql_alchemy_conn = postgresql+psycopg2://airflow:airflow@localhost/airflow

I ran airflow db init once after setting AIRFLOW_HOME and then after making the changes.

Now I get the following errors when running airflow webserver:

enter image description here


Solution

  • Probably too late for OP but hopefully helpful for others...

    As described in the documentation, you can generate a configuration file pre-populated with all the defaults using:

    airflow config list --defaults > airflow.cfg
    

    Run this in the airflow home directory after doing pip install apache-airflow but before airflow db migrate (airflow db init as used in the original question is deprecated).

    This results in a file airflow.cfg containing commented-out configurations for all the defaults. To override a default (such as sql_alchemy_conn and executor in OP's case) simply uncomment and change the appropriate line (or, as I did, leave the original for future reference and add in your override).