1. Paste pg_hba.conf and any included files
Name each file by its path relative to pg_hba.conf (for example conf.d/10-app.conf for include_dir conf.d, or users.txt for @users.txt). On Debian and Ubuntu the file is /etc/postgresql/16/main/pg_hba.conf; elsewhere SHOW hba_file; prints its path.
Optional: which line decides one connection?
Paste at least pg_hba.conf above and click Check.
2. What PostgreSQL will do
| Severity | Where | Finding | Fix |
|---|
Which line decides
What it checks
Lines PostgreSQL 16 rejects, with its own error text (invalid IP mask "md5" when 10.1 has no /, scram instead of scram-sha-256, peer on a host line, a clientcert on a non-hostssl line); includes it cannot open; rules an earlier line always beats; trust over the network, on loopback and on the socket; password, ldap, pam and radius on lines that also accept connections without TLS; ident over TCP; md5; remote password lines that do not require TLS; 0.0.0.0/0 and all; ldapbindpasswd and radiussecrets stored in the file; regexes such as /admin that match anywhere in a name; quoted keywords such as "all", which mean a role or database literally named all; IPv4 shorthand (010.0.0.1 is 8.0.0.1, 10.1 is 10.0.0.1); an address that is not a valid IP and is silently read as a host name; host bits in a CIDR; and files include_dir skips.
The reading follows PostgreSQL 16's hba.c and the pg_hba.conf chapter of the PostgreSQL 16 manual. It was compared with a real PostgreSQL 16.15 server: every row of its pg_hba_file_rules view for 600 generated files, and the line that authenticated (or the refusal) for 5,760 real connections across 160 more (parity run). This tool is not affiliated with the PostgreSQL Global Development Group. Every finding type, with the PostgreSQL behaviour behind it: pg_hba.conf mistakes explained.
Prefer a CLI, or want this in your own CI?
Same engine, zero dependencies, Node 18 or later:
sudo node check.mjs /etc/postgresql/16/main # pg_hba.conf and everything it includes
node check.mjs ./pg_hba.conf --ssl off # the server has ssl = off
node check.mjs ./pg_hba.conf --user app --db appdb --addr 10.0.4.7 --tls
# which line decides one connection
node check.mjs ./pg_hba.conf --format json # machine-readable
node check.mjs ./pg_hba.conf --fail-on-risk # exit 2 on an error, high or medium finding
Get check.mjs and scan.mjs from the repo: nothing to install, no network calls, and it never connects to a database. On the server, SELECT * FROM pg_hba_file_rules; shows how PostgreSQL parses the file on disk now.
Common questions
Which pg_hba.conf line does PostgreSQL use?
The first one, reading from the top (with included files read where their include line stands), whose connection type, address, database and user all match. It does not look for the most specific line and it does not try the next line if authentication fails. So a reject line for one user placed under a line that allows all users never fires.
Why did my pg_hba.conf change do nothing after a reload?
If any line has an error, PostgreSQL refuses the whole file. On a reload it logs the error and keeps using the old rules, so your edit silently has no effect; at start-up the server will not start. Run SELECT * FROM pg_hba_file_rules WHERE error IS NOT NULL; to see the errors before reloading.
Does the all database match replication connections?
No. A physical replication connection (pg_basebackup, a streaming standby) only matches lines whose database field is the keyword replication. Logical replication connections name a real database and match like ordinary connections.
Is md5 still safe to use in pg_hba.conf?
MD5 password hashes are deprecated (PostgreSQL 18 warns about them). An md5 line already uses SCRAM for any role whose stored password is a SCRAM verifier, so the practical step is password_encryption = scram-sha-256, then re-set each password, then change the lines to scram-sha-256.
Does a clean result mean my database is secure?
No. It reads only the patterns listed on this page, from the files you paste. It does not see listen_addresses, your firewall, role passwords, pg_ident.conf maps, which roles are superusers or group members, or your network. Confirm on the server with the pg_hba_file_rules view, and have a qualified person review anything that protects valuable data.