TL;DR: The server reached Postgres fine, but the database name in your connection URL does not exist on that server. Fix the `/dbname` path segment of the URL. Auth working + this error = typo in the database name, nothing more.

```text
Error: database "mydb" does not exist
```

## Fix it

1. Confirm which databases actually exist. Connect with psql using the same host and credentials but the default `postgres` database:

```bash
psql "postgresql://db-host:5432/postgres" -c "l"
```

   Expected: a list of databases. Check whether your intended name is there, exactly as spelled.

2. Fix the URL path segment. In `postgresql://db-host:5432/mydb`, the database is `mydb`. Common mistakes: pluralization (`mydb` vs `mydbs`), environment suffixes (`mydb_prod` vs `mydb`), and case (`MyDB` vs `mydb`).

3. Update the URL in your MCP client config `env` block and restart the client.

   Expected: tool calls connect and queries run. No does-not-exist error.

## When to use this

- The MCP server authenticates successfully (no password error) but every tool call fails with `database "x" does not exist`.
- You recently switched environments (dev to prod) or copied a config from another project.

## When NOT to use this

- The error is `password authentication failed`. That is credentials, not the database name.
- The error is `connection refused` or a timeout. The server is not even reachable.

## Compatibility

- All URL-based MCP Postgres servers: @modelcontextprotocol/server-postgres, yawlabs/postgres-mcp, Tabulus, pgedge-postgres-mcp.

## Why it happens

The path segment of a Postgres URL is the database name, and Postgres treats it as an exact identifier. MCP configs get copy-pasted between projects and environments, so the host and credentials get updated while the stale database name rides along. The server connects to the host fine, then Postgres itself rejects the unknown name.

## Edge cases

- Database names are case-sensitive when quoted. If it was created as `"MyDB"`, the URL must say `MyDB` exactly.
- If the database truly does not exist yet, create it: `CREATE DATABASE mydb;` from a superuser connection.
- Some managed providers put you in a default database (often `postgres`) and your tables live in a schema there. Point the URL at the real database, not the schema name.