What is pg_hba.conf?

IntermediateConceptPostgreSQL
Answer

Short answer

pg_hba.conf ("host-based authentication") is the file that decides who may connect, to which database, from which address, and with which authentication method. PostgreSQL checks it top to bottom and uses the first matching line. If no line matches, the connection is refused.

Format

# TYPE   DATABASE   USER        ADDRESS          METHOD
local    all        postgres                     peer
host     shop       shop_app    10.0.11.0/24     scram-sha-256
hostssl  all        all         10.0.0.0/16      scram-sha-256
host     all        all         0.0.0.0/0        reject
Field Meaning
TYPE local (Unix socket), host (TCP), hostssl (TCP + TLS only)
METHOD scram-sha-256 (password, recommended), md5 (old), peer (OS user), trust (no password — avoid), reject

Apply changes

sudo systemctl reload postgresql          # or: SELECT pg_reload_conf();
SELECT * FROM pg_hba_file_rules;          -- see parsed rules and errors

The error it causes

FATAL: no pg_hba.conf entry for host "10.0.12.8", user "shop_app", database "shop", SSL off

→ add a line for that subnet (and note "SSL off" — a hostssl rule won't match a non-TLS client).

Managed services

On RDS/Azure you don't edit pg_hba.conf — access is controlled by security groups/firewall rules plus parameters like rds.force_ssl.

What to say in the interview

"pg_hba.conf controls connection authentication by type, database, user and source address, first match wins. I use hostssl with scram-sha-256 for app subnets, never trust, reload after changes, and the 'no pg_hba.conf entry' error tells me exactly which rule is missing."

All Databases (MySQL, PostgreSQL, MongoDB) questions Roadmap: PostgreSQL basics

More on PostgreSQL