3D000
PostgreSQLFATALCommonInvalid Catalog NameHIGH confidence

database does not exist

What this means

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.

Why it happens
  1. 1Misspelled database name in the connection string
  2. 2The database has not been created yet
  3. 3The database was dropped while the application still had it in its connection string
  4. 4Database name is case-sensitive due to quotes used at creation time
How to reproduce

A connection string references a database that does not exist.

trigger — this will error
trigger — this will error
-- 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 the database
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.

Verify the correct database 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.

What not to do

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.

Sources
Official documentation ↗

src/backend/postmaster/postmaster.c — InitPostgres()

CREATE DATABASE

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All PostgreSQL errors