Configuring a Remote Database for Airflow
This topic describes how to configure a remote database for Airflow on the HPE Data Fabric.
About this task
Airflow uses SQLAlchemy to connect to the metadata database. The metadata database stores the information about Airflow configurations, user information, roles and policies, and statistics of each DAG state, run, and task.
- Postgres
- MySQL
- SQLite
While SQLite is the default database on Apache Airflow, the Airflow community recommends Postgres for most use cases. For more details, see Set up a Database Backend.
For a list of the supported databases, see Choosing database backend.
Procedure
- Configure the remote database for Airflow. See Set up a Database Backend.
-
Update
<AIRFLOW-HOME>/conf/airflow.cfgwith your SQLAlchemy connection string.-
For PostgreSQL, update
<AIRFLOW-HOME>/conf/airflow.cfgwith:postgresql+psycopg2://<user>:<password>@<host>/<db> -
For MySQL, update
<AIRFLOW-HOME>/conf/airflow.cfgwith:mysql+mysqldb://<airflow-user>:<airflow-password>@<host>[:<port>]/<airflow-dbname>To connect to MySQL from Airflow, install the mysqlclient.- Run
. <airflow_home>/build/env/bin/activate - Run
pip install mysqlclient==2.2.0 - Run
deactivate
- Run
-
-
Create the database schema using the steps that apply to the currently installed
Ecosystem Pack. To identify the Ecosystem Pack that is installed, see Checking the EEP Version:
- For DEP 10.0.0 and later, use the
airflow-admincommand.- Run the
airflow-admin db migratecommand to initialize the database:airflow-admin db migrate - Run the
airflow-admin connections create-default-connectionscommand to create default connections:airflow-admin connections create-default-connections
- Run the
- For EEP 9.2.x through EEP 9.4.x, use the
airflowcommand.- Run the
airflow db migratecommand to initialize the database:airflow db migrate - Run the
airflow connections create-default-connectionscommand to create default connections:airflow connections create-default-connections
- Run the
- EEP 9.1.x and earlier, use the
airflowcommand:airflow db init
- For DEP 10.0.0 and later, use the
-
After the database configuration completes, create a user by following the steps in the
Command Line Interface and Environment Variables
Reference. For example:
Or, for EEP 9.4.x and earlier, use theairflow-admin users create --username mapr --firstname mapr --lastname mapr -p mapr --role Admin --email admin@example.orgairflowcommand:airflow users create --username mapr --firstname mapr --lastname mapr -p mapr --role Admin --email admin@example.org - Restart Airflow services as described in Starting, Stopping, and Restarting Airflow Services.