How to fix Invalid catalog name in PostgreSQL
PostgreSQL error 3D000 means you specified a database name that doesn't exist or is misspelled. Fix it by verifying the database name exists and checking your connection string.
Quick fix
Fixes 3D000
psql -U postgres- Verify the database exists
- Check your connection string
- Create the database if it doesn't exist
- Fix maintenance_database in multi-tenant setups
psql -U postgresInvalid catalog name
What this error means
In PostgreSQL, a "catalog" refers to a database. Error 3D000 "Invalid catalog name" occurs when your application attempts to connect to or use a database that doesn't exist in the PostgreSQL server. This is a connection-level error that prevents any queries from executing. The error can be triggered by: - Specifying a non-existent database name in your connection string - Mistyping the database name - Attempting to connect after a database has been dropped - Using a different database name than what was created during setup
Typical symptoms
- Connection fails immediately when trying to connect to PostgreSQL
- Application crashes with "SQLSTATE[3D000]" or error code 3D000
- ORM migrations fail during database setup with "Invalid catalog name"
- Application works with one database name but fails when configuration changes
Common causes
- Database name in connection string doesn't exist in PostgreSQL
- Database name is misspelled in the connection string or configuration
- Database was dropped or deleted but connection string wasn't updated
- Using wrong maintenance database (common in multi-tenant setups)
- Database hasn't been created yet during initial setup
How to fix "Invalid catalog name"
Connect to PostgreSQL as a superuser and list all databases:
psql -U postgresThen in the PostgreSQL prompt:
\lThis shows all databases. Look for the database name you're trying to connect to. If it doesn't appear in the list, you need to create it.
Verify the database name in your connection string matches exactly (case-sensitive). Common connection string formats:
postgresql://user:password@localhost:5432/dbnameEnsure:
- The database name is spelled correctly
- No extra spaces or special characters
- The database exists (from step 1)
Check in:
- Environment variables (.env, .env.local)
- Configuration files (config.js, database.yml, etc.)
- Application code with hardcoded connections
If the database is missing, create it:
CREATE DATABASE mydbname;For specific character encoding:
CREATE DATABASE mydbname
ENCODING 'UTF8'
LC_COLLATE 'C'
LC_CTYPE 'C'
TEMPLATE template0;Then reconnect with the correct connection string.
Some tools (Ecto, Rails, etc.) use a "maintenance database" to create/drop other databases. By default it's "postgres", but some cloud providers use different names:
# Ecto example
config :myapp, MyApp.Repo, maintenance_database: "defaultdb"# Rails example
adapter: postgresql
database: <%= ENV["DB_NAME"] %>
maintenance_db: defaultdbCheck your database hosting provider's documentation for the correct maintenance database name.
Advanced notes
PostgreSQL error codes follow the SQL standard. 3D000 specifically means "INVALID CATALOG NAME" in the Class 3D category. When catching this error in application code, check for SQLSTATE 3D000. In PL/pgSQL, you can catch it with: WHEN SQLSTATE '3D000' THEN ... Some hosted PostgreSQL providers (DigitalOcean, AWS RDS) create a default database with a different name than "postgres" - always check your provider's documentation. For connection pooling tools like PgBouncer, ensure the database exists in the PostgreSQL server, not just in PgBouncer's configuration.
Frequently asked questions
- What does "3D000" mean?
- In PostgreSQL, a "catalog" refers to a database. Error 3D000 "Invalid catalog name" occurs when your application attempts to connect to or use a database that doesn't exist in the PostgreSQL server. This is a connection-level error that prevents any queries from executing.
- How do I fix "3D000"?
- PostgreSQL error 3D000 means you specified a database name that doesn't exist or is misspelled. Fix it by verifying the database name exists and checking your connection string.
- What causes "3D000"?
- Database name in connection string doesn't exist in PostgreSQL Database name is misspelled in the connection string or configuration Database was dropped or deleted but connection string wasn't updated
- Is the "3D000" error serious?
- Yes. This is a high-severity error that usually blocks work until it is fixed, but the steps above resolve it.
Official resources & further reading
- ๐PostgreSQL Official Documentation
- ๐PostgreSQL Error Codes(Official Docs)