Use it when clients get "no pg_hba.conf entry" or authentication fails.
pg_hba.conf Authentication
pg_hba.conf controls which clients may connect to PostgreSQL: by connection type, database, user, address and authentication method (scram-sha-256, peer, cert…), first matching line wins.
1. Error text in the client and server log.
2. SELECT * FROM pg_hba_file_rules; — parsed rules and errors.
3. Matching line for client IP/user/db?
4. listen_addresses and firewall.
5. Reload and test.
connection → first matching hba line → auth method → role login
Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 How to verify Verify boundary
Reload and check pg_hba_file_rules. Test from the client host with psql and the same user. Confirm SSL is used when the rule is hostssl.
Step 2 Common failures Narrow the fault
A broad reject or trust rule above your rule changes the result. trust lets anyone in without a password. Forgetting to reload leaves old rules active.
Order matters. Use scram-sha-256 rather than md5/trust. Reload after changes (SELECT pg_reload_conf();). The server also needs listen_addresses for remote clients.
SELECT * FROM pg_hba_file_rules;— first check for this topicpsql -c "SELECT now(), version();"— PostgreSQL reachable and versionmysql -e "SELECT NOW(), VERSION();"— MariaDB/MySQL reachable and versionsqlcmd -S <server> -Q "SELECT @@VERSION"— SQL Server reachable and version
ReferenceWhat it is1 section · depth on demand
How it works
For each connection the server picks the first rule matching connection type (local, host, hostssl), database, user and client address, then applies its method: peer, scram-sha-256, cert or reject. listen_addresses must also include the interface.
ReferenceImportant terms & boundaries3 sections · depth on demand
Example
# TYPE DATABASE USER ADDRESS METHOD
local all postgres peer
hostssl shop app 10.0.0.0/24 scram-sha-256
host all all 0.0.0.0/0 reject
Documented example, not captured output. Rules are evaluated top-down; the first match wins. Reload after changes: SELECT pg_reload_conf();. Use scram-sha-256 (not md5 or trust) and hostssl to require TLS. Error "no pg_hba.conf entry for host" shows the exact client address and user.
In depth
First match wins
Each connection is compared with the rules from top to bottom; the first line whose type, database, user and address match decides the method. There is no fall-through: if that method fails (wrong password), the connection is rejected even if a later line would have allowed it.
# TYPE DATABASE USER ADDRESS METHOD
local all postgres peer
hostssl shop shop_app 10.0.0.0/24 scram-sha-256
hostssl replication replicator 10.0.1.12/32 scram-sha-256
host all all 0.0.0.0/0 reject
Connection types
| Type | Matches |
|---|---|
local | Unix socket |
host | TCP, with or without TLS |
hostssl / hostnossl | TCP with / without TLS |
hostgssenc | TCP with GSSAPI encryption |
replication in the database column matches physical replication connections only; all does not include them.
Methods
scram-sha-256 (password, recommended) · peer (OS user = DB user, local only) · cert (client certificate) · ldap, gss, radius · md5 (deprecated) · trust (no check — never on network lines) · reject.
Checking what the server loaded
SELECT pg_reload_conf();
SELECT line_number, type, database, user_name, address, auth_method, error
FROM pg_hba_file_rules;
A line with a value in error is ignored. The client message no pg_hba.conf entry for host "10.0.0.7", user "app", database "shop", no encryption lists exactly the values that must match a line — compare them with the table above.
Common mistakes
trustmethod in pg_hba.conf.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Terms & aliases
Hover a linked term for a quick definition; click it to open its glossary entry. Aliases are other names that find this Topic in search.