GrepBoardTools
Sites ▾

Tools / Server config

pg_hba.conf rule checker

Paste the file, then fill in what the client sends: socket or TCP, SSL, database, user and the address the server sees.

What you type is calculated only in your browser and is not sent to a server.

Paste the whole file — comments and blank lines count for line numbers.

Examples
Connection

SSL = sslmode=require and the like. GSSAPI = gssencmode with Kerberos.

pg_basebackup, a standby, pg_receivewal (replication=true). Logical replication counts as a normal connection.

Case-sensitive, as sent by the client.

Empty: psql uses the user name.

The address the server sees: IPv4 or IPv6, no host names.

Direct and indirect, comma separated, for +group and samerole. - = none. Empty = unknown.

Result

Line 6 matches → scram-sha-256

line 6
host    app             +app_users      10.0.0.0/24             scram-sha-256

What it does

For every new connection PostgreSQL reads pg_hba.conf from the top and uses the first line whose connection type, database, user and address all match. This tool follows the same order: it shows which line is chosen, its authentication method, and for each line above it why it did not match. When nothing matches it prints the no pg_hba.conf entry for host … message the server would log.

Examples

RulesConnectionResult
only host all all 127.0.0.1/32 scram-sha-256psql -h ::1no match (IPv4 rule, IPv6 client)
host app +app_users 10.0.0.0/24 scram-sha-25610.0.0.5 · alice · member of app_usersmatch → scram-sha-256
host all all 0.0.0.0/0 reject, then host all bob 0.0.0.0/0 md5bobstops at reject — the next line is never tried
local all all identUnix socketapplied as peer
host all all 10.0.0.0/8 md5 above host replication all 10.0.0.0/8 md5pg_basebackupthe replication line matches — all does not cover physical replication
host all all 10.0.0.7 255.255.0.255 md510.0.200.7match — the mask is applied bit by bit, contiguous or not

Common mistakes

  • localhost goes to ::1 — psql -h localhost may connect over ::1. With only a 127.0.0.1/32 line, nothing matches or a later line catches it. When the address is 127.0.0.1 or ::1 the tool also checks the other one.
  • Expecting a fall-through — if authentication fails on the matching line (wrong password, peer mismatch) the connection fails; later lines are not tried. reject ends the search too. Put narrow lines first and broad ones last.
  • Quoted keywords — "all" and "replication" are no longer keywords; they match a database or user with that name. A value starting with /, such as "/^c", is still a regular expression when quoted.
  • Editing without a reload — the file is read at startup and on reload. If any line is invalid, a reload keeps the old rules and a startup fails.

How it was checked

Before publishing, eight rule sets were loaded into PostgreSQL 17.11 (the postgres:17 container) and real connections were made from four client containers on different IPv4 and IPv6 addresses, plus the server's own socket, 127.0.0.1 and ::1. Each set was first loaded with every method replaced by password and a wrong password, so the log line Connection matched file … line N gives the first matching line; then the original file was loaded again to confirm what that line's method did (connection authenticated: … method=… (file:N), pg_hba.conf rejects connection, no pg_hba.conf entry). All 111 connections and all 182 lines compared with the pg_hba_file_rules view agreed.

samehost and samenet (they depend on the server's addresses), host-name addresses (DNS), @file, include, +group when membership is unknown, regular expressions outside the syntax this page evaluates, and unusual numeric forms such as 010.0.0.1 give no verdict — the tool says it cannot decide and why. Option values of ldap and radius lines are not checked.

FAQ

How do I see which line the server actually used?

With log_connections = on every successful connection logs the file and line, e.g. connection authenticated: user="…" method=trust (/…/pg_hba.conf:7) (PostgreSQL 17 logs this for trust too). A failed authentication adds DETAIL: Connection matched file "…" line N: "…". A reject line logs only pg_hba.conf rejects connection for host …, without a line number.

Can I check the file before reloading?

SELECT line_number, type, database, user_name, address, auth_method, error FROM pg_hba_file_rules; parses the file on disk now and shows each line. If any row has an error, a reload will not apply the file. A row with every column empty is also an error (for example clientcert=1).

Is the file I paste sent to a server?

No. Everything is matched in your browser. The file, addresses and user names are not sent to a server and are not passed to the analytics or ads this site uses. See the privacy notice.