GrepBoard/매뉴얼
605 편 ·

no pg_hba.conf entry for host "::1" 해결

·시험 환경 PostgreSQL 17.11 (Docker postgres:17) · 2026-10·시험 범위 ↓·6 단계

no pg_hba.conf entry for host "::1" 은 localhost 가 IPv6 ::1 로 붙어서입니다. pg_hba.conf 에 ::1/128 을 더하거나 -h 127.0.0.1 로 붙습니다.

output
psql: error: connection to server at "::1", port 5432 failed: FATAL:  pg_hba.conf rejects connection for host "::1", user "alice", database "app", no encryptionpsql: error: connection to server at "2001:db8::2", port 5432 failed: FATAL:  no pg_hba.conf entry for host "2001:db8::10", user "alice", database "app", no encryption

host "::1" 은 접속이 IPv4 127.0.0.1 이 아니라 IPv6 루프백 ::1 로 들어왔다는 뜻입니다. 그 뒤 문구로 두 경우를 가릅니다. pg_hba.conf rejects connection(첫째 줄)은 연결 종류·DB·사용자·주소가 모두 맞는 reject 줄에 걸렸다는 것이고, no pg_hba.conf entry 는 네 가지가 모두 맞는 줄이 하나도 없었다는 것입니다. 맞는 줄이 없는 가능한 원인 하나가 IPv4 루프백(127.0.0.1/32)만 열고 IPv6 루프백(::1/128)은 열지 않은 경우입니다 — DB·사용자·연결 종류(host/hostssl)가 안 맞아도 같은 문구가 나오므로 파일을 보고 확인합니다. IPv4 루프백만 열어 둔 것이 원인이라면 ::1/128 줄을 같이 두거나, 클라이언트에서 -h 127.0.0.1 로 주소를 박으면 풀립니다. 두 문구는 PostgreSQL 소스(auth.c)에서 같은 자리에 쓰이는 짝이고, 따옴표 안은 이름이 아니라 숫자 주소입니다.

붙여 넣으면 어느 줄이 걸리는지 바로 보는 pg_hba.conf 대조기도 있습니다.

[1] 서버 로그에서 들어온 주소를 확인합니다. log_connections = on 이면 접속마다 connection received: host=… 가 남습니다(켜는 법은 어느 pg_hba.conf 줄에 걸렸나). 아래는 IPv4 루프백만 열어 둔 파일입니다.

run/set-08.conf
# IPv4 loopback only · IPv6 rangeshost    all    all    127.0.0.1/32            trusthost    all    all    2001:db8::10/128    md5host    all    all    2001:db8::/64       passwordhost    all    all    ::0/0                   rejectlocal   all    all                            reject

같은 기계에서 같은 사용자 alice 로 두 번 붙었습니다. 주소 꼴 하나로 결과가 갈립니다.

output
LOG:  connection received: host=127.0.0.1 port=50858LOG:  connection authenticated: user="alice" method=trust (/var/lib/postgresql/data/pg_hba.conf:2)LOG:  connection received: host=::1 port=46254FATAL:  pg_hba.conf rejects connection for host "::1", user "alice", database "app", no encryption

::1 접속은 2째 줄 127.0.0.1/32 과 맞지 않아 아래로 내려가다 5째 줄 ::0/0 reject 에 걸렸습니다. 공식 문서도 IPv4 꼴로 적은 줄은 IPv4 접속에만, IPv6 꼴은 IPv6 접속에만 맞는다고 적습니다.

[2] 왜 localhost 가 ::1 로 가는지 봅니다. libpq 는 호스트 이름이 여러 주소로 풀리면 운영체제가 돌려준 순서대로 시도합니다. 클라이언트 기계에서 getent ahosts localhost 를 쳐서 ::1 이 127.0.0.1 보다 먼저 나오면 그 기계의 localhost 접속은 ::1 로 갑니다. 공식 문서대로 연결은 됐는데 인증이 실패하면 나머지 주소는 시도하지 않습니다. 그래서 ::1 에서 거절되면 127.0.0.1 줄이 있어도 쓰이지 않습니다.

