The PostgreSQL database management system, also known to many as Postgres, has many decades of development behind it. It originally started as a project at Berkeley University in California. Today, the open source database continues to defy solutions from commercial competitors, since the development team is constantly working on its functionality and performance. But what exactly is PostgreSQL?...
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.
- 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.
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:
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."