Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

PostgreSQL Error 28000: Invalid Authorization Specification

· 6 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

Error 28000 (invalid_authorization_specification) means PostgreSQL rejected the connection before it even checked your password, because the client's authentication request didn't match any rule in pg_hba.conf or the role isn't allowed to authenticate that way. The fix is to open pg_hba.conf, find the line that should match your connection, correct the authentication method or the address range, and reload the server. You need shell access to the database host and permission to edit PostgreSQL's configuration files (usually the postgres system user or sudo).

What You'll Need

  • Shell or terminal access to the machine running PostgreSQL (or its container).
  • Permission to edit files in the data directory (typically /var/lib/postgresql/<version>/main on Debian/Ubuntu, /var/lib/pgsql/<version>/data on RHEL-family, or the path shown by SHOW hba_file;).
  • The exact connection string or client settings that produced the error (host, port, database, user, and whether SSL was used).
  • A way to reload PostgreSQL: pg_ctl reload, systemctl reload postgresql, or SELECT pg_reload_conf(); from an existing session.

Step-by-Step

  1. Read the server log first. The client message is generic; the log line is specific. Look in /var/log/postgresql/ or the log_directory setting for a line like no pg_hba.conf entry for host "10.0.0.5", user "app", database "appdb", SSL off or pg_hba.conf rejects connection ... authentication method 10 not supported. That line tells you exactly which host, user, database and SSL state failed to match.
  2. Locate pg_hba.conf. Connect with any working superuser session and run SHOW hba_file;. If you have no working session, use the path above for your distribution. Open the file in an editor as the postgres user.
  3. Understand the rule format. Each line has: connection type (local, host, hostssl, hostnossl), database, user, address (for host lines), and authentication method. Rules are evaluated top to bottom, first match wins. A line for host all all 127.0.0.1/32 scram-sha-256 will not match a client connecting from 10.0.0.5, and a hostssl line will not match a client that connected without SSL.
  4. Add or fix the matching line. For a remote app server at 10.0.0.5 connecting as user app to database appdb over SSL, add above any broader catch-all: hostssl appdb app 10.0.0.5/32 scram-sha-256. If the client cannot do SSL, use host instead of hostssl. If the client is old and only supports md5, use md5 — but prefer scram-sha-256 and upgrade the client where possible.
  5. Check the authentication method is supported. Error 28000 often appears when the server is set to scram-sha-256 but the client library is too old to negotiate it, or when a method like ident or peer is configured for a TCP connection where it cannot work. peer and ident only make sense for local Unix-socket connections or with a working ident service; for TCP use scram-sha-256, md5, or cert.
  6. Check the role exists and can log in. Run SELECT rolname, rolcanlogin, rolpassword IS NOT NULL FROM pg_authid WHERE rolname = 'app'; as a superuser. If rolcanlogin is false, the role cannot authenticate at all; fix with ALTER ROLE app LOGIN;. If the password hash is null, set one with ALTER ROLE app PASSWORD '...';.
  7. Reload, don't restart, if possible. Run SELECT pg_reload_conf(); or systemctl reload postgresql. A reload re-reads pg_hba.conf without dropping existing connections. Restart only if reload is unavailable.
  8. Retest with the exact same client settings. Use psql "host=10.0.0.5 dbname=appdb user=app sslmode=require" so you reproduce the same SSL and address path. Confirm success before moving on.

Common Mistakes

  • Editing the wrong pg_hba.conf. A cluster can have several data directories; always confirm with SHOW hba_file;.
  • Putting the new rule below a broad catch-all. Because first match wins, a later specific line is ignored if an earlier host all all 0.0.0.0/0 ... line already matched.
  • Using hostssl when the client connects without SSL. The line simply won't match, producing 28000.
  • Forgetting to reload. The file change has no effect until PostgreSQL re-reads it.
  • Confusing 28000 with 28P01. 28P01 is a wrong password; 28000 is a rejected authentication specification — the server never got as far as checking the password.
  • Assuming a firewall issue. A firewall block usually gives a timeout or connection refused, not 28000.

Tips

  • Keep the most specific rules at the top and the catch-all at the bottom; comment each line with the app and date so future changes are safe.
  • Prefer scram-sha-256 over md5; md5 is deprecated in current PostgreSQL versions.
  • Test with psql from the same host as the failing app so address and SSL behaviour match.
  • After any pg_hba.conf edit, run pg_reload_conf() and check the log for syntax errors — a bad file is ignored and the old rules stay active.
  • For containers, remember the config inside the container may be overwritten on restart; change it via the image's documented mechanism or a mounted config.

Troubleshooting

If the error persists after a reload, re-read the log line — it may now name a different host or user than you assumed. Check whether the client is connecting over IPv6 when you added an IPv4 rule (or vice versa); add the matching CIDR. If the client uses a connection pooler such as PgBouncer, the pooler's own pg_hba.conf and user list also apply, so fix both. If you see "authentication method 10 not supported", the client library is too old for scram-sha-256; upgrade the driver or, as a temporary measure, set the role's password to md5 with SET password_encryption = 'md5'; ALTER ROLE app PASSWORD '...'; and use md5 in pg_hba.conf. If you cannot connect at all, start PostgreSQL in single-user mode (postgres --single -D /path/to/data postgres) to edit roles, then reload normally. Never disable authentication entirely (trust for all hosts) as a fix — restrict trust to localhost only, and revert it once the real rule works.

Frequently Asked Questions

What is the difference between error 28000 and 28P01?

28000 means the server rejected the authentication specification before checking credentials — usually a pg_hba.conf mismatch or unsupported auth method. 28P01 means the password was checked and was wrong.

Can error 28000 be caused by the client, not the server?

Yes. An old client library that cannot negotiate scram-sha-256, or one forcing SSL when the server rule is hostnossl, will trigger it. Updating the driver or aligning sslmode with the server rule resolves it.

Do I need to restart PostgreSQL after editing pg_hba.conf?

No. A reload (SELECT pg_reload_conf(); or systemctl reload postgresql) is enough. Restart only if reload fails.

Why does it work locally but fail remotely?

Local Unix-socket connections often use peer or trust rules, while remote TCP connections need a matching host line with a password method. Add the remote client's address range.

Can a firewall cause error 28000?

No. Firewalls produce timeouts or connection refused. If you see 28000, the TCP connection reached PostgreSQL and was rejected by its authentication rules.

Is it safe to set trust for all addresses to test?

No. Use trust only for 127.0.0.1/32 temporarily, and revert it immediately after confirming the real rule works.