Search code examples
postgresqldatabase-administrationpostgresql-8.4

Can a superuser log into a PostgreSQL server without a specific database assigned to them?


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?


Solution

  • 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.