PostgreSQL “database does not exist”: list, create, connect with -d
List databases with psql -l, create the missing one with createdb, and pass -d explicitly.
List databases with psql -l. If yours is missing, create it with createdb mydb, then connect explicitly with psql -d mydb. Bare psql defaults the database name to your OS username.
Try these fixes in order
List existing databases
See which databases actually exist before assuming a typo. Connect to the default postgres database to run the listing.
psql -lCreate the database
Create the database from a role with CREATEDB privilege (superusers qualify). Add -O to set a different owner.
createdb mydbConnect with -d explicitly
Connect to the new database by name. The -d flag overrides psql's username default.
psql -d mydbConfirm the right server
If the database should exist but does not appear, verify you reached the right server: host, port, and cluster all matter.
psql -c "\\conninfo"Interpret what you see
You ran bare psql or psql mydb
What it suggests: Bare psql connects to a database named after your OS user. If you meant a different database, the name in the error is the default, not necessarily a typo.
Next check: Run psql -l to list real databases, then connect with -d.
First time using this database name
What it suggests: A fresh install contains postgres, template0, and template1 only. Application databases must be created explicitly.
Next check: Run createdb mydb from a role with CREATEDB privilege.
The database exists according to a teammate
What it suggests: The database may live on a different server or port than the one you reached.
Next check: Confirm host and port with \conninfo from a working connection.
Why this happens
- The database was never created; only the default postgres database and templates exist.
- psql defaulted the database name to your OS username, which does not match the database you meant.
Still not working?
Do not create databases by copying template files or data directories by hand; use createdb or CREATE DATABASE so catalogs, permissions, and encodings are set up correctly.
Official sources
These steps are based on the linked documentation and general diagnostics. BugMedic has not independently tested every product and system configuration. Review commands before running them.