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
- Unlimited traffic
- Fast SSD NVMe storage
- Free Plesk Web Host Edition
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."