1

I am trying to log in to a PostgreSQL server. I do not know the inner workings of this server at the moment. But every time I do log in with the following commands:

psql postgres
psql -U username

I land up with this error:

no pg_hba.conf entry for host "[local]", user "username", database "postgres", SSL off

Do I have to have a database assigned to me if I'm created as a super user on the server?

1 Answer 1

3

Users are not specific to a database in PostgreSQL, but all databases in a cluster share the same users.

Still you need a database to connect to if you want to log into PostgreSQL – there cannot be a connection without a database. You also cannot switch databases while staying connected to the PostgreSQL server.

For administrative purposes PostgreSQL has the postgres database that you can use if you need a connection that is not to a specific database, e.g. if you just want to create a user or create or drop a database.

The statement you are looking for is

psql postgres username

If that fails, there is probably no entry in pg_hba.conf that allows username to log into postgres locally. Try with user postgres.

Note: Do not use PostgreSQL 8.4.

Sign up to request clarification or add additional context in comments.

2 Comments

"You also cannot switch databases while staying connected to the PostgreSQL server" - you can switch between databases, psql uses \c for this. However access control is applied for this change.
@A.Scherbaum You don't stay connected when you use \c. psql disconnects and reconnects.

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.