PostgreSQL MCP Server logo

PostgreSQL MCP Server

Query PostgreSQL, inspect schemas, analyze performance, monitor health, and manage access through MCP.

Install PostgreSQL MCP Server

Pick your client, then add it in one click or paste the config.

STDIONode.js
~/Library/Application Support/Claude/claude_desktop_config.json
claude_desktop_config.json
{
  "mcpServers": {
    "postgresql-mcp-server-4": {
      "command": "npx",
      "args": [
        "-y",
        "@yawlabs/postgres-mcp@latest"
      ],
      "env": {
        "DATABASE_URL": "YOUR_VALUE_HERE",
        "ALLOW_WRITES": "YOUR_VALUE_HERE",
        "POSTGRES_MAX_ROWS": "YOUR_VALUE_HERE"
      }
    }
  }
}

Settings → Developer → Edit Config, merge this into mcpServers, then fully quit and reopen Claude Desktop.

Values are written into the snippet above so you can paste it as is. They never leave your browser.

Install not yet sandbox-tested— the server itself is confirmed live (we called its tools/list endpoint). The stdio install command is a separate, ongoing check.

Overview

PostgreSQL MCP Server connects MCP clients to a configured PostgreSQL database for SQL queries, schema inspection, query plans, health checks, and operational diagnostics. It provides separate read-only and general query tools, with writes disabled by default and optionally enabled through `ALLOW_WRITES=1`. Performance tools cover statistics, locks, bloat, replication, I/O, sequential scans, unused indexes, and hypothetical index recommendations. Reach for it when an AI assistant needs structured PostgreSQL discovery or troubleshooting rather than only basic SQL execution.

Use cases

  • Inspect an unfamiliar PostgreSQL schema
  • Analyze slow queries and missing indexes
  • Check connection pressure and lock contention
  • Audit database roles and table privileges
  • Review replication, bloat, and maintenance risks

Key features

  • Read-only SQL execution by default
  • Schema and relationship introspection
  • EXPLAIN plans with optional analysis
  • HypoPG-based index recommendations
  • Health, lock, replication, and I/O diagnostics
  • Role and table privilege inspection

Tools23

What PostgreSQL MCP Server lets your agent do. Expand a tool for its parameters.

Verified live~10.6k tokens of context

Security & health

What it can reach and how reliably it runs — from our own checks, not the maintainer’s claims.

ActiveLast checked 1d ago

Recent health check succeeded.

9/9 checks healthy over the last 44d

What it can do

From the 23 tools this server returned when we ran it; 23 declare their own safety hints.

Can delete or modify data · 3Handles credentials · 1Makes network requests · 23Read-only tools · 20
Network at startup3 connections
Files written at startupNone
Install scriptsNone
npm provenanceNot published
Package age183 days
Maintainers1

Observed 2026-10-22 in an isolated sandbox. A description of reach, not a security audit.

Supply-chain signal

No high-severity advisories surfaced by our automated scan.

Critical 0High 0Medium 0Low 0

Scanned 14d ago via OSV.dev · @yawlabs/postgres-mcp@latest (npm)

Adoption & maintenance

Factual signals from GitHub, npm, and our automated checks — not a rating.

GitHub stars10Stargazers on the source repository.
npm downloads6kPackage downloads in the last 30 days.
Last commit12d agoMost recent push to the default branch.
Tools exposed23Callable tools this server registers over MCP.
Directory activity5 viewsConfig copies, upvotes, and views on AllMCPs.

How PostgreSQL MCP Server works

What PostgreSQL MCP Server does

PostgreSQL MCP Server exposes PostgreSQL operations as MCP tools for AI assistants. It connects to the database identified by DATABASE_URL and supports SQL execution, schema discovery, query planning, health inspection, access review, and performance analysis.

The server includes both low-level SQL tools and focused database helpers. Agents can list schemas, tables, views, functions, extensions, roles, and privileges; describe tables and relationships; search for columns; inspect locks and replication; and review database statistics. Results from large SQL queries are limited by POSTGRES_MAX_ROWS, which defaults to 1,000 and includes a truncation indicator.

How it works

The server runs as a standard MCP process, commonly launched with npx, and communicates with an MCP client over its configured process connection. User SQL is sent through PostgreSQL's extended query protocol and can use positional parameters, helping avoid string-interpolated queries and stacked statements.

pg_readonly always wraps execution in a read-only transaction and rolls it back. pg_query is also read-only by default, but ALLOW_WRITES=1 removes its in-server read-only wrapper; PostgreSQL permissions still determine what the configured role can actually do. A least-privileged database role remains the primary access boundary. The separate pg_kill tool requires writes to be enabled because it changes backend session state.

