PSQL asks for password for a specific database

Posted on

Question :

I am hosting two different databases (manage_invite and manage_invite_v49) on the same server.

enter image description here

As you can see, when I try to connect them using the CLI, it demands the password for the second database only. But they are on the same server therefore the pg_hba.conf file is the same for both database. Do you know what could the issue be? I would like my manage_invite_v49 db to be accessible without a password, as the first one.

Here is my pg_hba.conf file:

# Database administrative login by Unix domain socket
local   all             postgres                                peer

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     trust
# IPv4 local connections:
host    all             all               md5
# IPv6 local connections:
host    all             all             ::1/128                 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
local   replication     all                                     peer
host    replication     all               md5
host    replication     all             ::1/128                 md5

Answer :

You are trying to connect according to the rule below

host    all             all               md5

which says password is required. Most probably there is a line in .pgpass which has password for manage_invite database only.
You can either remove -h localhost from command line which will use the line below;

local   all             all                                     trust

and therefore psql just wont asks for password or add a password line for manage_invite_v49 database.

Leave a Reply

Your email address will not be published. Required fields are marked *