Question

I'm a novice in PostgreSQL. Now I'm trying to access a remote DB in PostgreSQL(9.3.3) with psql command like:

:~ tomohitoy$ psql -U root -h [my remote host's ip address]

However this returns an error message like:

psql: FATAL:  password authentication failed for user "root"

in MacOSX 10.9.2, PostgreSQL was installed by homebrew, running PostgreSQL.

in postgresql.conf(local)

listen_addresses = '*'

in pg_hba.conf(local)

host  all  all  [my remote host's ip address]  trust

Thank you in advance!

Was it helpful?

Solution

You didn't specify the password prompt on the command line, so you would need to have it specified in the PGPASSWORD environment variable for root user. You could alternately use the -W option to have psql prompt you to type in the password.

This assumes you have defined a root user in postgres and set its password.

There is also the .pgpass file: http://www.postgresql.org/docs/9.3/static/libpq-pgpass.html

Edit factoring in OP's comment:

If you don't have a user named root on your Postgres server, that would be the proximal issue. The user and password you use to connect to Postgres must exist in the Postgres instance to which you're connecting.

There should be at least one user in there you created during install (quite likely called postgres, although it could be something else).

You can also create new users (roles) in Postgres: http://www.postgresql.org/docs/9.3/static/app-createuser.html

Edit 2 factoring in OP's additional comments

In the case you outline below -- connecting to a colleague's remote Postgres server -- then your local Postgres server doesn't matter at all for this, since you're not (with that command) trying to connect to it.

You need to use a user and a password that are defined on the remote Postgres server (not a *nix account) to which you are trying to connect. Your colleagues will need to provide you with credentials you can use to connect. They should either have an user created specifically for you, or a shared user whose credentials you can use.

A special config should not be needed simply to connect to a server in the way you are stating. Simply specify the user on the cmdline and the password via one of the methods above.

The main config file that really matters for psql (that is, the client side of Postgres as opposed to the server) is .psqlrc, in which you can define an assortment of settings and customizations for psql sessions.

Note:

For some operations, a special config of sorts would be required. For example, some Postgres operations require the superuser role, and so you would need to login with a special superuser user in that case, but for basic things, as long as the user you login as has access to the database to which you're trying to connect, that should be fine.

Also:

The psql command above needs a database target at the end. It could be the default template1 database if, say, you want to create a new database and work with that, after the creation of which you can then switch the connection to that new database.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top