.pgpass and pg_service.conf Generator
libpq reads connection settings from pg_service.conf and passwords from .pgpass, so psql, pg_dump and psycopg can connect without a password on the command line. Both files are strict: .pgpass needs colons and backslashes escaped and 0600 permissions, and pg_service.conf rejects spaces around = and keywords your libpq does not know. Paste connection URIs to get both files, test which .pgpass line a connection will use, and check a service file the way libpq parses it. Nothing leaves your browser.
Which .pgpass line will libpq use?
Check a pg_service.conf
Do more than .pgpass and pg_service.conf generator — meet Chat2DB
Chat2DB is an AI-powered SQL client for Windows, macOS and Linux. Write SQL in natural language, format and optimize queries automatically, and manage MySQL, PostgreSQL, Oracle and 20+ other databases in one workspace.
How to use
- Enter one connection per line as name = postgresql://user:password@host:port/dbname?params. Percent-encode special characters in the password, as in any URI.
- Copy the pg_service.conf block and the .pgpass lines into place, then run chmod 600 ~/.pgpass. Connect with psql "service=name".
- If a connection still asks for a password, paste your .pgpass and the connection details into the checker to see which line libpq picks, or paste your service file to find the line libpq rejects.
Frequently asked questions
What is the format of the .pgpass file?
One entry per line: hostname:port:database:username:password. Any of the first four fields can be * to match anything. Write a colon or backslash inside a field as \: or \\. libpq uses the first line that matches, so put specific lines before wildcard lines. On Linux and macOS the file must be mode 0600 or libpq ignores it with a warning.
Why is my .pgpass file ignored?
The common causes are permissions (psql prints: password file has group or world access; run chmod 600 ~/.pgpass), a host that does not match exactly (localhost and 127.0.0.1 are different strings, and a socket connection outside the default directory is looked up by its directory path), an unescaped colon in the password, trailing spaces, or an earlier wildcard line with a wrong password.
How do I connect with a pg_service.conf service?
Put a [name] section with key=value lines in ~/.pg_service.conf, then run psql "service=name" or set PGSERVICE=name. Any libpq-based client works, including pg_dump and psycopg. Values from the service file override PG* environment variables, and parameters you pass directly override the service file.
