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

Re­quire­ments

  • A Cloud Server running Linux (any dis­tri­b­u­tion)
  • Post­greSQL installed and running
VPS Hosting (Virtual Private Servers)
World-class VPS at America’s lowest price
  • Save 50% or more vs leading hosts
  • Unlimited traffic & no setup fees 
  • 99.99% uptime guar­an­teed
  • Free 24/7 premium support 

Switch to the Post­greSQL 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­greSQL uses a different security model.

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

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

Go to Main Menu