PostgreSQL 17.12Lab-verified · 2026-11-30

PostgreSQL 28000: no pg_hba.conf entry for host

The server has no pg_hba.conf rule (or no login role) for this client address, user and database.

PostgreSQL 17.12
28000: no pg_hba.conf entry for host "172.17.0.3", user "app_user", database "shop", no encryption

Jump to a cause

  1. 01No pg_hba.conf line allows the client's IP address (only localhost is allowed)
  2. 02A newly created user is not covered by the existing pg_hba.conf line
  3. 03No role exists for the login name (e.g. the OS user name)
  4. 04The role was created without LOGIN (CREATE ROLE is NOLOGIN by default)

Lab-verifiedReproduced and fixed on PostgreSQL 17.12 · 2026-11-30 · container image postgres:17

SQLSTATE 28000 is invalid_authorization_specification. The most searched form is FATAL: no pg_hba.conf entry for host "172.17.0.3", user "app_user", database "shop", no encryption: the server checks pg_hba.conf from top to bottom and no line matches that host, user and database. The same code is also used for role "ubuntu" does not exist and role "app_user" is not permitted to log in.

We reproduced all four causes on PostgreSQL 17. For the pg_hba cases, psql connects to the server's own IP (172.17.0.3) instead of 127.0.0.1, like a remote client. The pg_hba_file_rules view shows which rules the server has, so you can see why nothing matched.

01No pg_hba.conf line allows the client's IP address (only localhost is allowed)

pg_hba_file_rules shows host rules only for 127.0.0.1 and ::1. A connection from 172.17.0.3 matches none of them, so the server refuses it before checking the password. The host in the message is the client address the server saw, and that is the address you need to allow.

Setup
Setuprun as postgres
CREATE DATABASE shop;
CREATE ROLE app_user LOGIN PASSWORD 'Shop2026';
OUTPUT
CREATE DATABASE
CREATE ROLE
Setuprun as postgres
SELECT rule_number, type, database, user_name, address, netmask, auth_method FROM pg_hba_file_rules;
OUTPUT
 rule_number | type  |   database    | user_name |  address  |                 netmask                 |  auth_method
-------------+-------+---------------+-----------+-----------+-----------------------------------------+---------------
           1 | local | {all}         | {all}     |           |                                         | trust
           2 | host  | {all}         | {all}     | 127.0.0.1 | 255.255.255.255                         | scram-sha-256
           3 | host  | {all}         | {all}     | ::1       | ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff | trust
           4 | local | {replication} | {all}     |           |                                         | trust
           5 | host  | {replication} | {all}     | 127.0.0.1 | 255.255.255.255                         | trust
           6 | host  | {replication} | {all}     | ::1       | ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff | trust
(6 rows)
Reproducerun as app_user
$ PGPASSWORD='Shop2026' psql -h <server-ip> -U app_user -d shop
SELECT current_user, current_database(), inet_client_addr();
✕ ERROR
psql: error: connection to server at "172.17.0.3", port 5432 failed: FATAL:  no pg_hba.conf entry for host "172.17.0.3", user "app_user", database "shop", no encryption
SERVER LOG (same moment)
FATAL:  28000: no pg_hba.conf entry for host "172.17.0.3", user "app_user", database "shop", no encryption
Fixrun as postgres
COPY (SELECT 'host  shop  app_user  172.17.0.0/16  scram-sha-256')
  TO '/var/lib/postgresql/data/pg_hba_lab.conf';
SELECT pg_reload_conf();
OUTPUT
COPY 1
 pg_reload_conf
----------------
 t
(1 row)
Fixrun as postgres
SELECT rule_number, type, database, user_name, address, netmask, auth_method FROM pg_hba_file_rules;
OUTPUT
 rule_number | type  |   database    | user_name  |  address   |                 netmask                 |  auth_method
-------------+-------+---------------+------------+------------+-----------------------------------------+---------------
           1 | local | {all}         | {all}      |            |                                         | trust
           2 | host  | {all}         | {all}      | 127.0.0.1  | 255.255.255.255                         | scram-sha-256
           3 | host  | {all}         | {all}      | ::1        | ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff | trust
           4 | local | {replication} | {all}      |            |                                         | trust
           5 | host  | {replication} | {all}      | 127.0.0.1  | 255.255.255.255                         | trust
           6 | host  | {replication} | {all}      | ::1        | ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff | trust
           7 | host  | {shop}        | {app_user} | 172.17.0.0 | 255.255.0.0                             | scram-sha-256
