Big Data/Airflow

Airflow - Postgresql 설치 및 연동

chmono 2022. 11. 4. 13:06

 

 Docker 에 Postgres Image Pull한 뒤, Container를 생성해주자.

PS C:\Users\ktnexr> docker pull postgres
PS C:\Users\ktnexr> docker run -d -p 5432:5432 --name postgres -e LC_ALL=C.UTF-8 -e POSTGRES_PASSWORD=0000 postgres

 

생성한 Container로 접속하여 DB,User 생성 및 권한을 설정해준다.

PS C:\Users\ktnexr> docker exec -it postgres bash

root@e7a6cd6247f9:/# psql -U postgres
postgres=# create database airflow;
postgres=# create user admin with encrypted password '0000';
postgres=# grant all privileges on database airflow to admin;

postgres=# \c airflow
airflow=# grant all privileges on all tables in schema public to admin;

postgres=# \c airflow
airflow=# grant all privileges on all tables in schema public to admin;

airflow=# \q

실행 결과

 

postgresql 컨테이너를 생성해주면 Docker에서 아래와 같이 컨테이너가 추가되는 것을 확인할 수 있다.

 

이제 Postgre Cluster를 만들어주자

Postgres 버전 확인
root@e7a6cd6247f9:/# postgres --version

Postgres Cluster 생성
root@e7a6cd6247f9:/# pg_createcluster 15 main
root@e7a6cd6247f9:/# pg_ctlcluster 15 main start

pg_hba.conf 파일 수정해주기
root@e7a6cd6247f9:/# cd /etc/postgresql/15/main
root@e7a6cd6247f9:/etc/postgresql/15/main# vim pg_hba.conf

vim 설치 (명렁어 실행 안될 경우)
# apt-get update
# apt-get install -y vim

#IPv4 local connections:

host       all     all        0.0.0.0/0      md5

작성해주고 위에 두 줄은 주석 처리해준다.

 

 

 

 

DBeaver에서 Postgresql 을 연결해보자.

 

Test connection 클릭.

(필요한 driver 설치 안내가 나오면 설치해주면 된다.)

아래와 같이 연결하고자 하는 DB 정보 정확하게 뜨는 지 확인하고 [확인] 클릭.

 

정상적으로 연결된 모습은 아래와 같다.

 

마지막으로 완성된 Postgres 컨테이너를 commit해주기

root@e7a6cd6247f9:~# exit
PS C:\Users\ktnexr> docker commit postgres postgres:airflow

 

 

Docker hub에 Push해줄때는

PS C:\Users\ktnexr> docker commit postgres {id}/postgres:airflow
PS C:\Users\ktnexr> docker push {id}/postgres:airflow

push할 게 없어서 거절 당했나..