All How-To Guides

3 Ways to Connect to PostgreSQL with Claude Code

How to connect to PostgreSQL with Claude Code?

3 MCP servers featured

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

>2k

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-mcp

Postgres 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.

Best for: Performance optimization and DBA tasks View on GitHub

Postgres MCP (Anthropic)

anthropics/mcp-server-postgres

>2k

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-postgres

The 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.

Best for: Basic PostgreSQL access View on GitHub

Supabase MCP

supabase-community/supabase-mcp

>2k

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/mcp

If 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.

Best for: Supabase PostgreSQL projects View on GitHub

Quick Comparison

MCPStarsBest ForProsCons
Postgres MCP Pro>1.5kPerformance tuningIndex optimizationMore features to learn
Postgres MCP>2kGeneral accessOfficial, simpleBasic features
Supabase MCP>2kSupabase projectsZero setupSupabase only

Getting Started

To connect to PostgreSQL with Claude Code:

  1. For any PostgreSQL, use the official server:

    npx @modelcontextprotocol/server-postgres postgresql://user:pass@host:5432/db
    
  2. For Supabase, just add the remote server URL to your config.

  3. 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