Postgres login without password

In order to login to postgres without a password, you need to create a .pgpass file in your home directory. The contents of the file should look similar to:

localhost:5432:primarydb:root:RootPassword
localhost:5432:other_db:otheruser:Other_Password

After creating the file, make sure that the file permissions are 600 or less

chmod 600 ~/.pgpass

After the file is setup, you can login to the database just by executing the following command (or alternatively setup an alias in your bash file to that would execute the command. If you’re applying shortcuts, why not get maximum results):

psql -hlocalhost -Uotheruser other_db
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s