no pg_hba.conf entry for host in 60 seconds
# 1. The HBA file the server actually reads
psql -c "SHOW hba_file;"
# 2. Is the server listening on the network or only on loopback?
psql -c "SHOW listen_addresses;"
# 3. The line to add: database, user, client network, method
# host appdb app 10.0.0.0/24 scram-sha-256
# 4. Apply without restarting
psql -c "SELECT pg_reload_conf();"
# 5. Check active rules and parsing errors
psql -c "SELECT line_number, error FROM pg_hba_file_rules WHERE error IS NOT NULL;"
# 6. Is the port listening and reachable?
ss -ltnp | grep 5432
# 7. Test from the client, not from the server
psql -h 10.0.0.5 -U app -d appdb
The report comes in: the application can no longer connect to the database after a network change. From psql on the server everything works. From any other host the client returns an error that mentions a configuration file and a host. The reflex is to blame the password, the user, the grants. Wrong: PostgreSQL has not even reached the credential check yet, it stopped earlier, while reading pg_hba.conf.
Three conditions must be true at the same time for a remote connection to work. The server listening on the right interface. An HBA line that matches IP, database and user. Port 5432 open along the whole network path.
Here we check them one by one, in the order the server evaluates them. With the exact commands and the traps that waste more time than the error itself.
Reference versions: PostgreSQL 18 (current major at December 2026), psql client of the same major, Debian/Ubuntu systemd units, RHEL and derivatives for the data directory layout.
Prerequisites
- Access to the cluster with a role that can read configuration parameters and modify files on the server filesystem.
- The configuration file path of the cluster you care about: on a host with several installed versions there are several of them.
- A psql client of a major compatible with the server.
- Visibility on the host firewall and on the network firewall. Opening the local rule and forgetting the security group is one of the classics.
- If the change involves the listening address, a window in which the service can be restarted.
What the error means
The message that reaches the client is more explicit than it looks. A typical output:
psql: error: connection to server at "10.0.0.5", port 5432 failed:
FATAL: no pg_hba.conf entry for host "10.0.0.7", user "app", database "appdb", no encryption
If one of the three does not match a line in pg_hba.conf, the connection dies there.
The problem is authorization, not reachability.
Also read the final detail, “no encryption”. If the file only contains a hostssl line, that connection does not match and the rejection is correct: the client must negotiate TLS or a host line must be added.
Read also: PostgreSQL VACUUM: Autovacuum Tuning and Wraparound Risk
Finding the right pg_hba.conf
The official documentation says it plainly: the file traditionally lives in the data directory, but the actual path must be asked to the running server. There is only one command:
SHOW hba_file;
A typical output:
/var/lib/postgresql/18/main/pg_hba.conf
That result is the answer that matters. On Red Hat and derivatives the file sits in the data directory. On a cluster managed by a provider the file may not be editable at all, and there the only route is the service panel or API.
Before touching anything: copy the file and read the lines already present. This is not formal caution.
Read also: ORA-12541 TNS:no listener: 8-Step Troubleshooting Guide
The host line field by field
host appdb app 10.0.0.0/24 scram-sha-256
| Field | Typical values | What it controls |
|---|---|---|
| type | host, hostssl, hostnossl, local | generic TCP, TLS only, non-TLS only, Unix socket |
| database | name, list (a,b), all, replication, @file | which databases the rule applies to |
| user | name, list, all, +role | which roles are allowed |
| address | CIDR 10.0.0.0/24, single IP, hostname | where the client comes from |
| auth-method | scram-sha-256, md5, trust, peer, cert | how the client proves its identity |
The most frequent mistake is in the address field. Writing /32 when /24 is needed excludes everything except one host. Copying the gateway IP instead of the client IP does the same thing in a quieter way.
There is a detail that surprises people: the IP in the error message is not always the one the operator expects. With NAT or a load balancer in front of the database, the server sees the address of the device doing the translation, not the original client. In that case the rule must be written on the firewall network, not on the application server network.
On the database field there are dedicated keywords. Lists are written comma separated, without spaces, and one extra comma changes the meaning of the line without generating obvious errors at first glance.
scram-sha-256, md5 or trust
The current documentation points to scram-sha-256 as the modern method for password authentication. The client never sends the password in clear text: there is a challenge-response exchange, and that matters even when the connection is not encrypted.
md5 is historical. The server still accepts it, but the hash is weak and it should be treated as legacy. There is a concrete trap when moving from one method to the other: if a role has its password stored with an md5 hash, a line with scram-sha-256 will not authenticate it. That is not a bug, it is the storage format. The password must be reset so that it is saved in the new format, and the password_encryption parameter determines how new passwords are hashed (the default has been scram-sha-256 for several majors now).
trust deserves a separate line. It verifies nothing: anyone who reaches the port gets in with the role they declare. On a local socket on a development machine it is convenient. On an exposed network it is access without credentials, and the fact that it is written in the configuration file does not make it a conscious choice.
peer only applies to the Unix socket and maps the system user. cert requires TLS with a client certificate and is the right choice when you want to remove the password from the equation.
Read also: mysqldump Backup: Consistency & MySQL/MariaDB Restore
listen_addresses: does the server really listen on the network?
Before the HBA there is an upstream question: does the server accept TCP connections from anyone other than itself?
SHOW listen_addresses;
An output:
localhost
With that value the server listens on loopback only. No HBA rule can fix it: the connection never reaches the authentication logic, and the client gets connection refused or a timeout.
| Value | Effect |
|---|---|
| localhost | loopback only, no remote access |
| * | all interfaces, IPv4 and IPv6 |
| 0.0.0.0 | all IPv4 interfaces |
| :: | all IPv6 interfaces |
| 10.0.0.5,127.0.0.1 | only the listed interfaces |
The typical case is listen_addresses = '*' on a server that must accept clients from the internal network, with the HBA restricting the allowed subnets. Opening on all interfaces and leaving authorization to the HBA file is a legitimate choice, but it moves all the responsibility onto that file.
Here comes the trap that costs the most time: listen_addresses is a postmaster-level parameter. It requires a service restart.
sudo systemctl restart postgresql
Whoever edits both pg_hba.conf and postgresql.conf and then only does a reload sees half of the configuration working. The new HBA rules are active, the listening is not. And the error message that comes back is different from the original one, which sends you down the wrong path.
Reloading without restarting
Changes to pg_hba.conf are applied with a configuration reload. Sessions already open stay up, new connections use the updated rules.
SELECT pg_reload_conf();
Equivalent from the shell, if you prefer not to go through psql:
# as the postgres user
pg_ctl reload -D /var/lib/postgresql/18/main
# or via systemd on Debian and Ubuntu
sudo systemctl reload postgresql
The reload is not as silent as it seems. That is why the next check is not optional.
Worth remembering: reload for pg_hba.conf, restart for listen_addresses and port. They are two different operations with two different impacts on availability.
Checking active rules from SQL
This is exactly what it is for: understanding whether a rule will be discarded before trying it with a client.
SELECT line_number, type, database, user_name, address, auth_method
FROM pg_hba_file_rules;
A typical output:
line_number | type | database | user_name | address | auth_method
-------------+-------+----------+-----------+---------------+---------------
1 | local | {all} | {all} | | peer
95 | host | {appdb} | {app} | 10.0.0.0/24 | scram-sha-256
96 | host | {all} | {all} | 10.0.1.0/24 | scram-sha-256
Two things to know.
SELECT line_number, error FROM pg_hba_file_rules WHERE error IS NOT NULL;
If this returns rows, you have the exact position of the problem. The line number is the same one you see when you open the file in an editor: go there and fix it.
Read also: Active Directory Account Locked Out: Event 4740 Origin
Firewall and port 5432
PostgreSQL configuration is useless if the traffic is filtered before it arrives. The default port is 5432/TCP, and it must be open at every layer: host firewall, network firewall, cloud security group.
The first check is local, on the server:
ss -ltnp | grep 5432
A typical output:
LISTEN 0 200 127.0.0.1:5432 0.0.0.0:* users:(("postgres",pid=1187,fd=7))
That 127.0.0.1 is the signal: you are listening locally only, and no HBA rule will change the situation. If instead you read 0.0.0.0 or *:, the listener is there and the problem is elsewhere.
The decisive test is done from an external client, not from the server:
psql -h 10.0.0.5 -U app -d appdb
The type of error tells you where to look. Timeout: the traffic is filtered by a firewall. Connection refused: no listener on that port and that address. FATAL with no pg_hba.conf entry: network is fine, the rule is missing. Password authentication failed: the rule matches, the problem is the credential or the hash format.
Common Errors and Troubleshooting
| Exact error or message | Cause | Solution |
|---|---|---|
| no pg_hba.conf entry for host “10.0.0.7”, user “app”, database “appdb” | No HBA line matches IP, role and database | Check the path with SHOW hba_file; and add the correct host line |
| no pg_hba.conf entry … no encryption | The client connects in clear text and the file only has a hostssl rule | Add a host line or make the client negotiate TLS |
| connection to server … failed: Connection refused | listen_addresses on localhost or service stopped | Change postgresql.conf and restart the service |
| timeout expired | Host or network firewall filtering 5432 | Open the port at every layer of the path |
| password authentication failed for user “app” | The rule matches but the password hash is in md5 format on a scram-sha-256 line | Reset the password so it is saved in the new format |
| pg_hba_file_rules with a populated error column | Syntax error or a value not allowed on the indicated line | Fix the line indicated by line_number and reload |
| Connection ok from local psql, failed from remote | The local client uses the Unix socket and local rules, not host rules | Always test with -h against the real server IP |
Frequently Asked Questions
Do I need to restart PostgreSQL after changing pg_hba.conf?
No. Host-based authentication rules are applied with a configuration reload, so sessions already open stay active and new connections are evaluated against the updated file. A restart is needed instead for postmaster-level parameters, such as the listening address and the port. Confusing the two operations is the most common cause of half-applied configurations.
Why does the local connection work and the remote one not?
Because they are two different paths. A client launched on the server without specifying the host uses the Unix socket, which falls under local rules. A remote client goes over TCP and is evaluated against host or hostssl rules. If the file only contains the local line, the second case has no rule covering it and is rejected.
What is the difference between a host line and a hostssl line?
host accepts both encrypted and clear-text TCP connections, hostssl only those with negotiated TLS, hostnossl only clear-text ones. The distinction matters because the error message reports whether the connection was encrypted. If the file only has hostssl and the client does not negotiate TLS, the rejection is correct and the solution is on the client side, not on the server.
Can I use a hostname instead of a CIDR in the address field?
It is supported, but it depends on reverse resolution of the client name and becomes fragile: if DNS changes or does not respond, authentication fails. For server-to-server connections CIDR notation is more predictable and more readable during an audit. Hostnames make sense mainly when clients come from networks with dynamic addresses.
How do I verify that my new line was loaded without waiting for the first error?
Query the pg_hba_file_rules view right after the reload. Every line in the file appears with its line number, the interpreted fields and an error column. If that column is empty for the line you added, the rule is syntactically valid and will be evaluated. If it contains a message, you have the exact position to fix.
Conclusions with Operational Takeaways
The error does not talk about passwords. It talks about authorization, and the server tells you with three pieces of data you must read: client IP, user, database.
- Always ask the server which file it is reading. The path in the data directory is not the one loaded on the Debian or Ubuntu cluster.
- Check first whether you are listening on the network. If listen_addresses is on localhost, no HBA rule will save you, and it takes a restart, not a reload.
- Remember that the first matching rule wins.
- Prefer scram-sha-256 for password connections and leave md5 only where compatibility is needed, knowing that roles with old hashes must be reset.
- Use pg_hba_file_rules after every change: the error column tells you whether the rule will be discarded before a client even tries.
- Always test with -h against the real IP. The local test goes through the Unix socket and proves nothing about the remote path.
Read also: Ubuntu Server Upgrade: do-release-upgrade and Best Practices
Sources
- PostgreSQL: The pg_hba.conf File
- PostgreSQL: Connections and Authentication (listen_addresses, port)
- PostgreSQL: pg_hba_file_rules view
- PostgreSQL: versioning policy and supported releases
Updated: December 2026