PostgreSQL 17.12Lab-verified · 2026-12-01

PostgreSQL 3D000: database does not exist

The connection asked for a database that does not exist on this server under that exact name.

PostgreSQL 17.12
3D000: database "app_user" does not exist

Jump to a cause

  1. 01No database given, so psql uses the user name
  2. 02The database was created with a quoted mixed-case name
  3. 03The database for this environment has not been created
  4. 04A reset script runs DROP DATABASE on a database that is not there

Lab-verifiedReproduced and fixed on PostgreSQL 17.12 · 2026-12-01 · container image postgres:17

SQLSTATE 3D000 is invalid_catalog_name. You usually see it at connect time: FATAL: database "app_user" does not exist. The password was accepted; only the database name failed.

We reproduced four causes on PostgreSQL 17: three at connect time with psql -h 127.0.0.1, and one as an ERROR from DROP DATABASE in a reset script. Compare the name in the message with the list in pg_database.

01No database given, so psql uses the user name

psql -U app_user without -d connects to a database with the same name as the user. There is a shop database, but no app_user database, so the message names a database you never asked for.

Setup
Setuprun as postgres
CREATE DATABASE shop;
CREATE ROLE app_user LOGIN PASSWORD 'Shop2026';
OUTPUT
CREATE DATABASE
CREATE ROLE
Reproducerun as app_user
$ PGPASSWORD='Shop2026' psql -h 127.0.0.1 -U app_user
SELECT current_user, current_database();
✕ ERROR
psql: error: connection to server at "127.0.0.1", port 5432 failed: FATAL:  database "app_user" does not exist
SERVER LOG (same moment)
FATAL:  3D000: database "app_user" does not exist
Checkrun as postgres
SELECT datname FROM pg_database WHERE NOT datistemplate ORDER BY datname;
OUTPUT
 datname
----------
 lab
 postgres
 shop
(3 rows)

pg_database lists lab, postgres, shop. Pass the database explicitly with -d shop (or dbname=shop in the connection string) and the login succeeds.

After the fixrun as app_user
$ PGPASSWORD='Shop2026' psql -h 127.0.0.1 -U app_user -d shop
SELECT current_user, current_database();
✓ SUCCESS
 current_user | current_database
--------------+------------------
 app_user     | shop
(1 row)

02The database was created with a quoted mixed-case name

CREATE DATABASE "ShopDB" (GUI tools often quote names) keeps the capital letters. Connecting to shopdb looks for a different name, so it fails.

Setup
Setuprun as postgres
CREATE DATABASE "ShopDB";
CREATE ROLE app_user LOGIN PASSWORD 'Shop2026';
OUTPUT
CREATE DATABASE
CREATE ROLE
Reproducerun as app_user
$ PGPASSWORD='Shop2026' psql -h 127.0.0.1 -U app_user -d shopdb
SELECT current_user, current_database();
✕ ERROR
psql: error: connection to server at "127.0.0.1", port 5432 failed: FATAL:  database "shopdb" does not exist
SERVER LOG (same moment)
FATAL:  3D000: database "shopdb" does not exist
Checkrun as postgres
SELECT datname FROM pg_database WHERE lower(datname) = 'shopdb';
OUTPUT
 datname
---------
 ShopDB
(1 row)
Fixrun as postgres
ALTER DATABASE "ShopDB" RENAME TO shopdb;
OUTPUT
ALTER DATABASE

pg_database shows ShopDB. Either connect with the exact name ShopDB, or rename it once with ALTER DATABASE "ShopDB" RENAME TO shopdb; (nobody may be connected to it). After the rename, -d shopdb works.

After the fixrun as app_user
$ PGPASSWORD='Shop2026' psql -h 127.0.0.1 -U app_user -d shopdb
SELECT current_user, current_database();
✓ SUCCESS
 current_user | current_database
--------------+------------------
 app_user     | shopdb
(1 row)

03The database for this environment has not been created

The app config points to shop_dev, but that database was never created on this server (for example a new dev server where only the role was made).

Setup
Setuprun as postgres
CREATE ROLE app_user LOGIN PASSWORD 'Shop2026';
OUTPUT
CREATE ROLE
Reproducerun as app_user
$ PGPASSWORD='Shop2026' psql -h 127.0.0.1 -U app_user -d shop_dev
SELECT current_user, current_database();
✕ ERROR
psql: error: connection to server at "127.0.0.1", port 5432 failed: FATAL:  database "shop_dev" does not exist
SERVER LOG (same moment)
FATAL:  3D000: database "shop_dev" does not exist
Fixrun as postgres
CREATE DATABASE shop_dev OWNER app_user;
OUTPUT
CREATE DATABASE

Create it as a superuser (or a role with CREATEDB): CREATE DATABASE shop_dev OWNER app_user;. The same connection then succeeds.

After the fixrun as app_user
$ PGPASSWORD='Shop2026' psql -h 127.0.0.1 -U app_user -d shop_dev
SELECT current_user, current_database();
✓ SUCCESS
 current_user | current_database
--------------+------------------
 app_user     | shop_dev
(1 row)

04A reset script runs DROP DATABASE on a database that is not there

Test or setup scripts often start with DROP DATABASE shop_test; and then recreate it. On a fresh server (or after a previous run failed halfway) the database is not there yet, so the first line fails with ERROR: 3D000: database "shop_test" does not exist. Here it is not a connection error but a normal ERROR.

Setup
Setuprun as postgres
CREATE DATABASE shop;
OUTPUT
CREATE DATABASE
Reproducerun as postgres
DROP DATABASE shop_test;
✕ ERROR
ERROR:  3D000: database "shop_test" does not exist
Checkrun as postgres
SELECT datname FROM pg_database WHERE NOT datistemplate ORDER BY datname;
OUTPUT
 datname
----------
 lab
 postgres
 shop
(3 rows)

pg_database shows only lab, postgres and shop. With DROP DATABASE IF EXISTS shop_test; the missing database is only a NOTICE ... skipping, and the following CREATE DATABASE shop_test; runs.

After the fixrun as postgres
DROP DATABASE IF EXISTS shop_test;
CREATE DATABASE shop_test;
✓ SUCCESS
NOTICE:  00000: database "shop_test" does not exist, skipping
DROP DATABASE
CREATE DATABASE

FAQ

Why does psql say database "username" does not exist?

If you do not pass -d, psql connects to a database with the same name as the user. Pass the real database name with -d, or set PGDATABASE.

How do I list databases in PostgreSQL?

Run SELECT datname FROM pg_database WHERE NOT datistemplate; or \l in psql. Compare the names exactly, including upper and lower case.

The database exists in pgAdmin but I still get 3D000. Why?

It was probably created with capital letters (quoted). PostgreSQL then matches the name exactly, so shopdb is not ShopDB. Use the exact name or rename it to lowercase.

How do I drop a PostgreSQL database only if it exists?

Use DROP DATABASE IF EXISTS name;. If it is missing you get NOTICE: database "name" does not exist, skipping instead of the 3D000 error, so the script can go on to CREATE DATABASE.

How we verify

Each scenario starts from fresh database users. A script runs the setup, confirms the exact error code, applies the fix and runs the statement again. The output shown is what the database printed, saved by the script.

lab_a and lab_b are ordinary roles created for the test, each owning a schema of the same name; postgres is the superuser. PostgreSQL 17.12