What it does
PostgreSQL MCP connects Claude to any Postgres database using a standard connection string. Claude becomes a capable SQL collaborator: it can explore an unfamiliar schema, write complex analytical queries, identify performance bottlenecks using EXPLAIN, and manage data with INSERT and UPDATE statements.
It works with local Postgres instances, cloud-hosted databases (AWS RDS, GCP Cloud SQL, Azure Database, Supabase, Neon), and any Postgres-compatible system like CockroachDB or Aurora.
- Run any SQL query with results formatted as a table
- List all tables across all schemas
- Describe column definitions, types, nullability, and defaults
- List available schemas within the database
- Run
EXPLAIN ANALYZEto profile query performance - Execute multi-statement transactions
How to connect
Replace the connection string with your actual database credentials:
claude mcp add postgres -- npx -y @modelcontextprotocol/server-postgres \ "postgresql://myuser:mypassword@localhost:5432/mydb"
For cloud databases, use the full connection URL from your provider's dashboard.
Available tools
query— run a SQL query and return resultslist_tables— list tables in the current schemadescribe_table— return column definitions for a tablelist_schemas— list all schemas in the databaseexplain_query— return the query execution planexecute_transaction— run multiple statements atomically
Example usage
Ask Claude to investigate slow queries or build a monthly cohort analysis:
# User prompt
Find the 5 slowest queries in my orders table,
show me their execution plans, and suggest
which columns to index.
list_tables() describe_table("orders") explain_query("SELECT * FROM orders WHERE customer_id = $1 AND status = 'pending' ORDER BY created_at DESC LIMIT 20") → Seq Scan cost=0.00..8243.50 → Claude recommends: CREATE INDEX ON orders(customer_id, status)
Production safety: For production databases, create a read-only Postgres user and use that connection string. Grant only SELECT privileges on the relevant schemas to prevent accidental data modification.