// PostgreSQL error reference

PostgreSQL 28000: invalid authorization specification

The server refused the login before checking a password: no pg_hba.conf rule matches, the role doesn't exist, or it can't log in.

SQLSTATE
28000
Name
invalid_authorization_specification
Category
Invalid Authorization Specification
Error message
no pg_hba.conf entry for host "10.0.0.5", user "app", database "shop", no encryption

What it means

28000 covers login failures other than a wrong password (28P01). The most common is no pg_hba.conf entry: the server's host-based authentication file has no line that matches this client's address, user, database and encryption. Others with this code are role "app" does not exist and role "app" is not permitted to log in (the role lacks the LOGIN attribute).

The message lists exactly what the server saw, which is what you need to match in pg_hba.conf. The last part says whether the connection was encrypted: a rule of type hostssl only matches SSL connections.

Common causes

  • Connecting from a new IP address or network that no pg_hba.conf line covers.
  • The client connects without SSL but the only matching rule is hostssl (or with SSL when the rule is hostnossl).
  • A rule that lists specific users or databases that don't include this one.
  • The role doesn't exist on this server, or was created with CREATE ROLE (which defaults to NOLOGIN) instead of CREATE USER.

How to fix it

  1. Add a pg_hba.conf line for the client, above any broader reject line, then reload. For example hostssl shop app 10.0.0.0/24 scram-sha-256.

    SELECT pg_reload_conf();
    SELECT line_number, type, database, user_name, address, auth_method, error
    FROM pg_hba_file_rules;
  2. Allow the role to log in, or create it.

    ALTER ROLE app WITH LOGIN;
    CREATE ROLE app WITH LOGIN PASSWORD 'strong-password';
  3. Make sure the server listens on the network at all (listen_addresses), and that the client uses SSL if the rule needs it, for example sslmode=require.

Related errors

The code and message text are from the PostgreSQL documentation, Appendix A: PostgreSQL Error Codes. Browse the full PostgreSQL error list or search every database error.

// fewer errors, faster fixes

Work on PostgreSQL in SQLly

A native SQL client for macOS, Windows and Linux with schema-aware IntelliSense, guardrails for risky statements and clear error messages, for PostgreSQL and the other databases you use.