[Apache Airflow] Airflow DB to Postgres(Docker)
Airflow DB to Postgres(Docker)
- ๐ Airflow Local์ ์ค์น / ๐ Airflow Docker์ ์ค์น
- Postgres Container ์ค์น
- PostgreSQL DB ๋ฐ DB User ์์ฑ
- airflow.cfg ์์ 1
- pycopg2-binary ์ค์น
- airflow db ์ด๊ธฐํ
- airflow.cfg ์์ 2
Postgres Container ์ค์น
# container ์์ฑ
docker run -p 5432:5432 --name postgres1 -e POSTGRES_PASSWORD=1234 -d -v psql_data:/var/lib/postgresql/data postgres
# postgres shell ์ ์
docker exec -it postgres1 bash
su - postgres
psql
PostgreSQL DB ๋ฐ DB User ์์ฑ
- Postgres shell์์ DB ๋ฐ DB User ์์ฑ
# DB ์์ฑ (CREATE DATABASE [db_name])
CREATE DATABASE airflow_db;
# DB USER ์์ฑ (CREATE USER [id] with password '[password]';)
CREATE USER admin with password 'admin';
# user ์์ฑ ํ์ธ
\du
airflow.cfg ์์ 1
# airflow.cfg
sql_alchemy_conn = postgresql+psycopg2://admin:admin@localhost/airflow_db
pycopg2-binary ์ค์น
# ๊ฐ์ํ๊ฒฝ ์ ์ ํ
pip3 install psycopg2-binary
airflow db ์ด๊ธฐํ
# airflow db init
airflow db init
# user ์์ฑ
airflow users create -u admin -p admin -f jisu -l park -r Admin -e zsu58@korea.ac.kr
# ์ด๊ธฐํ ํ์ธ
docker exec -it postgres1 bash
su - postgres
# psql -U [db_user] [db_name]
psql -U admin -d airflow_db
# ์์ฑ๋ ํ
์ด๋ธ ํ์ธ
\dt
# user ํ์ธ
SELECT * FROM ab_user;
airflow.cfg ์์ 2
# airflow.cfg
executor = LocalExecutor