Last reviewed June 2026
PostgreSQL is the most popular open-source database, and connecting Claude to your Postgres instance enables powerful data exploration and query assistance. MCP servers provide secure, controlled database access. Here are the best options for PostgreSQL integration.
Recommended MCP Servers
Postgres MCP Pro
crystaldba/postgres-mcp
All-in-one PostgreSQL server with index tuning, query optimization, health checks, and safe SQL execution.
Key Features
- Index tuning recommendations
- EXPLAIN plan analysis
- Database health monitoring
- Safe read-only mode
Installation
pip install postgres-mcpPostgres MCP Pro is the premium choice for PostgreSQL. Beyond basic queries, it offers index tuning, query plan analysis, and health monitoring. Essential for serious database work where performance matters.
Postgres MCP (Anthropic)
anthropics/mcp-server-postgres
Official Anthropic PostgreSQL server for schema inspection and query execution.
Key Features
- Schema exploration
- Query execution
- Official Anthropic support
- Simple configuration
Installation
npx @modelcontextprotocol/server-postgresThe official Postgres MCP from Anthropic provides straightforward database access. Explore schemas, run queries, and analyze data with minimal setup. Perfect for developers who need reliable database connectivity.
Supabase MCP
supabase-community/supabase-mcp
Official Supabase integration providing PostgreSQL access through the Supabase platform.
Key Features
- Supabase project integration
- OAuth authentication
- Read-only mode available
- Zero local setup
Installation
Remote server: https://mcp.supabase.com/mcpIf your PostgreSQL runs on Supabase, this is the easiest path. Just add the remote server URL, authenticate with OAuth, and you're connected. No credentials to manage, no local setup required.
Quick Comparison
| MCP | Stars | Best For | Pros | Cons |
|---|---|---|---|---|
| Postgres MCP Pro | >1.5k | Performance tuning | Index optimization | More features to learn |
| Postgres MCP | >2k | General access | Official, simple | Basic features |
| Supabase MCP | >2k | Supabase projects | Zero setup | Supabase only |
Getting Started
To connect to PostgreSQL with Claude Code:
For any PostgreSQL, use the official server:
npx @modelcontextprotocol/server-postgres postgresql://user:pass@host:5432/dbFor Supabase, just add the remote server URL to your config.
For performance work, install Postgres MCP Pro:
pip install postgres-mcp
Example prompt: "Connect to my database and show me the schema for the users table."
Related Guides
Frequently Asked Questions
What is the best MCP server to connect PostgreSQL with Claude Code?
For general PostgreSQL use, Postgres MCP Pro by Crystal DBA (github.com/crystaldba/postgres-mcp) is the recommended choice. It provides configurable read/write access, index tuning, EXPLAIN plan analysis, and health checks. Anthropic's original reference Postgres server was deprecated and archived in 2025, so avoid it. If your database runs on Supabase, use the official Supabase MCP server instead.
How do I give Claude read-only access to my Postgres database?
Run Postgres MCP Pro in restricted mode with the --access-mode=restricted flag, which limits Claude to read-only queries. For Supabase, add read_only=true to the remote server URL. For true safety, also connect using a dedicated database role that only has SELECT privileges, since application-level limits are not a substitute for database permissions.
How do I set up the PostgreSQL connection string for Claude Code?
Install Postgres MCP Pro with 'pipx install postgres-mcp' or 'uv pip install postgres-mcp', then add it to your Claude Code MCP config and pass the connection string via the DATABASE_URI environment variable, formatted as postgresql://user:password@host:5432/dbname. Avoid hardcoding credentials in shared config files; use environment variables and a least-privilege user.
Can Claude run database migrations on Postgres or only query it?
It depends on the server and its access mode. Postgres MCP Pro in unrestricted mode can run DDL, INSERT, UPDATE, and migrations, while restricted mode allows reads only. The Supabase MCP server exposes an apply_migration tool, but it is disabled in read-only mode. For production databases, run read-only and apply migrations through your own reviewed pipeline.
