mcpservers
PostgreSQL MCP logo

PostgreSQL MCP

Official PostgreSQL MCP server — query and inspect Postgres databases with read-only access for safe AI-powered data analysis.

Turn it on
“My current setup uses the LLM to search through my local Postgres in multiple steps”
Hacker News · cahaya

★ Hand-picked walkthrough

Set Up PostgreSQL MCP Server with Claude Desktop

Charming Data

  1. 1

    Turn on PostgreSQL in your AI

    In Claude: open Settings → Connectors and add PostgreSQL. In ChatGPT: Settings → Apps & Connectors.

  2. 2

    Add it to your app once

    Copy the short config below into your app. It just tells your AI where to find PostgreSQL.

  3. 3

    Just ask

    Tell it what you want in plain words — no special commands.

    For example, say

    “List all tables in my database and show row counts for each”

Need the exact config? Show it +
{
  "mcpServers": {
    "postgres": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-postgres", "postgresql://user:pass@host:5432/dbname"]
    }
  }
}

Paste into your client's MCP configuration file.

Copy one, paste it to your AI, watch it work.

Schema Exploration

“Describe the schema of my database — list tables, key columns, and how they relate to each other”

Data Investigation

“How many orders were placed in the last 24 hours and what's the total revenue?”

Query Drafting

“Write a query to find users who signed up in the last 30 days but haven't made a purchase”

“I have been using the old MCP for months, and when I look at the Sonnet 3.5 generated migrations, there are always misunderstandings that I must correct”
Used the Postgres MCP for months; flags that AI-generated migrations need manual correction.
Hacker News consumer451 · 2025-07-26
  • · Use a read-only database user for AI queries — giving write access to production is risky
  • · Connection strings contain credentials — never paste them into shared logs or chats
  • · Large SELECT queries without LIMIT can return millions of rows and blow your context window
  • You want to explore an unfamiliar database schema
  • You need to run ad-hoc SELECT queries to investigate data or bugs
  • You're learning SQL and want AI to draft queries you can review
  • You're doing analytics on a read replica and want conversational queries
  • × You use MySQL, SQLite, or MongoDB (use those specific servers)
  • × You want to give AI unrestricted write access to production
  • × You need streaming replication or CDC — that's outside this server's scope

Imagine asking your AI: 'What tables are in my database and how are they related?' or 'Show me the top 10 slowest queries from the last hour' — and it connects directly to your Postgres database. This server lets your AI query and inspect Postgres databases through conversation, without you writing SQL by hand.

The official PostgreSQL MCP server provides read-only access to PostgreSQL databases. AI assistants can explore schemas, run SELECT queries, inspect table structures, and analyze data — with safety constraints that prevent accidental data modification.

Used by developers to let Claude help with database exploration, query optimization, and data analysis without risk.

Claude Cursor Cline
#official#anthropic#postgres#postgresql#database#sql
What does PostgreSQL MCP do? +

Imagine asking your AI: 'What tables are in my database and how are they related?' or 'Show me the top 10 slowest queries from the last hour' — and it connects directly to your Postgres database. This server lets your AI query and inspect Postgres databases through conversation, without you writing SQL by hand.

Do I need to know how to code? +

No. Turn it on in your AI's settings and ask in plain English — no terminal, no coding.

When should I use PostgreSQL MCP? +

Reach for it when you need to: You want to explore an unfamiliar database schema; You need to run ad-hoc SELECT queries to investigate data or bugs; You're learning SQL and want AI to draft queries you can review; You're doing analytics on a read replica and want conversational queries.

When should I avoid PostgreSQL MCP? +

Skip it when: You use MySQL, SQLite, or MongoDB (use those specific servers); You want to give AI unrestricted write access to production; You need streaming replication or CDC — that's outside this server's scope.

How do I install PostgreSQL MCP? +

In Claude Code, run: claude mcp add postgres -- npx -y @modelcontextprotocol/server-postgres postgresql://user:pass@host:5432/dbname. Copy-paste configs for Claude Desktop, Cursor, and Windsurf are at the top of this page.