Fix: FATAL: no pg_hba.conf entry for host
The server received the connection but no pg_hba.conf rule matches this client address, user, database and SSL mode. Add or correct a rule and reload the configuration.
Not checked by a trusted editor yet Last edited Outdated?
The PostgreSQL documentation shows the error in this form:
FATAL: no pg_hba.conf entry for host "123.123.123.123", user "andym", database "testdb"
Recent server versions append the connection’s encryption state at the end, for example , no encryption or an SSL note. Read every part of the message: it tells you exactly which combination of client address, user, database and encryption found no matching rule.
This is not a password problem. The client reached the server and the server is running, but pg_hba.conf has no line for this connection, so it is refused before any password is asked for.
Causes, most likely first
- No rule for the client’s network. The default file usually allows only local socket and loopback (
127.0.0.1/32,::1/128) connections. The client’s address is shown in the message; behind NAT, a proxy or Docker it may not be the address you expected. - SSL mismatch. A
hostsslrule matches only encrypted connections andhostnosslonly unencrypted ones. If the message saysno encryptionand you only havehostssllines, the client must connect with SSL (for examplesslmode=require) or you need ahostrule. - Database or user does not match. The rule names a different database or role, or uses
+groupand the user is not a member. - Replication connection. Standbys and
pg_basebackupneed a rule with the special database namereplication;alldoes not match replication connections. - You edited a file the server does not read, or did not reload after editing.
Fix it step by step
- Find the file the server uses:
sudo -u postgres psql -c 'SHOW hba_file;'. - Add a rule as narrow as possible: the specific database, user and client network, with
scram-sha-256. - Make sure no earlier line already matches this connection with a different result (for example a
rejectrule). - Check for parse errors, then reload. A restart is not needed.
- Connect again from the client.
# TYPE DATABASE USER ADDRESS METHOD
host appdb appuser 10.0.0.0/24 scram-sha-256
hostssl appdb appuser 192.0.2.0/24 scram-sha-256
host replication replicator 10.0.0.12/32 scram-sha-256
SELECT line_number, type, database, user_name, address, auth_method, error
FROM pg_hba_file_rules;
SELECT pg_reload_conf();
pg_hba_file_rules shows the file as currently saved on disk, so you can spot a typo (a non-empty error column) before reloading.
Related checks
- If the client gets
Connection refusedor a timeout instead, the server is not listening on that address or a firewall blocks port 5432; checklisten_addressesinpostgresql.conf(restart required) and the firewall. - Do not “fix” this with
host all all 0.0.0.0/0 trust. That allows anyone who can reach the port to log in as any user without a password. - On managed or containerized PostgreSQL, the rules may be generated by the platform; change them through its configuration rather than by editing the file.
Official documentation
See also
- 0198 Install PostgreSQL and connect with psql on Debian, Ubuntu and RHEL Install the PostgreSQL server from your distribution or the official PGDG repositories, start it, and open your first psql session as the… Beginner · How-to · Linux Article Install & connect 15 Oct 2026
- 0199 psql meta-commands cheat sheet The backslash commands you use every day in psql: connecting, listing databases, tables and roles, describing objects, timing queries, expanded output and… Beginner · Reference · Any system Article Install & connect · Roles & administration 15 Oct 2026
- 0200 PostgreSQL roles, privileges and default privileges Create login and group roles, grant access to databases, schemas and tables, and use ALTER DEFAULT PRIVILEGES so tables created later get… Intermediate · How-to · Linux Article Roles & administration · Security & access 15 Oct 2026
- 0201 pg_hba.conf and PostgreSQL authentication methods pg_hba.conf decides who may connect from where and how they must prove who they are. Rules are checked top to bottom and… Intermediate · Concept · Linux Article Install & connect · Security & access 15 Oct 2026
- 0209 Fix: FATAL: password authentication failed for user PostgreSQL reached the server and found a matching pg_hba.conf rule, but the password check failed. Usually a wrong password, a role without… Intermediate · Fix · Any system Article Roles & administration · Security & access 15 Oct 2026
- 0211 Fix: psql connection to server on socket /var/run/postgresql/.s.PGSQL.5432 failed psql tried the local Unix socket and found nothing there. The server is not running, listens on another port, or uses a… Beginner · Fix · Linux Article Install & connect 15 Oct 2026
Repos in the wild
- postgres/postgres: PostgreSQL source code mirror postgres/postgres The official read-only GitHub mirror of the PostgreSQL source repository. Browse the code and history here; patches go through the project's mailing lists, not pull requests. GitHub
History
Every saved edit is kept. The plot on the sleeve draws one line per edit. Open any edit to see exactly what changed.
- Commitpedia +3,122 chars