Skip to content

MCP server

PostgreSQL MCP server

Lets AI assistants explore a PostgreSQL database, run SQL in a restricted read-only mode and check query performance and database health.

At a glance

Maintained by
Crystal DBA
Tools exposed
9 listed below
Reviewed
September 24, 2026

Why it matters

What it does and why it matters

PostgreSQL holds the core data of many business apps: customers, orders, bookings and invoices. A PostgreSQL MCP server lets an AI assistant look at the schema, write SQL and explain the results in plain English. A manager can ask "how many bookings did we take last month, by channel" and get an answer without waiting for a report.

The original reference server from the MCP project was archived in May 2025. The best-maintained option we found is Postgres MCP Pro by Crystal DBA, a community server. Besides querying, it can explain query plans, find slow queries and suggest indexes, which also makes it useful for developers and database administrators.

Its restricted access mode runs read-only transactions with time limits, which is the setting we recommend for business users. Unrestricted mode allows writes and should be kept for development databases. We connect it to a read replica with a dedicated user, so even a badly written query cannot slow down or change production.

Use cases

Best business use cases

Plain-English reporting

Managers ask questions and get answers from live data. See automated reporting.

Data exploration

Analysts explore an unfamiliar schema quickly by asking what each table holds.

Performance checks

Developers find slow queries and get index suggestions.

Database health

Checks on bloat, connections and other health signals in one request.

Agent lookups

Agents look up a customer or order while handling a support request.

Tools

Available tools

Tool names as published by the maintainer at review time. Versions change, so check the repository for the current list.

Read and write: Read and write in unrestricted mode; restricted mode runs read-only transactions with time limits.

  • list_schemas

    Lists the schemas in the database.

  • list_objects

    Lists tables, views, sequences and extensions in a schema.

  • get_object_details

    Shows columns, constraints and indexes for an object.

  • execute_sql

    Runs SQL, limited by the chosen access mode.

  • explain_query

    Shows the execution plan, including with hypothetical indexes.

  • get_top_queries

    Reports the slowest queries using pg_stat_statements.

  • analyze_workload_indexes

    Recommends indexes for the heaviest queries.

  • analyze_query_indexes

    Recommends indexes for specific queries.

  • analyze_db_health

    Checks buffer cache, connections, constraints, indexes, sequences and vacuum health.

Workflows

Example workflows

Monthly sales questions

  1. 1

    Connect the server to a read replica in restricted mode.

  2. 2

    Ask for last month's revenue by product line.

  3. 3

    The assistant inspects the schema and writes the SQL.

  4. 4

    It runs the query and summarizes the result.

  5. 5

    You ask a follow-up, such as the same numbers for last year.

Slow page investigation

  1. 1

    A developer reports a slow page.

  2. 2

    The assistant lists the top slow queries.

  3. 3

    It explains the plan for the worst one.

  4. 4

    It suggests an index and shows the expected plan.

  5. 5

    The developer reviews and applies the change in a migration.

Prompts

Example prompts

  • “Show me the ten customers with the highest order value this quarter, with their order count.”

  • “Which tables hold booking data, and how are they related?”

  • “List the slowest queries this week and suggest indexes for the top three.”

Setup

Installation and configuration

Examples for Claude Desktop and Claude Code. Replace the placeholder values with your own keys, and store secrets outside version control.

Claude Desktop: claude_desktop_config.json

{
    "mcpServers": {
        "postgres": {
            "command": "uvx",
            "args": [
                "postgres-mcp",
                "--access-mode=unrestricted"
            ],
            "env": {
                "DATABASE_URI": "postgresql://username:password@localhost:5432/dbname"
            }
        }
    }
}

Claude Code: terminal

claude mcp add postgres -e DATABASE_URI="postgresql://username:password@localhost:5432/dbname" -- uvx postgres-mcp --access-mode=restricted
  • Local server: stdio. PyPI: postgres-mcp (uvx postgres-mcp or pipx install postgres-mcp). Docker: crystaldba/postgres-mcp.
  • Needs: DATABASE_URI (Postgres connection string, required); OPENAI_API_KEY (optional, only for experimental LLM-based index tuning).

Security

Security considerations

  • Least privilege

    Create a dedicated database user that can read only the tables the assistant needs.

  • Use a replica

    Point the server at a read replica or copy, not the primary production database.

  • Log every query

    Keep a log of the queries the assistant runs, and review it in the first weeks.

  • Watch for sensitive data

    Mask or exclude columns with personal or payment data from the user the assistant uses.

Related servers

Servers that pair well with it

Supabase

Supabase's official hosted MCP server lets AI work with your Supabase projects: tables, SQL, migrations, edge functions, branches and docs.

MySQL

A community MCP server that lets AI run SQL against MySQL, read-only by default, with insert, update and delete each switched on separately.

BigQuery

Google's remote BigQuery MCP server lets AI list datasets and tables and run SQL, with a read-only query tool and IAM controls.

Keep exploring

FAQ

Questions people ask us

Have a question that is not here? Ask us directly.

Start a project

Want this connected to your own systems? We build AI workflows with MCP.

Send a short brief. We reply with questions, a suggested plan and an estimate you can compare with other offers.

Your privacy choices

We use necessary storage to run this site. With your permission we also use Google Analytics to see which pages help people, and load maps from Google. You can change this at any time. Read the cookie policy.