CertGrid CertGrid
Troubleshooting·PostgreSQL

PostgreSQL pg_hba.conf Rule Order

The same two rules, the same client, opposite outcomes - decided entirely by which line comes first. pg_hba.conf stops at the first match, and a reject below a permit rule does nothing at all.

Roles and Authentication Guide 18 of 47 Advanced

pg_hba_file_rules lets you read the parsed rules from SQL, including any that failed to parse - useful before a reload rather than after.

Rule order can only be proved by connecting, so db-util01 makes the same connection four times across the guide.
Server NameIP AddressOSRolesCPURAMHDD
db-a01192.168.0.81Ubuntu 26.04 LTSPrimary / Source / Replica Set Member 12 Core4 GB50 GB
db-util01192.168.0.84Ubuntu 26.04 LTSClient, Backup Target and Monitoring2 Core4 GB50 GB

This guide includes

Use this when two rules contradict each other. This matters because pg_hba.conf is first-match-wins - the same two lines in the opposite order produce the opposite outcome, with nothing else changed.

Before you start

  1. Read the rules as the server parsed them

  2. Put a reject rule above the permit rule

  3. Watch the connection be rejected

  4. Swap the two lines and change nothing else

  5. Put the file back

Official sources