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
CREATE DATABASE shop;
CREATE ROLE app_user LOGIN PASSWORD 'Shop2026';CREATE DATABASE
CREATE ROLE$ PGPASSWORD='Shop2026' psql -h 127.0.0.1 -U app_userSELECT current_user, current_database();psql: error: connection to server at "127.0.0.1", port 5432 failed: FATAL: database "app_user" does not existFATAL: 3D000: database "app_user" does not existSELECT datname FROM pg_database WHERE NOT datistemplate ORDER BY datname; 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.
$ PGPASSWORD='Shop2026' psql -h 127.0.0.1 -U app_user -d shopSELECT current_user, current_database(); 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
CREATE DATABASE "ShopDB";
CREATE ROLE app_user LOGIN PASSWORD 'Shop2026';CREATE DATABASE
CREATE ROLE$ PGPASSWORD='Shop2026' psql -h 127.0.0.1 -U app_user -d shopdbSELECT current_user, current_database();psql: error: connection to server at "127.0.0.1", port 5432 failed: FATAL: database "shopdb" does not existFATAL: 3D000: database "shopdb" does not existSELECT datname FROM pg_database WHERE lower(datname) = 'shopdb'; datname
---------
ShopDB
(1 row)ALTER DATABASE "ShopDB" RENAME TO shopdb;ALTER DATABASEpg_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.
$ PGPASSWORD='Shop2026' psql -h 127.0.0.1 -U app_user -d shopdbSELECT current_user, current_database(); 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
CREATE ROLE app_user LOGIN PASSWORD 'Shop2026';CREATE ROLE$ PGPASSWORD='Shop2026' psql -h 127.0.0.1 -U app_user -d shop_devSELECT current_user, current_database();psql: error: connection to server at "127.0.0.1", port 5432 failed: FATAL: database "shop_dev" does not existFATAL: 3D000: database "shop_dev" does not existCREATE DATABASE shop_dev OWNER app_user;CREATE DATABASECreate it as a superuser (or a role with CREATEDB): CREATE DATABASE shop_dev OWNER app_user;. The same connection then succeeds.
$ PGPASSWORD='Shop2026' psql -h 127.0.0.1 -U app_user -d shop_devSELECT current_user, current_database(); 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
CREATE DATABASE shop;CREATE DATABASEDROP DATABASE shop_test;ERROR: 3D000: database "shop_test" does not existSELECT datname FROM pg_database WHERE NOT datistemplate ORDER BY datname; 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.
DROP DATABASE IF EXISTS shop_test;
CREATE DATABASE shop_test;NOTICE: 00000: database "shop_test" does not exist, skipping
DROP DATABASE
CREATE DATABASEFAQ
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