Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Postgres asks for password, even though pg_hba.conf says trust

I have installed PostgreSQL 9.3 on my Mac. I am trying to do this command:


$ sudo -u postgres psql template1
Password:
Password: 
psql: FATAL:  password authentication failed for user "postgres"

As you can see, it asks for a password, which I give it. And it fails. I try the password for the postgres user, and the computer password. It always says it fails.

I read that you can change the pg_hba.conf file to not ask for a password. It is below:

> # TYPE  DATABASE        USER            ADDRESS                 METHOD
> 
> # "local" is for Unix domain socket connections only 
> local   all             all                                     trust
> # IPv4 local connections: 
> host    all             all             127.0.0.1/32            trust
> # IPv6 local connections: 
> host    all             all             ::1/128                 trust
> # Allow replication connections from localhost, by a user with the
> # replication privilege. 
> local   replication     postgres                                trust 
> host    replication     postgres        127.0.0.1/32            trust          
> host    replication     postgres        ::1/128                 trust 

From my understanding this should not ask for a password. And yet it does.

Interesting note: it logs in fine in pgAdmin3. But not in terminal.

Update #1:

Tried to restart PostgreSQL after I change the pg_hba.conf file. This is the message I get.

$ pg_ctl -D postgres -l server.log restart
pg_ctl: PID file "postgres/postmaster.pid" does not exist
Is server running?
starting server anyway
pg_ctl: could not read file "postgres/postmaster.opts"
like image 442
Aaron Avatar asked Nov 11 '22 00:11

Aaron


1 Answers

Turns out I had two versions of PostgreSQL installed on my system. 8.4 and 9.3. Whenever 8.4 was installed, all of the defaults were set to used it instead of 9.3. So even though 9.3 would never ask for permissions, or a password, 8.4 would.

Finally was able to kill the 8.4 version, which was running. And redirect traffic to 9.3. It works now!!!

I set 8.4's pg_hba.conf file to trust as well... just in case.

like image 89
Aaron Avatar answered Nov 15 '22 05:11

Aaron