Logging in to postgresql without password

From Foochal

Jump to: navigation, search


Often times you might want to login to postgresql without typing your password. Some scenarios when this is useful:

  • Don't want to remember password
  • Remember but don't want to type the password
  • Take automatic backups using pg_dump using cron

The solution is to create a password file:

  • Create a password file
vi ~/.pgpass
  • Type the following on the first line, of course replace the dbhost, dbuser and dbpassword with your actual values
dbhost:*:dbuser:dbuser:dbpassword
  • Quit the file, and set the correct permission
chmod 600 ~/.pgpass
  • Done. Try the following:
psql -h dbhost -U dbuser 

and you should be able to login without typing your password.


Personal tools