PostgreSQL 3D000: database does not exist
The connection names a database that isn't on this server. Often a typo, a case mismatch, or a client defaulting the database name to the user name.
- SQLSTATE
3D000- Name
invalid_catalog_name- Category
- Invalid Catalog Name
What it means
Every PostgreSQL connection is to one database, named in the connection string. If no database by that name exists on the server you reached, login stops with 3D000.
Database names are case-sensitive once created with quotes, and many clients fill in a default: psql and libpq use the user name as the database name when none is given, so psql -U app tries to open a database called app.
Common causes
- A typo, or a database created with a quoted mixed-case name such as
"Shop". - No database given, so the client used the user name as the database name.
- Connecting to the wrong server or port (another instance, a different container) where the database was never created.
- The database was dropped or hasn't been created yet by setup scripts.
How to fix it
-
Connect to a database that always exists, such as
postgres, and list the databases.-- psql -h db -U app -d postgres SELECT datname FROM pg_database ORDER BY datname;
-
Create the database if it should exist.
CREATE DATABASE shop OWNER app;
-
Pass the database name explicitly in the connection string, for example
postgresql://app@db:5432/shoporpsql -d shop. -
If it was created with capitals, use the exact name. In a URL or
-doption no quotes are needed:psql -d Shop.
Questions
Why does psql say database does not exist when I only gave a user name?
When no database is specified, psql connects to a database with the same name as the user. Add -d postgres or the database you want.
Related errors
28P01password authentication failed42P01relation does not exist3F000schema does not exist42P04database already exists4060SQL Server: Cannot open database requested1049MySQL: Unknown database
The code and message text are from the PostgreSQL documentation, Appendix A: PostgreSQL Error Codes. Browse the full PostgreSQL error list or search every database error.
Work on PostgreSQL in SQLly
A native SQL client for macOS, Windows and Linux with schema-aware IntelliSense, guardrails for risky statements and clear error messages, for PostgreSQL and the other databases you use.