(7 rows)

Add a line of the form host <database> <user> <client network> scram-sha-256. In this lab the line is written with COPY into a file that pg_hba.conf includes; on a normal server you add the same line to pg_hba.conf with an editor. Then run SELECT pg_reload_conf();. Rule 7 appears in pg_hba_file_rules and the same connection succeeds with inet_client_addr 172.17.0.3.

After the fixrun as app_user
$ PGPASSWORD='Shop2026' psql -h <server-ip> -U app_user -d shop
SELECT current_user, current_database(), inet_client_addr();
✓ SUCCESS
 current_user | current_database | inet_client_addr
--------------+------------------+------------------
 app_user     | shop             | 172.17.0.3
(1 row)

02A newly created user is not covered by the existing pg_hba.conf line

The existing rule allows only app_user to shop from 172.17.0.0/16. report_user was created later and has the right password and CONNECT privilege, but no pg_hba.conf line matches it, so it fails with the same message naming user "report_user".

Setup
Setuprun as postgres
CREATE DATABASE shop;
CREATE ROLE app_user LOGIN PASSWORD 'Shop2026';
CREATE ROLE report_user LOGIN PASSWORD 'Report2026';
GRANT CONNECT ON DATABASE shop TO report_user;
COPY (SELECT 'host  shop  app_user  172.17.0.0/16  scram-sha-256')
  TO '/var/lib/postgresql/data/pg_hba_lab.conf';
SELECT pg_reload_conf();
OUTPUT
CREATE DATABASE
CREATE ROLE
CREATE ROLE
GRANT
COPY 1
 pg_reload_conf
----------------
 t
(1 row)
Setuprun as postgres
SELECT rule_number, type, database, user_name, address, netmask, auth_method FROM pg_hba_file_rules;
OUTPUT
 rule_number | type  |   database    | user_name  |  address   |                 netmask                 |  auth_method
-------------+-------+---------------+------------+------------+-----------------------------------------+---------------
           1 | local | {all}         | {all}      |            |                                         | trust
           2 | host  | {all}         | {all}      | 127.0.0.1  | 255.255.255.255                         | scram-sha-256
           3 | host  | {all}         | {all}      | ::1        | ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff | trust
           4 | local | {replication} | {all}      |            |                                         | trust
           5 | host  | {replication} | {all}      | 127.0.0.1  | 255.255.255.255                         | trust
           6 | host  | {replication} | {all}      | ::1        | ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff | trust
           7 | host  | {shop}        | {app_user} | 172.17.0.0 | 255.255.0.0                             | scram-sha-256
(7 rows)
Reproducerun as report_user
$ PGPASSWORD='Report2026' psql -h <server-ip> -U report_user -d shop
SELECT current_user, current_database();
✕ ERROR
psql: error: connection to server at "172.17.0.3", port 5432 failed: FATAL:  no pg_hba.conf entry for host "172.17.0.3", user "report_user", database "shop", no encryption
SERVER LOG (same moment)
FATAL:  28000: no pg_hba.conf entry for host "172.17.0.3", user "report_user", database "shop", no encryption
Fixrun as postgres
COPY (VALUES ('host  shop  app_user     172.17.0.0/16  scram-sha-256'),
             ('host  shop  report_user  172.17.0.0/16  scram-sha-256'))
  TO '/var/lib/postgresql/data/pg_hba_lab.conf';
SELECT pg_reload_conf();
OUTPUT
COPY 2
 pg_reload_conf
----------------
 t
(1 row)
Fixrun as postgres
SELECT rule_number, type, database, user_name, address, netmask, auth_method FROM pg_hba_file_rules;
OUTPUT
 rule_number | type  |   database    |   user_name   |  address   |                 netmask                 |  auth_method
-------------+-------+---------------+---------------+------------+-----------------------------------------+---------------
           1 | local | {all}         | {all}         |            |                                         | trust
           2 | host  | {all}         | {all}         | 127.0.0.1  | 255.255.255.255                         | scram-sha-256
           3 | host  | {all}         | {all}         | ::1        | ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff | trust
           4 | local | {replication} | {all}         |            |                                         | trust
           5 | host  | {replication} | {all}         | 127.0.0.1  | 255.255.255.255                         | trust
           6 | host  | {replication} | {all}         | ::1        | ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff | trust
           7 | host  | {shop}        | {app_user}    | 172.17.0.0 | 255.255.0.0                             | scram-sha-256
           8 | host  | {shop}        | {report_user} | 172.17.0.0 | 255.255.0.0                             | scram-sha-256
