Jeff Wu
Jeff Wu

Reputation: 2578

What do I need to specify to get .pgpass to work?

Can someone point me to a piece of documentation that specifies the matching rules psql applies to the .pgpass file? I always spend a few extra keystrokes trying to find the right combination of host, port, database, username to get it to connect.

Some things are obvious (i.e. if my linux username is not the same as my postgres username than I need to specify it) but based on what I've seen there is some non-obvious behavior.

Upvotes: 0

Views: 2757

Answers (1)

Bohuslav Burghardt
Bohuslav Burghardt

Reputation: 34766

Here is the documentation you are probably looking for. It explains the rules pretty well.

Just so this isn't a link-only answer, here are the rules:

  • Each .pgpass entry is on its own line and has the following format:
    • hostname:port:database:username:password
  • You can use a wildcard (*) for each field except password
  • If you use wildcards, put more specific entries first

You can use for instance localhost:*:*:foo:password to specify password for user foo on your local machine regardless of the database you are connecting to or the port the Postgres is actually running on.

Upvotes: 5

Related Questions