HiveBrain v1.2.0
Get Started
← Back to all entries
debugsqlModerate

psql: fatal database does not exist error

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
errorfatalexistdatabasepsqldoesnot

Problem

I have a linux user account, postgresql role, and associated database, all called foo.

from the linux user foo, I ran the command

dropdb foo


Now when I try to run psql from the linux user foo, I get the error...

psql: FATAL:  database "foo" does not exist


So does this mean that when running psql from a linux user account, there must be a database associated with that linux user account?

Solution

psql assumes that you want to connect to a database, you can either provide one (just after the command) or it will assume you want to connect to a database whose name is the same as your username (or the account name of the process that started psql):

So, you could write:

psql my_db


or

psql -d my_db


or yet

psql --dbname=my_db


... and psql will connect to the (local) database named my_db.

You have more connection options that you can check in the documentation.

If you don't have yet a database created, check createdb.

Code Snippets

psql -d my_db
psql --dbname=my_db

Context

StackExchange Database Administrators Q#176002, answer score: 14

Revisions (0)

No revisions yet.