Bobcares

PostgreSQL FATAL database root does not exist

PDF Header PDF Footer

Learn how to fix the PostgreSQL error “FATAL: database ‘root’ does not exist” caused by default login behavior. Our PostgreSQL Support team is ready to assist you.


PostgreSQL FATAL Database Root Does Not Exist

Getting the PostgreSQL FATAL database root does not exist error is common when the system defaults to using your OS username. This typically happens when no specific database is mentioned during connection. Read this article to learn how to resolve the issue and ensure smooth PostgreSQL access.

psql: FATAL: database “root” does not exist or psql: FATAL: database “” does not exist error occurs when the psql command line client is invoked without arguments. By default, psql tries to connect to a database with the same name as the user system username.

Decoding the ‘FATAL: database root does not exist’ Message

The psql error occurs commonly due to two scenarios, check out the below section:

  • Incorrect database name:

Occurs on the scenario where the user script or application connects to a database named ‘root’, but the PostgreSQL server uses a different database name.

  • Default connection behavior

In scenarios, when you run psql without specifying a database, PostgreSQL tries to access a database matching your OS username. This error commonly appears when you are logged in as ‘root’ and no ‘root’ database exists.

Read this article to learn how to resolve PostgreSQL’s “Relation Does Not Exist” error effectively.

"PostgreSQL

How to choose the right database

Here are the tips to choose the right database to avoid connection error.

  1. Connecting with the built in postgres database is the most prudent course of action.
  2. Don’t stick to system usernames as database names unless you have mistakenly or unintentionally created a database with the same name as the OS user.
  3. If you are running a script or app, ensure the database is trying to connect with an existing database.
  4. Ensure which database you are using, in cases when you are working in a team or on a managed server.

How to fix PostgreSQL FATAL: database root does not exist

Here are the several ways to fix PostgreSQL FATAL: database root does not exist. The scenario decides which way of resolution you should implement.

  1. Connect to an existing database

If you have an existing database, then connect to it directly by using the -d flag:


psql -d your_database_name

Replace your_database_name with the actual name of your database.

  1. Connect as the postgres user

Use default superuser postgres to connect automatically to the postgres by default.

sudo su - postgres
psql
  1. Use the default postgres database

If you haven’t selected the right and safest database, connect to the default postgres database.

psql -d postgres
  1. Create a root role

“FATAL: role ‘root’ does not exist”, this typically means PostgreSQL role root is missing. Create it like thos:

From the terminal:

sudo su - postgres
createuser root -s

The -s flag grants superuser privileges.

Or from the psql prompt:

CREATE ROLE root WITH SUPERUSER;

  1. Create a database named root

If your application expects a database called root, create it while logged in as a superuser:

From the terminal:

sudo su - postgres
createdb root

Or inside the psql prompt:

CREATE DATABASE root;

Or inside the psql prompt: CREATE DATABASE root;

 

Read our expert article to understand how to set a default value for character varying in PostgreSQL, with a clear example.

[Need assistance with a different issue? Our team is available 24/7.]

Conclusion

To sum up, the PostgreSQL FATAL: database root does not exist error happens when PostgreSQL tries to access a database with the same name as the user OS Username by default. The error can be fixed by specifying the correct database name or else incorporating the fault postgres user and database.

In brief, our Support Experts demonstrated how to fix the “554 5.7.1 : Relay access denied” error.

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Get featured on the Bobcares blog and share your expertise with a global tech audience.

WRITE FOR US
server management

Spend time on your business, not on your servers.

TALK TO US

Or click here to learn more.

Speed issues driving customers away?
We’ve got your back!