에듀테크 프로젝트 대시보드
연결과 pg_hba.conf
클라이언트는 어디서 접속하는지(pg_hba.conf)와 누구인지 증명(인증 방식)을 통과해야 합니다.
postgresql://user:password@host:5432/dbname?sslmode=require&connect_timeout=5
host=localhost port=5432 dbname=school user=school password=pw # 키-값 형식# 환경변수로도 지정 가능
export PGHOST=localhost PGUSER=school PGDATABASE=school
export PGPASSFILE=~/.pgpass # user:pass 를 파일로 (chmod 600)
psql # 인자 없이 접속# ~/.pgpass 형식: host:port:database:user:password
localhost:5432:school:school:s3cr3t# postgresql.conf
listen_addresses = 'localhost' # 기본. 외부 허용 시 '*' 또는 특정 IP
port = 5432listen_addresses = 'localhost' 유지 — DB 를 인터넷에 노출하지 않음ssh -L 5432:localhost:5432 user@server# TYPE DATABASE USER ADDRESS METHOD
local all postgres peer
local school school scram-sha-256
host school school 127.0.0.1/32 scram-sha-256
host all all 0.0.0.0/0 reject| METHOD | 의미 |
|---|---|
peer | 로컬 OS 계정명 == DB 역할명 (로컬 소켓 전용) |
scram-sha-256 | 비밀번호 (권장, 현대 기본값) |
md5 | 구형 비밀번호 해시 — 신규는 scram |
trust | 무조건 허용 — 운영 금지 |
reject | 즉시 거부 |
-- pg_hba.conf / listen_addresses 외 대부분 파라미터
SELECT pg_reload_conf();sudo systemctl reload postgresql@16-main # 동일 효과
# listen_addresses, port, shared_buffers 등은 reload 로 안 되고 restart 필요-- 비밀번호는 scram 으로 저장되게
SHOW password_encryption; -- scram-sha-256
ALTER ROLE school PASSWORD 'new-strong-secret';