You have a database with 50 tables. You know there's an answer in there somewhere — something about which users churned last quarter, or which products are underperforming — but you're not sure which tables to join. With the Postgres MCP server, you describe what you want in English and Claude figures out the SQL. Then it runs it and shows you the results.
What the PostgreSQL MCP server does
The official server from modelcontextprotocol/servers exposes two main tools: query (run a SQL query and return results) and list_tables (list tables and their schemas in the database). Claude uses list_tables first to understand your schema, then writes targeted queries based on what you ask.
This schema-reading behavior is the key feature most people don't realize exists. You don't need to describe your database to Claude. It reads the schema itself, then writes queries that are actually correct for your specific tables and column names.
Step 1: Create a read-only database user
Before connecting, create a dedicated read-only Postgres user. This is important — you don't want Claude running as your database owner.
-- Run these in psql as your database superuser
CREATE USER claude_readonly WITH PASSWORD 'a-strong-password-here';
GRANT CONNECT ON DATABASE your_database TO claude_readonly;
GRANT USAGE ON SCHEMA public TO claude_readonly;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO claude_readonly;
ALTER DEFAULT PRIVILEGES IN SCHEMA public
GRANT SELECT ON TABLES TO claude_readonly;
The last line ensures future tables are also accessible without another grant. This user can read everything but can't insert, update, delete, or drop anything.
Step 2: Configure the server
{
"mcpServers": {
"postgres": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-postgres",
"postgresql://claude_readonly:password@localhost:5432/your_database"
]
}
}
}
For a remote database, replace localhost:5432 with your host and port. Restart Claude Desktop after saving.
What you can actually ask Claude
Once connected, start by asking Claude to describe your database. "What tables do you see and what are they for?" Claude reads the schema and gives you a plain-English summary of your own database — surprisingly useful even if you built it yourself.
Then try real questions:
- "How many users signed up each day in September?"
- "Which products have the highest return rate?"
- "Find all orders where the shipping cost exceeded 10% of the order total."
- "Who are the top 10 customers by revenue in the last 90 days?"
Claude writes the SQL, shows it to you before running, runs it, and summarizes the results. The "shows it to you before running" part is important — you can review the query before it executes.
Using with cloud databases
The Postgres MCP server works with any PostgreSQL-compatible cloud service:
- Supabase: Use the connection string from your project settings. Add
?sslmode=requireto the URL. - Neon: Same — connection string from the dashboard, with SSL required.
- AWS RDS: Ensure your security group allows connections from your IP. Use the endpoint from the RDS console.
- Railway/Render: Connection strings are available in the service's settings.
What's the difference between the Postgres server and the SQLite server?
The Postgres server connects to a running PostgreSQL database — either local or remote. The SQLite server works with a local .db file. For small datasets and local analysis, SQLite is simpler. For production databases, staging environments, and larger datasets, use the Postgres server.
Frequently Asked Questions
The default behavior depends on your database user's permissions. The server doesn't enforce read-only mode at the protocol level — that's why you should create a read-only Postgres role and connect as that user. With a SELECT-only role, even if Claude tries to run a DELETE query, it will fail at the database level.
Yes. Use a full connection string with host, port, user, password, and database name. Make sure the remote database allows connections from your IP and use SSL for any non-local connection: append ?sslmode=require to your connection string.
Claude is generally cautious about destructive SQL and will surface what it's about to run before executing. But the safest approach is a read-only database user — then even if Claude generates a DELETE statement, the database refuses it. Defense in depth beats relying on the AI's behavior.
Yes. Add multiple entries in your mcpServers config — one per database. Name them distinctly (e.g., postgres-prod, postgres-dev) so Claude knows which one you're referring to when you ask questions.