> ## Content Index
> Fetch the complete content index at: https://www.ggorantala.dev/llms.txt
> Use this file to discover other available public pages before exploring further.

# FATAL: no pg_hba.conf entry for host (28000): Causes and Fixes
- URL: https://www.ggorantala.dev/postgresql-no-pg-hba-conf-entry/
- Published: 2026-12-01T06:52:39.000Z
- Updated: 2026-12-01T06:52:39.000Z
- Description: 'no pg_hba.conf entry for host' means PostgreSQL heard you and found no rule for your host, user, database and SSL state. Read the last words of the message first, then add one narrow rule and reload. Here's how.
- Author: Gopi Gorantala
- Tags: no-pg-hba-conf-entry, sqlstate-28000, pg-hba-conf, sslmode, pg-hba, pg-connections, postgresql, postgresql-errors

This is the line that did it:

```ini
hostssl   all   all   127.0.0.1/32   scram-sha-256

```

Nothing wrong with it. It's a good rule. It says "anyone may connect from this address, as long as the connection is encrypted". And then the loyalty-points service, whose connection string had `sslmode=disable` in it since somebody copied it from a laptop setup two years ago, got this back on its first connect after the change:

```log
psql: error: connection to server at "127.0.0.1", port 5444 failed: FATAL:  no pg_hba.conf entry for host "127.0.0.1", user "loyalty_app", database "loyalty", no encryption

```

The fix took one word. Finding the word is what this article is about, because "no pg\_hba.conf entry for host" is the most literal error PostgreSQL has, and people still spend an hour on it by reading only the first half.

## The FATAL line, and its older spelling

Here's every shape I could get out of a PostgreSQL 16.15 server (Ubuntu 24.04 package, `psql` 16.15, `lc_messages = 'C'`) in one afternoon of breaking `pg_hba.conf` on purpose:

```log
FATAL:  no pg_hba.conf entry for host "127.0.0.1", user "loyalty_app", database "loyalty", no encryption
FATAL:  no pg_hba.conf entry for host "127.0.0.1", user "loyalty_app", database "loyalty", SSL encryption
FATAL:  no pg_hba.conf entry for replication connection from host "127.0.0.1", user "loyalty_app", no encryption

```

A fourth value, `GSS encryption`, shows up when the client negotiated GSSAPI encryption (Kerberos shops). I didn't set up Kerberos for this, so that one comes from the strings in the 16.15 server binary, not from my terminal.

If you're on 11 or older, or you're reading an old forum thread or an Atlassian KB page, the tail looks different: `SSL off` and `SSL on` instead of `no encryption` and `SSL encryption`. Same check, same meaning. The wording changed when PostgreSQL 12 added GSSAPI encryption and the last field had to describe three states instead of two.

The SQLSTATE is `28000`, `invalid_authorization_specification`. A server with a non-English `lc_messages` translates the text, never the code.

Drivers pass the server's text through unchanged: pgJDBC wraps it in `PSQLException`, psycopg in `OperationalError`, node-postgres puts `28000` in `error.code`. My sandbox couldn't fetch driver packages this run, so there's no driver output here, only `psql`.

## The server answered, so skip the network