(8 rows)

Add a line for the new user (or use a group with +role / all if that fits your policy) and reload. After pg_reload_conf() rule 8 is listed and report_user connects to shop.

After the fixrun as report_user
$ PGPASSWORD='Report2026' psql -h <server-ip> -U report_user -d shop
SELECT current_user, current_database();
✓ SUCCESS
 current_user | current_database
--------------+------------------
 report_user  | shop
(1 row)

03No role exists for the login name (e.g. the OS user name)

Roles are separate from operating system users. Connecting as ubuntu fails because the server has no role with that name; pg_roles returns 0 rows.

Setup
Setuprun as postgres
SELECT rolname FROM pg_roles WHERE rolname = 'ubuntu';
OUTPUT
 rolname
---------
(0 rows)
Reproducerun as ubuntu
$ psql -U ubuntu -d lab
SELECT current_user, current_database();
✕ ERROR
psql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: FATAL:  role "ubuntu" does not exist
SERVER LOG (same moment)
FATAL:  28000: role "ubuntu" does not exist
Fixrun as postgres
CREATE ROLE ubuntu LOGIN;
OUTPUT
CREATE ROLE

Create the role with CREATE ROLE ubuntu LOGIN; (as a superuser or a role with CREATEROLE). The same connection then works and current_user is ubuntu.

After the fixrun as ubuntu
$ psql -U ubuntu -d lab
SELECT current_user, current_database();
✓ SUCCESS
 current_user | current_database
--------------+------------------
 ubuntu       | lab
(1 row)

04The role was created without LOGIN (CREATE ROLE is NOLOGIN by default)

CREATE ROLE app_user PASSWORD '...' creates a role that cannot log in, even with the right password. CREATE USER adds LOGIN automatically, CREATE ROLE does not.

Setup
Setuprun as postgres
CREATE ROLE app_user PASSWORD 'Shop2026';
OUTPUT
CREATE ROLE
Reproducerun as app_user
$ PGPASSWORD='Shop2026' psql -h 127.0.0.1 -U app_user -d lab
SELECT current_user, current_database();
✕ ERROR
psql: error: connection to server at "127.0.0.1", port 5432 failed: FATAL:  role "app_user" is not permitted to log in
SERVER LOG (same moment)
FATAL:  28000: role "app_user" is not permitted to log in
Checkrun as postgres
SELECT rolname, rolcanlogin FROM pg_roles WHERE rolname = 'app_user';
OUTPUT
 rolname  | rolcanlogin
----------+-------------
 app_user | f
(1 row)
Fixrun as postgres
ALTER ROLE app_user LOGIN;
OUTPUT
ALTER ROLE

pg_roles.rolcanlogin is f. Run ALTER ROLE app_user LOGIN; and the same password works.

After the fixrun as app_user
$ PGPASSWORD='Shop2026' psql -h 127.0.0.1 -U app_user -d lab
SELECT current_user, current_database();
✓ SUCCESS
 current_user | current_database
--------------+------------------
 app_user     | lab
(1 row)

FAQ

How do I fix FATAL: no pg_hba.conf entry for host in PostgreSQL?

Read the host, user and database in the message, then add a pg_hba.conf line that matches all three (for example host shop app_user 172.17.0.0/16 scram-sha-256) and run SELECT pg_reload_conf();. Check the loaded rules with SELECT * FROM pg_hba_file_rules;.

It works from localhost but not from another machine. Why?

The default rules allow 127.0.0.1 and ::1. A connection from another address needs its own host line for that client network.

What does FATAL: role does not exist mean in PostgreSQL?

There is no role with the name you logged in as. When you omit -U, psql uses your operating system user name, which often has no matching role. Create the role or log in with an existing one.

Why is my role not permitted to log in?

It was created with CREATE ROLE without LOGIN. Check rolcanlogin in pg_roles and run ALTER ROLE name LOGIN;.

What is the difference between CREATE USER and CREATE ROLE?

They are the same command except that CREATE USER includes LOGIN by default. A role made with CREATE ROLE needs LOGIN added to connect.

How we verify

Each scenario starts from fresh database users. A script runs the setup, confirms the exact error code, applies the fix and runs the statement again. The output shown is what the database printed, saved by the script.

lab_a and lab_b are ordinary roles created for the test, each owning a schema of the same name; postgres is the superuser. PostgreSQL 17.12