2

I am trying to connnect to Postgresql 9.1 database on remote ubuntu 12.04 server from my windows pc using putty.i have created user with password and when i run the command

psql -U opentaps -d opentaps (opentaps is the user i created for database opentaps) i get the below mesaage . psql: FATAL: password authentication failed for user "opentaps" i did try psql -U opentaps -d opentaps -h localhost but still same message after i supply the password . my password for the opentaps user is correct .also even when i try psql -U postgres -d postgres i get the same failure message .

I made some changes in pg_hba.conf and it looks like this

https://docs.google.com/document/d/13ymGYj9e7YPFiaffwixLzsWJygp_OfBmgBi4Axgrg5A/edit?usp=sharing

also in postgresql.conf i made the change by uncomenting listen_addresses = '*' i know i am missing something here .need your help to know what else i need to change to connect to the server.

thanks for your help

2
  • It doesn't look like a pg_hba.conf or listen_addresses problem. Assuming certainty that it's the correct password, I'd check its validity with select usename,valuntil from pg_user. If you can't connect at all, replace temporarily md5 with trust in pg_hba.conf to bypass the password. Commented Nov 4, 2013 at 23:38
  • yes i did change the md5 with trust in pg_hba.conf and restarted postgresql and voila this time it connected.thanks for your help. Commented Nov 5, 2013 at 9:57

3 Answers 3

8

One hack around this is to edit pg_hba.conf

sudo vi /etc/postgresql/9.3/main/pg_hba.conf

To temporarily

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

Then go and

sudo -u postgres psql template1
ALTER USER postgres with encrypted password 'your_password';

then go back and set pg_hba.conf back to

# Database administrative login by Unix domain socket
local   all             postgres                                   md5
Sign up to request clarification or add additional context in comments.

Comments

1

Be sure that you are logged in as the user opentaps when you launch psql from the command line.

you should also fill the .pgpass file with correct information, with the following format:

hostname:port:database:username:password

if no .pgpass file has been created, you should create one. cf. postgresql docs for reference

2 Comments

Since -U opentaps is explicitly passed, the logged in username is not relevant. And if the password entered by hand is rejected, it will be equally rejected from a .pgpass file.
Daniel you are correct .i did create this file .pgpass as per the docs but it didnt help i still got the same failure message.
1

A little late response but here it goes:

First, your .pgpass file should be in your Ubuntu user's home directory. If there isn't a file you can create it with nano ~/.pgpass

Second, your file should contain this format hostname:port:database:username:password. Don't forget to chmod 0600 ~/.pgpass so you can disallow any access to world or group, as it says here.

Now, the command should be something like this: psql -h localhost -w -U opentaps -d opentaps -c "select * from mytable". Where:

-h is your host.

-w is to use your .pgpass file, in case you don't want to type your password. Ohterwise use -W to force psql to prompt a password.

-U is your postgres username.

-d is your database name.

and -c is to execute a string sql command.

1 Comment

just says password authentication failed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.