본문 바로가기
🔧 트러블슈팅 노트

[PostgreSQL] no pg_hba.conf entry for host "xxx.xxx.xxx.xxx", user "postgres", database "postgres", SSL off error 오류

by cheonvi 2023. 2. 24.

PostgreSQL 은 postgresql.conf 파일과 pg_hba.conf 파일을 통해 특정 서버에서 특정 사용자에만 접속이 가능하도록 제한할 수 있습니다.

pg_hba.conf 파일을 편집으로 오픈합니다. 

 

아래는 pg_hba.conf 파일의 기본상태입니다.

ADDRESS 부분을 보면 어디에서도 외부에서 접속이 가능하도록 IP 가 적용되어 있는 부분이 없습니다.

sudo vi /etc/postgresql/14/main/pg_hba.conf


# DO NOT DISABLE!
# If you change this first entry you will need to make sure that the
# database superuser can access the database using some other method.
# Noninteractive access to all databases is required during automatic
# maintenance (custom daily cronjobs, replication, and similar tasks).
#
# Database administrative login by Unix domain socket
local   all             postgres                                md5

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     peer
# IPv4 local connections:
host    all             all             127.0.0.1/32            scram-sha-256
# IPv6 local connections:
host    all             all             ::1/128                 scram-sha-256
# Allow replication connections from localhost, by a user with the
# replication privilege.
local   replication     all                                     peer
host    replication     all             127.0.0.1/32            scram-sha-256
host    replication     all             ::1/128                 scram-sha-256

 

모든 IP 에서 모든 사용자, 데이터베이스에 접속가능하도록 설정을 추가방법은 아래와 같습니다. 

 

host    all             all             0.0.0.0/0               md5 <=== 추

# DO NOT DISABLE!
# If you change this first entry you will need to make sure that the
# database superuser can access the database using some other method.
# Noninteractive access to all databases is required during automatic
# maintenance (custom daily cronjobs, replication, and similar tasks).
#
# Database administrative login by Unix domain socket
local   all             postgres                                md5

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     peer
# IPv4 local connections:
host    all             all             127.0.0.1/32            scram-sha-256
# IPv6 local connections:
host    all             all             ::1/128                 scram-sha-256
# Allow replication connections from localhost, by a user with the
# replication privilege.
local   replication     all                                     peer
host    replication     all             127.0.0.1/32            scram-sha-256
host    replication     all             ::1/128                 scram-sha-256
host    all             all             0.0.0.0/0               md5

 

적용이 완료되었으면 PostgreSQL 을 아래 명령어를 통해서 재 구동해서 pg_hba 설정값을 적용해줍니다.

sudo service postgresql restart