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
CREATE DATABASE shop;
CREATE ROLE app_user LOGIN PASSWORD 'Shop2026';CREATE DATABASE
CREATE ROLESELECT rule_number, type, database, user_name, address, netmask, auth_method FROM pg_hba_file_rules; 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)$ PGPASSWORD='Shop2026' psql -h <server-ip> -U app_user -d shopSELECT current_user, current_database(), inet_client_addr();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 encryptionFATAL: 28000: no pg_hba.conf entry for host "172.17.0.3", user "app_user", database "shop", no encryptionCOPY (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();COPY 1
pg_reload_conf
----------------
t
(1 row)SELECT rule_number, type, database, user_name, address, netmask, auth_method FROM pg_hba_file_rules; 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.
$ PGPASSWORD='Shop2026' psql -h <server-ip> -U app_user -d shopSELECT current_user, current_database(), inet_client_addr(); 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
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();CREATE DATABASE
CREATE ROLE
CREATE ROLE
GRANT
COPY 1
pg_reload_conf
----------------
t
(1 row)SELECT rule_number, type, database, user_name, address, netmask, auth_method FROM pg_hba_file_rules; 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)$ PGPASSWORD='Report2026' psql -h <server-ip> -U report_user -d shopSELECT current_user, current_database();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 encryptionFATAL: 28000: no pg_hba.conf entry for host "172.17.0.3", user "report_user", database "shop", no encryptionCOPY (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();COPY 2
pg_reload_conf
----------------
t
(1 row)SELECT rule_number, type, database, user_name, address, netmask, auth_method FROM pg_hba_file_rules; 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.
$ PGPASSWORD='Report2026' psql -h <server-ip> -U report_user -d shopSELECT current_user, current_database(); 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
SELECT rolname FROM pg_roles WHERE rolname = 'ubuntu'; rolname
---------
(0 rows)$ psql -U ubuntu -d labSELECT current_user, current_database();psql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: FATAL: role "ubuntu" does not existFATAL: 28000: role "ubuntu" does not existCREATE ROLE ubuntu LOGIN;CREATE ROLECreate 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.
$ psql -U ubuntu -d labSELECT current_user, current_database(); 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
CREATE ROLE app_user PASSWORD 'Shop2026';CREATE ROLE$ PGPASSWORD='Shop2026' psql -h 127.0.0.1 -U app_user -d labSELECT current_user, current_database();psql: error: connection to server at "127.0.0.1", port 5432 failed: FATAL: role "app_user" is not permitted to log inFATAL: 28000: role "app_user" is not permitted to log inSELECT rolname, rolcanlogin FROM pg_roles WHERE rolname = 'app_user'; rolname | rolcanlogin
----------+-------------
app_user | f
(1 row)ALTER ROLE app_user LOGIN;ALTER ROLEpg_roles.rolcanlogin is f. Run ALTER ROLE app_user LOGIN; and the same password works.
$ PGPASSWORD='Shop2026' psql -h 127.0.0.1 -U app_user -d labSELECT current_user, current_database(); 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