pg_explain returns text or JSON plans and can optionally run EXPLAIN ANALYZE. Analyzed statements are rolled back, although effects outside transactional table data, such as sequence advancement or certain function side effects, may remain. The index advisor uses HypoPG to cost hypothetical indexes without creating them on disk and returns only candidates that reduce estimated planner cost.

Setup and configuration

Add the server to an MCP client configuration with npx -y @yawlabs/postgres-mcp@latest and provide a PostgreSQL connection string:

config.json
{
  "mcpServers": {
    "postgres": {
      "command": "npx",
      "args": ["-y", "@yawlabs/postgres-mcp@latest"],
      "env": {
        "DATABASE_URL": "postgres://user:password@host:5432/dbname"
      }
    }
  }
}

On Windows, launch npx through cmd /c. Restart the MCP client and approve the server when prompted. Set ALLOW_WRITES to 1 only when write operations are needed; leaving it unset keeps the normal query path read-only. POSTGRES_MAX_ROWS controls the maximum number of rows returned from large query results.

Node.js 22 or newer is required. The package is distributed as a single bundled file with no runtime dependency installation beyond the package launch.

Tools and capabilities

  • Execute parameterized SQL with pg_readonly or pg_query.
  • List and describe schemas, tables, views, functions, extensions, and columns.
  • Generate EXPLAIN plans, including optional analysis, buffers, settings, memory, WAL, serialization, and hypothetical-index options where supported by the PostgreSQL version.
  • Recommend indexes with HypoPG and inspect top queries, sequential scans, unused indexes, table bloat, and I/O activity.
  • Check connection pressure, active queries, wait events, database statistics, locks, replication, and advisory findings.
  • Review roles and table privileges, cancel or terminate backends, and inspect tables without primary keys or row-level security.

Several diagnostics depend on PostgreSQL features or extensions. pg_top_queries requires pg_stat_statements; index recommendations require HypoPG; approximate and exact bloat methods require pgstattuple; and I/O reporting requires PostgreSQL 16 or newer. Permission-limited diagnostic subqueries can return warnings while leaving the rest of a snapshot available.

Limitations and notes

Read-only transactions do not block every possible external side effect. Functions or commands such as backend signaling, file access, large-object export, or COPY ... TO PROGRAM still depend on the privileges of the configured PostgreSQL role. Use a least-privileged role, especially when a client automatically approves read-only tools.

Diagnostic counters are generally cumulative since their associated statistics reset and should be interpreted with their reset timestamps. Connection activity is scoped to the current database in health reports, while lock inspection is cluster-wide. Exact bloat inspection scans tables and can be slow; provide a schema and avoid using it indiscriminately on large databases. Index-advisor results are planner estimates, not measured execution times, and a bounded search can report that its budget was exhausted.

Reviews

No reviews yet — be the first to share how it worked for you.

Frequently Asked Questions about PostgreSQL MCP Server

PostgreSQL MCP Server is an MCP server that connects AI assistants to PostgreSQL through a configured DATABASE_URL. Its main tools run SQL, inspect schemas and relations, generate EXPLAIN plans, diagnose health and performance, review roles and privileges, and optionally manage backend sessions.

Install it by adding `npx -y @yawlabs/postgres-mcp@latest` to your MCP client configuration and setting `DATABASE_URL` to a PostgreSQL connection string. On Windows, invoke it through `cmd /c`; then restart the client and approve the server.

Yes, PostgreSQL MCP Server works with Cursor. Configure it as an MCP process using the package launch command and provide `DATABASE_URL`; the server then exposes its PostgreSQL tools through Cursor.

Enable writes by setting `ALLOW_WRITES=1` in the server environment. This lifts the in-server read-only wrapper for `pg_query`, but PostgreSQL still enforces the privileges of the role in `DATABASE_URL`; `pg_readonly` remains read-only.

Related MCP servers

Add a badge to your READMEShow it’s listed — live SVG, Markdown or HTML.

AllMCPs Directory Badge

Full Badge Customizer

Showcase your server listing on GitHub or your project documentation. Embed this dynamic SVG badge to highlight official listing status and live engagement.

Badge Style:
Live Dynamic SVG PreviewPostgreSQL MCP Server AllMCPs Directory Badge
Markdown (GitHub README)
[![AllMCPs](https://allmcps.com/api/badge/postgresql-mcp-server-4?style=directory)](https://allmcps.com/mcp/postgresql-mcp-server-4)
HTML Embed
<a href="https://allmcps.com/mcp/postgresql-mcp-server-4"><img src="https://allmcps.com/api/badge/postgresql-mcp-server-4?style=directory" alt="PostgreSQL MCP Server on AllMCPs" /></a>