On my configuration (Ubuntu 10.04.3
and PostgreSQL 8.4
), I could finally get it to work when the username I am logged in is the same as the one I'm trying to get a password from the .pgpass
file for.
Logged in as deployer
, I was trying to use the .pgpass
file to access the database owned by an user name appname
, which has no Unix user equivalent. I could not make the .pgpass
work, until I started using deployer
as the user to access my database...
Here is my /home/deployer/.pgpass
file content:
*:*:*:deployer:password
Here a part of the /etc/postgresql/8.4/main/pg_hba.conf
one:
# TYPE DATABASE USER CIDR-ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all md5
# IPv4 local connections:
host all all 127.0.0.1/32 md5
host all all 192.168.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
As you can see, all my connections requires password (md5
).
With this configuration, assuming I have a database I created with this command:
deployer@ubuntu-server:~$ createdb -T template0 -O deployer -E UTF8 dbname
I'm able to perform the following operation without entering a password:
deployer@ubuntu-server:~$ dropdb dbname
As soon as I change the name of my .pgpass
to .pgpass-no
, it will require a password.
BTW, do not forget that your .pgpass
file must be under 0600
permissions:
deployer@ubuntu-server:~$ ls -la .pgpass
-rw------- 1 deployer staff 24 2012-01-06 17:29 .pgpass