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

Re­quire­ments

  • A Cloud Server running Linux (any dis­tri­bu­tion)
  • Post­gr­eSQL installed and running
VPS Hosting
VPS hosting at un­beat­able prices on Dell En­ter­prise Servers
  • 1 Gbit/s bandwidth & unlimited traffic
  • Minimum 99.99% uptime & ISO-certified data centres
  • 24/7 premium support with a personal con­sult­ant

Switch to the Post­gr­eSQL user

If you have used MySQL/MariaDB in the past, you may be ac­cus­tomed to logging into the database with the command mysql -u root -p from any account. However, Post­gr­eSQL uses a different security model.

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

This means that before using Post­gr­eSQL, 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 Post­gr­eSQL 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, Post­gr­eSQL gives the error message that "database [your username] does not exist."

Go to Main Menu