The good news hiding in this error: almost everything already worked. DNS resolved, TCP connected, the postmaster accepted the socket, read your startup packet, and repeated your user and database names back to you. If it were a network problem you'd be looking at [Connection refused](https://ggorantala.dev/postgresql-connection-refused-port-5432/?ref=ggorantala.dev) or a timeout instead. If your password were wrong, you'd see [password authentication failed](https://ggorantala.dev/postgresql-password-authentication-failed/?ref=ggorantala.dev), and that one only appears *after* a `pg_hba.conf` line matched. The [connection errors comparison](https://ggorantala.dev/postgresql-connection-errors-compared/?ref=ggorantala.dev) lines all of them up by how far the connection got.

So the question is narrow. Read the four values in the message as the server saw them:

- **host** is the client address *as the server sees it*. Behind Docker, NAT or a load balancer that is not your laptop's IP. In the Hasura and Compose threads it's nearly always something like `172.23.0.4`, the container's address on the Compose network.
- **user** and **database** are what the client sent, not what you think it sent. A default database name or an environment variable can swap these.
- **the last field** is the encryption state of *this* attempt.

My first instinct, years ago, was to stare at the `host` value and start editing CIDR ranges. That's the right column maybe half the time. The last field is the one people skip, and on managed databases it's most of the cases I've seen.

Two queries settle it. `SHOW hba_file` needs superuser or `pg_read_all_settings`; `pg_hba_file_rules` is superuser-only by default; on managed services you often can't read either:

```sql
SHOW hba_file;
SELECT rule_number, line_number, type, database, user_name, address, netmask, auth_method, error
FROM pg_hba_file_rules;

```

And from the client side, one explicit connection with nothing left to defaults:

```bash
psql "host=db.internal port=5432 dbname=loyalty user=loyalty_app sslmode=require connect_timeout=5" -c 'select 1'

```

If that works and the app doesn't, the app is sending something different. Usually `sslmode`, sometimes the database name.

## Break pg\_hba.conf on purpose

Don't do this on a shared server. I used a throwaway cluster: PostgreSQL 16.15 from the Ubuntu 24.04 packages, `initdb` into `/tmp/pglab/data`, port 5444, listening on `127.0.0.1` only, with a self-signed certificate so `ssl = on` works. (No Docker daemon in my sandbox this time. The same steps work inside a `postgres:16` container; `pg_hba.conf` lives in the data directory there too.)

Step 1, the setup. Add to `postgresql.conf`:

```ini
port = 5444
listen_addresses = '127.0.0.1'
ssl = on
lc_messages = 'C'
log_connections = on
log_line_prefix = '%m [%p] %q%u@%d %h app=%a sqlstate=%e '

```

and make `pg_hba.conf` exactly this:

```ini
# TYPE  DATABASE  USER      ADDRESS        METHOD
local   all       postgres                 scram-sha-256
hostssl all       all       127.0.0.1/32   scram-sha-256

```

Create the role and database (`CREATE ROLE loyalty_app LOGIN PASSWORD '...'`, then `CREATE DATABASE loyalty OWNER loyalty_app` as a separate statement, since `CREATE DATABASE` refuses to run inside a transaction block and a multi-statement `psql -c` is one).

Step 2, connect without TLS:

```bash
psql "host=127.0.0.1 port=5444 user=loyalty_app dbname=loyalty sslmode=disable" -c 'select 1'

```

```log
psql: error: connection to server at "127.0.0.1", port 5444 failed: FATAL:  no pg_hba.conf entry for host "127.0.0.1", user "loyalty_app", database "loyalty", no encryption

```

Step 3, leave `sslmode` out entirely. libpq defaults to `prefer`, tries TLS first, and gets in. `pg_stat_ssl` for that backend said `t|TLSv1.3`. That's why the same rule breaks one service and not the other.

Step 4, a physical replication connection (what `pg_basebackup` and a standby use):

```bash
psql "host=127.0.0.1 port=5444 user=loyalty_app replication=true sslmode=disable" -c 'IDENTIFY_SYSTEM'

```

```log
psql: error: connection to server at "127.0.0.1", port 5444 failed: FATAL:  no pg_hba.conf entry for replication connection from host "127.0.0.1", user "loyalty_app", no encryption

```

Step 5, flip the rule to plaintext-only and connect *with* TLS. Replace the `hostssl` line with `hostnossl loyalty all 127.0.0.1/32 scram-sha-256`, reload, then use `sslmode=require`:

```log
psql: error: connection to server at "127.0.0.1", port 5444 failed: FATAL:  no pg_hba.conf entry for host "127.0.0.1", user "loyalty_app", database "loyalty", SSL encryption

```

What you shrank: one rule instead of the dozen a real file has, and a single client address. Production files fail the same way. There's more to read, that's all.

Confirmation that you reproduced *this* error and not a neighbour: `FATAL`, SQLSTATE `28000`, and the words `no pg_hba.conf entry`. If you see `pg_hba.conf rejects connection` instead, a line *did* match and its method is `reject` (more below). If you see `password authentication failed`, a line matched and the password didn't.

Teardown: `pg_ctl -D /tmp/pglab/data stop`, then delete the directory. Nothing else on the machine was touched.

## Why it broke, the simple version

PostgreSQL reads `pg_hba.conf` top to bottom and uses the first line whose connection type, database, user and address all match the incoming connection. If it reaches the end without a match, you get this error. There is no default allow. "Connection type" includes whether the connection is encrypted, which is why the last word in the message matters so much.

## How PostgreSQL walks the file

The *postmaster* is the main PostgreSQL process; it accepts connections and starts a *backend* process for each. `pg_hba.conf` (host-based authentication) decides, per connection, which authentication method runs, or whether it's allowed at all. The column-by-column tour is in [pg\_hba.conf explained](https://ggorantala.dev/pg-hba-conf-explained/?ref=ggorantala.dev).

The backend gets the startup packet (user, database, whether this is a replication connection) and already knows the client address and whether TLS or GSSAPI was negotiated. Then it walks the parsed rules in order:

```log
for each rule, top to bottom:
  type      local | host | hostssl | hostnossl | hostgssenc | hostnogssenc  -> matches this socket + encryption?
  database  all | name | replication | sameuser | samerole | @file          -> matches?
  user      all | name | +group | @file                                     -> matches?
  address   CIDR / hostname (not for local)                                 -> matches the client IP?
  first rule where all of that is true wins -> its method runs (scram-sha-256, peer, reject, ...)
no rule matched -> FATAL: no pg_hba.conf entry for ...

```

The message is built from exactly those inputs. The source in `src/backend/libpq/auth.c` has two formats, one for normal connections and one ending `for replication connection from host`, and appends the encryption state as the last argument. That's the whole decision. No hidden fallbacks.

Two things surprised me while breaking it.

First, the `replication` keyword in the database column only matches *physical* replication. When I connected with `replication=database` (that's a logical replication connection, the kind Debezium and other CDC tools open), I got the *normal* message, naming database `loyalty`, not the replication one. The docs say this in a sentence that's easy to miss: logical replication connections name a real database and are matched like any other connection. So a Debezium connector needs a rule for its database, while a standby needs a rule with `replication` in the database column. People add the wrong one and wonder why nothing changed.

Second, and this one cost me real minutes: `pg_hba.conf` is only read at startup and on reload. Mid-lab I edited the file and connected again. Same error. `pg_hba_file_rules` cheerfully showed the *new* rule, because that view parses the file on disk as it is right now, not what the server has loaded. It's a validator, not a mirror. After `SELECT pg_reload_conf();` the connection worked.

Then it got worse in an instructive way. I added a broken line (`10.20.0.0/33`, a mask that can't exist) and reloaded. The server log said:

```log
LOG:  invalid CIDR mask in address "10.20.0.0/33"
CONTEXT:  line 5 of configuration file "/tmp/pglab/data/pg_hba.conf"
LOG:  /tmp/pglab/data/pg_hba.conf was not reloaded

```

and the *old* rules stayed active. My plaintext connection, which the new file would have refused, still went through. That's a safety feature, since a typo can't lock everyone out. It's also how you end up with a file on disk that says one thing while the server enforces another for weeks. `pg_hba_file_rules` showed it immediately, with the `error` column filled in for line 5.

For completeness: if your rule says `hostssl` and the server has `ssl = off`, the line can never match, and the server logs `hostssl record cannot match because SSL is disabled` when it loads the file. Every non-TLS client then falls through to "no entry".

## Fixing 'no pg\_hba.conf entry for host' without opening the door

Start from the last field of the message, because it decides which fix you need.

**It says `no encryption`, and the server wants TLS.** Fix the client, not the server. Set `sslmode=require` (or better, `verify-full` with the CA certificate) in the connection string. In a libpq URI that's `?sslmode=require`; in pgJDBC it's the `sslmode` property, and the current [pgJDBC docs](https://jdbc.postgresql.org/documentation/use/?ref=ggorantala.dev) list `prefer` as its default, so an explicit `sslmode=disable` somewhere in your config is the usual culprit. node-postgres doesn't attempt TLS unless you pass an `ssl` option. The [connection string formats](https://ggorantala.dev/postgresql-connection-string-formats/?ref=ggorantala.dev) article has the spelling for each client.

This is the RDS case. On RDS for PostgreSQL 15 and later, the `rds.force_ssl` parameter defaults to `1` ([AWS docs](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/PostgreSQL.Concepts.General.SSL.html?ref=ggorantala.dev)), so a plaintext client gets exactly this error with `no encryption` on the end. The pgsql-general thread "Connection error to new pg15 instance" is that discovery in real time. Turning `rds.force_ssl` off in the parameter group works and is the wrong fix.

**It says `SSL encryption`, and the rule is `hostnossl`.** Rare, but it happens when someone wrote a "no TLS on the internal network" rule. Change the rule to `host` (matches either) or `hostssl`, not the client.

**The host isn't what you expected.** Add a rule for the address the server actually sees, as narrow as you can make it:

```ini
# before: only the app subnet that existed last year
hostssl  loyalty  loyalty_app  10.20.1.0/24   scram-sha-256

# after: add the new subnet, same database, same role, still TLS
hostssl  loyalty  loyalty_app  10.20.1.0/24   scram-sha-256
hostssl  loyalty  loyalty_app  10.20.7.0/24   scram-sha-256

```

For Docker Compose, the client address is the app container on the Compose network. The official `postgres` image's entrypoint appends a catch-all `host all all all` line with the method from `POSTGRES_HOST_AUTH_METHOD` (scram-sha-256 on current tags; check the entrypoint for your tag) when it initialises a fresh data directory, which is why the image rarely hits this error until somebody mounts their own `pg_hba.conf`.

**It's a replication connection.** Physical: a line with `replication` in the database column. Logical (CDC): a line naming the actual database. Both need a role with the `REPLICATION` attribute, which is a separate problem.

**The host is `::1`.** `localhost` can resolve to the IPv6 loopback first. If your file only has `127.0.0.1/32`, the message names `"::1"`. Add the `::1/128` line (`initdb`'s default file has both), or connect to `127.0.0.1` explicitly. My sandbox had no IPv6 loopback, so I didn't run this variant.

Then reload, and check that it took:

```sql
SELECT pg_reload_conf();                                   -- needs superuser or an explicit GRANT EXECUTE
SELECT line_number, error FROM pg_hba_file_rules WHERE error IS NOT NULL;   -- should return nothing

```

`pg_reload_conf()` returning `t` only means the signal was sent. Check the server log for `was not reloaded`. (Where that log lives depends on the packager; see [finding the PostgreSQL log](https://ggorantala.dev/postgresql-server-logs-location/?ref=ggorantala.dev).)

Cost: a reload doesn't drop existing sessions. Requiring TLS adds a handshake per new connection, which a pool amortises.

What isn't a fix, even though it's the top answer in half the threads I read:

- `host all all 0.0.0.0/0 trust`. That's every role, including `postgres`, from anywhere, with no password. You'll forget it's there.
- `host all all 0.0.0.0/0 md5` as a "temporary" catch-all. Better than `trust`, still puts your login prompt on every network that can route to you, and `md5` is deprecated from PostgreSQL 18.
- Turning off forced TLS on a managed service so an old client connects. Fix the client.
- Making the app role a superuser. It doesn't even help: `pg_hba.conf` is checked before role attributes come into it, and superusers get no exemption.

## What I'd do instead

Keep `pg_hba.conf` short, explicit and in version control, and write it per role and per database rather than `all all`:

```ini
# TYPE    DATABASE     USER            ADDRESS         METHOD
local     all          postgres                        peer
hostssl   loyalty      loyalty_app     10.20.0.0/16    scram-sha-256
hostssl   loyalty      loyalty_migrate 10.20.9.0/24    scram-sha-256
hostssl   replication  replicator      10.30.0.10/32   scram-sha-256
hostssl   loyalty      debezium        10.30.0.20/32   scram-sha-256
host      all          all             0.0.0.0/0       reject

```

The explicit `reject` at the end changes the error to `pg_hba.conf rejects connection for host ...`. I like that. It tells whoever reads the log that the refusal was a decision someone made on purpose, not a gap. In my lab, a `reject` line placed *above* the `hostssl` rule produced that message even for a perfectly good TLS connection, which is the first-match rule biting from the other direction.

From PostgreSQL 16 you can split the file with `include`, `include_dir` and `include_if_exists`, which makes per-team or per-app fragments manageable. And put `sslmode=verify-full` in every app's connection string from day one, so a server-side switch to `hostssl` is a non-event.

## The test that would have caught this

The loyalty-points failure would have been caught by any CI job that connects with the production connection string's options against a database whose `pg_hba.conf` matches production's. A Testcontainers PostgreSQL with your real `pg_hba.conf` mounted, and the app's own config (not a test override) doing the connecting.

On the server side:

- Run `SELECT * FROM pg_hba_file_rules WHERE error IS NOT NULL` after every edit, and fail the deploy if it returns rows.
- Alert on `was not reloaded` in the server log.
- Keep the file in git and review changes to it like code, with the reason for each rule in a comment.
- With `log_connections = on`, PostgreSQL 16 logs which file and line authenticated each connection (`connection authenticated: identity="loyalty_app" method=scram-sha-256 (/tmp/pglab/data/pg_hba.conf:3)` in my lab). Before tightening a rule, grep a week of logs for which lines are actually in use.

Version notes worth re-checking on upgrade: the message tail is `SSL off`/`SSL on` up to 11 and `no encryption`/`SSL encryption`/`GSS encryption` from 12\. `pg_hba_file_rules` exists from 10; on 16 it also has `rule_number` and, for included files, `file_name`. `include` directives are 16+. MD5 password authentication is deprecated in 18, so any `md5` rule you add today is debt.

Scope, honestly: I reproduced every variant above against 16.15 in a disposable cluster, read the message formats out of the 16.15 server binary, and checked the old `SSL off` wording and the RDS default against the threads and AWS docs linked here. I did not run 12 through 15, 17, 18 or 19 servers this time, or any driver.

## The short list

- The last word decides the fix. `no encryption` against a `hostssl` rule means the client needs `sslmode=require`, not a looser file.
- The host in the message is what the server sees. Behind Docker or NAT it isn't your laptop.
- `pg_hba_file_rules` shows the file on disk, not what's loaded. Reload, then check the log for `was not reloaded`.
- Physical replication matches the `replication` keyword; logical (CDC) connections match the real database name.
- `trust` and `0.0.0.0/0` aren't fixes. They're the next incident.

## Things people search after this one

### How do I fix "no pg\_hba.conf entry for host" on AWS RDS?

On RDS for PostgreSQL 15 and later, `rds.force_ssl` defaults to 1, so a client connecting without TLS gets this error ending in `no encryption`. Set `sslmode=require` (or `verify-full` with the RDS CA bundle) in the client. You can't edit `pg_hba.conf` on RDS, and switching `rds.force_ssl` off weakens every connection to fix one client.

### Where is pg\_hba.conf?

Ask the server: `SHOW hba_file;` as a superuser. It's in the data directory for `initdb`\-created clusters and the Docker image, and under `/etc/postgresql/<major>/main/` on Debian and Ubuntu packages. Managed services don't expose it.

### Do I need to restart PostgreSQL after editing pg\_hba.conf?

No. A reload is enough: `SELECT pg_reload_conf();`, `pg_ctl reload`, or `systemctl reload postgresql`. But if the new file has a syntax error, PostgreSQL keeps the old rules and logs `pg_hba.conf was not reloaded`, so check the log or `pg_hba_file_rules` afterwards.

### Why does it say "replication connection" when I'm not replicating?

You (or your tool) connected with `replication=true`, which `pg_basebackup` and standbys do. Those connections only match rules with `replication` in the database column. Logical replication tools like Debezium connect with a real database name and need a normal rule for that database instead.