Pcornel
Browse topics
Options
Recent
Favorites
Databases · Technical reference

pg_hba.conf Authentication

Direct answer

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.

When to use this

Use it when clients get "no pg_hba.conf entry" or authentication fails.

First 30 seconds

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.

Operational verification

connection → first matching hba line → auth method → role login

Context & applicabilityCommon mistakes · platform/version boundaries
Platform / version applicability
MariaDB / MySQL / PostgreSQL / Microsoft SQL Server concepts
applies
Structured applicability is explicit Topic metadata; it does not infer compatibility beyond the stored rows.
At a glance

Operational reference

Fast context before you go deeper.

PlatformMariaDB / MySQL / PostgreSQL / Microsoft SQL Server concepts
Scope / prerequisiteUse it when clients get "no pg_hba.conf entry" or authentication fails.
What next?2 suggested next steps
Evidence0
On this pageJump to a specific section
Operational workflow

Verification & Troubleshooting

Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.

2 steps Observe → verify → isolate → change minimally → repeat the original test.
ObservedRecord what the original test actually shows

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.

Key points

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.

Key checks
  • SELECT * FROM pg_hba_file_rules; — first check for this topic
  • psql -c "SELECT now(), version();" — PostgreSQL reachable and version
  • mysql -e "SELECT NOW(), VERSION();" — MariaDB/MySQL reachable and version
  • sqlcmd -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

TypeMatches
localUnix socket
hostTCP, with or without TLS
hostssl / hostnosslTCP with / without TLS
hostgssencTCP 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.

Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.

Common mistakes

  • trust method in pg_hba.conf.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Terminology layer

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.

Aliases that resolve here
pg_hba.conf authenticationpg_hba.confpostgresql authentication
Confirmation

Confirm action

Continue?