database does not exist
A client attempted to connect to (or a statement referenced) a database that does not exist in the Postgres cluster. The lookup is performed against pg_database during the connection startup phase.
- 1Misspelled database name in the connection string
- 2The database has not been created yet
- 3The database was dropped while the application still had it in its connection string
- 4Database name is case-sensitive due to quotes used at creation time
A connection string references a database that does not exist.
-- From psql: -- psql -d nonexistent_database -- Results in: FATAL: database "nonexistent_database" does not exist -- List existing databases from within a connected session: SELECT datname FROM pg_database ORDER BY datname;
expected output
FATAL: database "nonexistent_database" does not exist
Fix 1
Create the database
WHEN When the database should exist but was never created.
CREATE DATABASE myapp; -- With owner and encoding: CREATE DATABASE myapp OWNER = appuser ENCODING = 'UTF8' LC_COLLATE = 'en_US.UTF-8' LC_CTYPE = 'en_US.UTF-8';
Why this works
CREATE DATABASE calls the createdb() internal function which creates a new entry in pg_database and copies the template database (template1 by default) to a new data directory under PGDATA/base/<oid>/. After creation the database is immediately available for connections.
Fix 2
Verify the correct database name
WHEN When the database may exist under a slightly different name.
-- Connect to postgres (the maintenance database) and list all databases: SELECT datname FROM pg_database ORDER BY datname;
Why this works
pg_database is a cluster-wide catalog visible from any database in the cluster. Connecting to the postgres database (which always exists) and querying pg_database reveals all available database names with their exact casing.
✕ Use the postgres maintenance database as an application database
The postgres database is reserved for administrative connections; application data should be in a dedicated database.
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev