How to Fix Postgres Error 28000 Invalid Authorization Specification

Published
Length
3 min read

Luis Felipe Dias

All posts

The postgres error 28000 invalid authorization specification happens when the server blocks a login request. You fix it by matching client role, host address, and encryption settings to server rules. In the official database rules, state 28000 maps to the invalid authorization specification condition. The internal engine macro for this specific failure is ERRCODE_INVALID_AUTHORIZATION_SPECIFICATION. Unlike password failures, this error means the server has no matching rule for the request. Your

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

The postgres error 28000 invalid authorization specification happens when the server blocks a login request. You fix it by matching client role, host address, and encryption settings to server rules.

In the official database rules, state 28000 maps to the invalid authorization specification condition. The internal engine macro for this specific failure is ERRCODE_INVALID_AUTHORIZATION_SPECIFICATION. Unlike password failures, this error means the server has no matching rule for the request. Your database sees the incoming network packet, checks its host rules, and drops the request.

What causes postgres error 28000 invalid authorization specification

This failure begins before the database checks a user password or runs any query. The database engine reads its host rules from top to bottom on each login attempt. Each rule checks the request type, target database name, user role, and client IP address. If no line matches all four values, the engine returns state 28000 right away.

A common trigger in production is a shift in client IP addresses after a deploy. New app containers or serverless workers often get fresh IP ranges in the cloud network. If the database host rules only list the old subnet, new nodes cannot log in. The engine rejects them with the 28000 code because their source address is unknown.

Transport encryption mismatches also cause this exact error code in cloud clusters and local setups. Many teams force encrypted links on the server to protect data moving across the network. If an app tries to log in over an unencrypted link, the server blocks it. The host file might only include rules for encrypted traffic, leaving plain traffic without a match.

Role and database name typos in the app settings trigger this error as well. When a host rule only allows specific group roles, an unknown user name fails fast. Missing client certificates during mutual TLS checks will also return state 28000 to the client.

How to diagnose and fix state 28000 safely in production

Start your check by reading the server error log instead of the client app log. Client drivers only show the generic 28000 code to avoid leaking details to attackers. The server log records the exact IP address, user role, database name, and encryption state. This log line tells you right away why the login attempt missed the active rules.

Dynamic Authorization + End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Once you find the mismatch, update your host rules with the smallest possible scope. Never open the database to all IP addresses or disable password checks to fix a bug. Add the exact CIDR subnet for your app tier and require encrypted links for remote hosts. Reload the server settings so the database applies the updated rules without dropping active sessions.

You should also review how roles and privileges work after the user logs in. The special role name PUBLIC grants a privilege to every role on the system. By default, PUBLIC receives CONNECT and TEMPORARY on databases, and EXECUTE on functions and procedures. The object owner can revoke these default rights to lock down the database.

If an owner revokes CONNECT from PUBLIC, you must grant it to valid roles. Group roles can be set up to manage privileges when there are many users. Users are then granted membership in the group role to keep rules clean and simple. In PostgreSQL 15 and later, default settings block users from creating objects in public schemas. In earlier versions, an admin removes that ability by revoking CREATE on public from PUBLIC. For read access, the SELECT privilege allows reading from specific columns of a table or view.

Check every Postgres query on the wire

Database roles and network rules decide who can open a session. They do not read what each SQL statement does after login. With hoop.dev, you run an open-source proxy, a sidecar for your Postgres, inline in the Postgres wire protocol. On every query an AI agent or engineer runs against production, hoop.dev decides to pass, mask, block, or hold it for human review. Your apps and agents keep their login details and change only the host and port in the connection string their tool uses.

Before a query runs, hoop.dev guardrails refuse bad deletes or drops with a real Postgres error, or hold risky queries for approval. On the way back, hoop.dev data masking rewrites sensitive values in returned rows in memory, and every verdict goes to the audit trail. Furthermore, hoop.dev holds SOC 2 Type II, is MIT licensed, and generates evidence for HIPAA, GDPR, and PCI DSS. See the code on GitHub.

Frequently asked questions

How is error 28000 different from error 28P01 in Postgres?

State 28000 means no host rule matched the client IP, database, role, or TLS state. State 28P01 means a rule matched, but the client sent the wrong password or token.

Why does state 28000 happen when TLS is not enabled on the client?

Servers often use host rules that only accept encrypted links from remote network addresses. When a client tries an unencrypted login, it misses those rules and triggers state 28000.

Can missing database privileges cause an authorization failure during login?

Yes, login fails if an owner revokes default CONNECT rights from PUBLIC without new grants. Grant CONNECT on the target database to a group role and add your users there.

The query runs. The emails stay hidden.