Skip to content
gohacks.dev
Databases

pg_hba.conf Generator

Build PostgreSQL pg_hba.conf rules for local sockets, TLS-only host connections, replication and a final reject, with warnings for trust, md5 and open ranges.

Free · No sign-up · Your inputs stay in your browser

Input

Generate pg_hba.conf rules

Output

pg_hba.conf

366 characters

PostgreSQL uses the first line whose type, database, user and address match, so order is the policy: specific rules first, a catch-all reject last. Reload with SELECT pg_reload_conf(); and check with SELECT * FROM pg_hba_file_rules; which reports lines that failed to parse.

Runs in this browser. Nothing you paste is sent to a server.

First match wins

PostgreSQL reads pg_hba.conf top to bottom and uses the first line whose type, database, user and address match the connection; later lines are never consulted. So specific rules go first and a catch-all reject goes last. The pg_hba.conf chapter describes every field and method.

Applying changes

Edits take effect on reload, not restart: SELECT pg_reload_conf(); or pg_ctl reload. Before relying on the new rules, SELECT * FROM pg_hba_file_rules; shows how the server parsed each line, including any line it rejected with an error.

Share

Frequently asked questions

What is the difference between host and hostssl?
host matches connections over TCP with or without TLS; hostssl only matches TLS connections, so a client that does not use TLS falls through to the next rule, ideally a reject.
Why is md5 discouraged?
MD5 password hashes are weak and the md5 method is deprecated. scram-sha-256 is the default since PostgreSQL 14; set password_encryption = scram-sha-256 and reset passwords to rehash them.
Is what I paste sent anywhere?
No. The tool runs entirely in your browser with JavaScript. Nothing you type or paste is sent to our server or stored.

Keep planning

Similar tools