오지's blog

postgres 설치 및 원격접속 설정 본문

개발노트/데이터베이스

postgres 설치 및 원격접속 설정

오지구영ojjy90 2021. 9. 15. 10:53
728x90
반응형

$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt-get install postgresql postgresql-contrib
$ sudo -i -u postgres
$ psql
postgres-# create database airflow;
postgres-# create user admin with encrypted password 'admin';
postgres-# grant all privileges on database airflow to admin;
postgres-# \q


원격접속 허용 설정

루트계정으로 변경
1. postgresql.conf 설정파일 내용 변경
$ sudo vi /etc/postgresql/12/main/postgresql.conf
listen_addresses = 'localhost'          # what IP address(es) to listen on;
에서 
listen_addresses = '*'          # what IP address(es) to listen on;
로 변경

2. pg_hba.conf설정파일 내용 변경
$ sudo vi /etc/postgresql/12/main/pg_hba.conf
# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
에서

# IPv4 local connections:
# host    all             all             127.0.0.1/32            md5
host    all             all             0.0.0.0/0            trust
로 변경

 

다시시작

$ sudo systemctl restart postgresql.service 

 

 

 

 

 

참고.

sqlalchemy 라이브러리를 활용하여 postgresql 접속할수 있는 connection_string

postgresql+psycopg2://scott:tiger@localhost/mydatabase

https://docs.sqlalchemy.org/en/14/core/engines.html

 

Engine Configuration — SQLAlchemy 1.4 Documentation

Engine Configuration The Engine is the starting point for any SQLAlchemy application. It’s “home base” for the actual database and its DBAPI, delivered to the SQLAlchemy application through a connection pool and a Dialect, which describes how to talk

docs.sqlalchemy.org

 

Comments