[3] pg_hba.conf 에 ::1/128 줄을 짝으로 둡니다. 가장 흔한 해법입니다. 아래 파일은 두 루프백에 같은 방식을 줬습니다.

run/set-01.conf
# TYPE  DATABASE        USER            ADDRESS                 METHOD…host    all             all             127.0.0.1/32            scram-sha-256host    all             all             ::1/128                 scram-sha-256…
output
LOG:  connection received: host=127.0.0.1 port=39038LOG:  connection authenticated: identity="alice" method=scram-sha-256 (/var/lib/postgresql/data/pg_hba.conf:4)LOG:  connection received: host=::1 port=41104LOG:  connection authenticated: identity="alice" method=scram-sha-256 (/var/lib/postgresql/data/pg_hba.conf:5)

두 접속이 각자 4째·5째 줄에 걸렸습니다. 고친 뒤에는 SELECT pg_reload_conf(); 로 다시 읽게 하고, 반영됐는지는 서버 로그로 확인합니다. 한 줄이라도 틀리면 파일 전체가 무시됩니다 — pg_hba.conf 를 고쳤는데 반영이 안 될 때.

[4] 주소를 하나로 묶고 싶으면 samehost 를 씁니다. 서버 자신의 IP 전부와 맞는 예약어라 두 루프백이 한 줄에 걸립니다.

run/set-07.conf
…host    all        dave      samehost          scram-sha-256…
output
LOG:  connection received: host=127.0.0.1 port=51678LOG:  connection authenticated: identity="dave" method=scram-sha-256 (/var/lib/postgresql/data/pg_hba.conf:4)LOG:  connection received: host=::1 port=45260LOG:  connection authenticated: identity="dave" method=scram-sha-256 (/var/lib/postgresql/data/pg_hba.conf:4)

[5] 서버 파일을 건드릴 수 없으면 클라이언트에서 주소를 박습니다. psql -h 127.0.0.1 … 이나 연결 문자열 host=127.0.0.1(또는 hostaddr=127.0.0.1)은 이름 풀이를 거치지 않으니 늘 IPv4 로 붙습니다. 애플리케이션 설정의 localhost 를 127.0.0.1 로 바꾸는 것과 같습니다.

[6] IPv4 매핑 꼴 ::ffff: 로 IPv4 를 덮으려 하지 않습니다. 아래 8째 줄은 IPv4 클라이언트 192.0.2.10 과 맞지 않았습니다.

run/set-04.conf
…host    all   carol   ::ffff:192.0.2.10/128           md5host    all   carol   0.0.0.0/0                        password…
output
LOG:  connection received: host=192.0.2.10 port=55660LOG:  connection authenticated: identity="carol" method=password (/var/lib/postgresql/data/pg_hba.conf:9)

8째 줄 md5 가 아니라 9째 줄 0.0.0.0/0 에 걸렸습니다. 공식 문서도 IPv4-in-IPv6 범위의 주소라도 IPv6 꼴 줄은 IPv6 접속에만 맞는다고 적습니다. IPv4 클라이언트는 IPv4 꼴로 적습니다.

IPv6 주소 하나가 빠졌을 때도 문구는 같습니다. 맨 위 둘째 줄은 2001:db8::10 에서 들어왔는데 host 줄이 127.0.0.1/32 · ::1/128 뿐인 파일이라 맞는 줄이 없었던 경우입니다. 그 주소나 대역(2001:db8::/64)을 IPv6 꼴로 넣습니다.

Connection refused 처럼 아예 연결이 안 되면 인증 전 단계입니다 — PostgreSQL 5432 Connection refused 해결. 줄에는 걸렸는데 비밀번호에서 막히면 psql password authentication failed 해결로 넘어갑니다.

공식 근거: pg_hba.conf · libpq 다중 호스트·주소 · log_connections · auth.c (REL_17_STABLE)

pg_hba.conf 규칙 대조기 도구로 바로 확인 ↗ — 브라우저 안에서 계산합니다.

#postgresql#pg_hba#ipv6#localhost#psql