Skip to content

Instantly share code, notes, and snippets.

@sabman
Created May 18, 2011 10:49
Show Gist options
  • Save sabman/978352 to your computer and use it in GitHub Desktop.
Save sabman/978352 to your computer and use it in GitHub Desktop.
postgresql tips psql ~/.pgpass

From: http://blog.ralreegorganon.com/2008/08/23/psql-and-passwords-on-the-command-line/

psql and passwords on the command line

psql doesn’t let you pass it a password at the command line (and with good reason–otherwise everyone would be able to see it with ps) but it can be somewhat frustrating if you’re trying to use psql in a script, as it will prompt for the password. One way to deal with this is to create a .pgpass file in your home directory. The lines in the file should be in the following format:

hostname:port:database:username:password

All values but the password can have * to match anything. Additionally, the file needs to have its permissions restricted, otherwise it will be ignored.

chmod 0600 ~/.pgpass

With that in place, you should be able to run psql from the command line without being prompted for a password.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment