What it does
For every new connection PostgreSQL reads pg_hba.conf from the top and uses the first line whose connection type, database, user and address all match. This tool follows the same order: it shows which line is chosen, its authentication method, and for each line above it why it did not match. When nothing matches it prints the no pg_hba.conf entry for host … message the server would log.
Examples
| Rules | Connection | Result |
|---|---|---|
only host all all 127.0.0.1/32 scram-sha-256 | psql -h ::1 | no match (IPv4 rule, IPv6 client) |
host app +app_users 10.0.0.0/24 scram-sha-256 | 10.0.0.5 · alice · member of app_users | match → scram-sha-256 |
host all all 0.0.0.0/0 reject, then host all bob 0.0.0.0/0 md5 | bob | stops at reject — the next line is never tried |
local all all ident | Unix socket | applied as peer |
host all all 10.0.0.0/8 md5 above host replication all 10.0.0.0/8 md5 | pg_basebackup | the replication line matches — all does not cover physical replication |
host all all 10.0.0.7 255.255.0.255 md5 | 10.0.200.7 | match — the mask is applied bit by bit, contiguous or not |
Common mistakes
localhostgoes to::1—psql -h localhostmay connect over::1. With only a127.0.0.1/32line, nothing matches or a later line catches it. When the address is 127.0.0.1 or ::1 the tool also checks the other one.- Expecting a fall-through — if authentication fails on the matching line (wrong password, peer mismatch) the connection fails; later lines are not tried.
rejectends the search too. Put narrow lines first and broad ones last. - Quoted keywords —
"all"and"replication"are no longer keywords; they match a database or user with that name. A value starting with/, such as"/^c", is still a regular expression when quoted. - Editing without a reload — the file is read at startup and on reload. If any line is invalid, a reload keeps the old rules and a startup fails.
How it was checked
Before publishing, eight rule sets were loaded into PostgreSQL 17.11 (the postgres:17 container) and real connections were made from four client containers on different IPv4 and IPv6 addresses, plus the server's own socket, 127.0.0.1 and ::1. Each set was first loaded with every method replaced by password and a wrong password, so the log line Connection matched file … line N gives the first matching line; then the original file was loaded again to confirm what that line's method did (connection authenticated: … method=… (file:N), pg_hba.conf rejects connection, no pg_hba.conf entry). All 111 connections and all 182 lines compared with the pg_hba_file_rules view agreed.
samehost and samenet (they depend on the server's addresses), host-name addresses (DNS), @file, include, +group when membership is unknown, regular expressions outside the syntax this page evaluates, and unusual numeric forms such as 010.0.0.1 give no verdict — the tool says it cannot decide and why. Option values of ldap and radius lines are not checked.
FAQ
How do I see which line the server actually used?
With log_connections = on every successful connection logs the file and line, e.g. connection authenticated: user="…" method=trust (/…/pg_hba.conf:7) (PostgreSQL 17 logs this for trust too). A failed authentication adds DETAIL: Connection matched file "…" line N: "…". A reject line logs only pg_hba.conf rejects connection for host …, without a line number.
Can I check the file before reloading?
SELECT line_number, type, database, user_name, address, auth_method, error FROM pg_hba_file_rules; parses the file on disk now and shows each line. If any row has an error, a reload will not apply the file. A row with every column empty is also an error (for example clientcert=1).
Is the file I paste sent to a server?
No. Everything is matched in your browser. The file, addresses and user names are not sent to a server and are not passed to the analytics or ads this site uses. See the privacy notice.