Solve the PostgreSQL Error "psql: FATAL: database "root" does not exist"

Learn how to solve the common PostgreSQL error psql: FATAL: database "root" does not exist." New PostgreSQL users often encounter this error when first logging in to PostgreSQL.

    Requirements

    • A Cloud Server running Linux (any distribution)
    • PostgreSQL installed and running

    vServer (VPS) from IONOS

    Low-cost, powerful VPS hosting for running your custom applications, with a personal assistant and 24/7 support.

    100 % SSD storage
    Ready in 55 sec.
    SSL certificate

    Switch to the PostgreSQL User

    If you have used MySQL/MariaDB in the past, you may be accustomed to logging into the database with the command mysql -u root -p from any account. However, PostgreSQL uses a different security model.

    PostgreSQL has its own user on the system which is created when PostgreSQL is installed. The postgres user is able to log into PostgreSQL without using a password. No other user is able to log into PostgreSQL.

    This means that before using PostgreSQL, you will need to switch to that user account with the command:

    su - postgres

    You will then be able to log into the PosgreSQL client with the command:

    psql

    You will not be able to access the database from the command line as any other user.

    What the Error Means

    When you log into PostgreSQL as any user other than the postgres user, it will attempt to log you into a database of the same name as your user account. This means that if you try to use the psql command as root, it will try to log you into the database root. If you try to log in while signed on as jdoe it will look for the database jdoe, and so forth.

    Unable to find this database, PostgreSQL gives the error message that "database [your username] does not exist."


    Wait! We’ve got something for you!
    Have a look at our great prices for different domain extensions.


    Enter the web address of your choice in the search bar to check its availability.
    .org
    $1/1st year
    then $20/year
    .com
    $1/1st year
    then $15/year
    .info
    $1/1st year
    then $20/year
    .me
    $1/1st year
    then $20/year