QuickDevGuide

Home › PostgreSQL Database

Security Best Practices — PostgreSQL Database

Security in PostgreSQL involves authentication, authorization, encryption, and hardening at multiple layers. Authentication (pghba.conf) The pghba.conf file controls who can connect and how they authenticate: Method Description scram-sha-256 Recommended password auth (PostgreSQL 10+) md5 Legacy password hash (avoid for new setups) cert Client certificate authentication peer / ident OS user matching (local connections) reject Deny connection Authorization (GRANT/REVOKE) PostgreSQL uses a role-based permission system. Roles can own objects, have login privileges, and inherit permissions from other roles. Encryption In transit — SSL/TLS connections (ssl = on in postgresql.conf) At rest — OS-level disk encryption or pgcrypto for column-level Passwords — Always use crypt() + gensalt() from…

Key Takeaways