본문으로 건너뛰기

5.3 DNS와 PostgreSQL 연결

DNS 지연은 새 connection에서만 나타나 connection pool 뒤에 숨을 수 있습니다. Pod 재시작이나 traffic spike 때 connection이 한꺼번에 만들어지면 갑자기 드러납니다.

resolvectl query db.internal
dig db.internal
getent ahosts db.internal

dig는 DNS 질의를 직접 확인하고, getent는 application이 사용하는 NSS 경로를 더 가깝게 반영합니다. /etc/nsswitch.conf, /etc/resolv.conf, search domain과 ndots를 함께 봅니다.

PostgreSQL server 측 이름 조회

pg_hba.conf에 hostname을 사용하거나 logging에서 reverse lookup을 의존하면 server 측 DNS 상태도 영향을 줄 수 있습니다. IP 규칙과 hostname 규칙의 보안과 운영 trade-off를 검토합니다.

Connection 단계 측정 예시는 다음과 같습니다.

time getent hosts db.internal
time pg_isready -h db.internal -p 5432
time psql 'host=db.internal dbname=postgres connect_timeout=3' -c 'select 1'

세 결과의 차이로 name resolution, TCP, TLS, authentication, query round trip을 대략 분리합니다. 운영 credential을 command history에 직접 넣지 않습니다.

Kubernetes에서는 application namespace의 DNS search path와 CoreDNS 상태를 확인합니다. 동일 hostname이 IPv4와 IPv6를 모두 반환할 때 connection fallback도 측정합니다.