# postgres-mcp

> postgres-mcp is an open-source MCP server for databases. MCP server giving AI assistants Postgres index tuning, EXPLAIN plans and health checks. It is available on CLI, API, Self-hosted, Linux, macOS and Windows.

- **Kind:** MCP server
- **Pricing:** Open source
- **Platforms:** CLI, API, Self-hosted, Linux, macOS, Windows
- **Repository:** https://github.com/crystaldba/postgres-mcp
- **GitHub stars:** 3,516
- **License:** MIT
- **Categories:** [databases](https://ai-powered.com/categories/databases)
- **Listing updated:** 2026-12-01

## About

Postgres MCP Pro connects an AI assistant to a PostgreSQL database and adds performance tooling on top of plain query execution. Beyond running SQL, it can review health signals such as index usage, buffer cache hit rates, vacuum state, replication lag and sequence limits, and it can explain query plans, including simulated plans with hypothetical indexes.

Index recommendations come from a search over candidate indexes built from workload data gathered through the pg_stat_statements and hypopg extensions. Users can also ask the assistant to analyze specific queries, which makes the server useful when chasing slow ORM code or planning schema changes before deployment.

It suits developers working against development databases and DBAs who want an assistant to investigate production performance. Access can be set to unrestricted for development or restricted to read-only transactions with an execution time limit for production use.

## Features

- **Database health checks:** Reports on index health, connection use, buffer cache, vacuum, replication, constraints and sequence limits.
- **Index tuning:** Searches candidate multicolumn indexes against the workload and weighs performance gains against storage cost.
- **Query plan analysis:** Retrieves EXPLAIN plans and simulates how hypothetical indexes would change them.
- **Slow query discovery:** Ranks the top queries by total or mean execution time from pg_stat_statements data.
- **Configurable access modes:** Switches between unrestricted read/write access and read-only transactions with a query time limit.
- **Multiple transports:** Serves MCP over stdio, SSE or Streamable HTTP for local or shared server setups.

## Good for

- Finding missing or unused indexes in a slow application database
- Getting plain-language explanations of EXPLAIN output for a problem query
- Checking a production Postgres instance for vacuum, connection or replication issues
- Letting an assistant safely run read-only exploratory SQL against a live database
- Reviewing an ORM-generated query and suggesting an index or rewrite

## Tools

From the tool list in its README, going by the names, 1 of 9 tools changes data. From the server's own tool labels and tool names; not verified by us.

- `list_schemas` (name suggests: reads): Lists all database schemas available in the PostgreSQL instance.
- `list_objects` (name suggests: reads): Lists database objects (tables, views, sequences, extensions) within a specified schema.
- `get_object_details` (name suggests: reads): Provides information about a specific database object, such as a table's columns, constraints and indexes.
- `execute_sql` (name suggests: changes): Executes SQL statements, with read-only limitations in restricted mode.
- `explain_query` (name suggests: reads): Gets the execution plan for a SQL query, optionally with hypothetical indexes.
- `get_top_queries` (name suggests: reads): Reports the slowest SQL queries based on pg_stat_statements data.
- `analyze_workload_indexes` (name suggests: reads): Analyzes the database workload and recommends indexes for resource-intensive queries.
- `analyze_query_indexes` (name suggests: reads): Analyzes a list of specific SQL queries (up to 10) and recommends indexes for them.
- `analyze_db_health` (name suggests: reads): Performs health checks including buffer cache hit rates, connection health, constraint validation, index health, sequence limits and vacuum health.

## FAQ

### Which Postgres versions are supported?

Postgres 15 and later are supported and tested, and Postgres 12 is tested on a best-effort basis.

### How do I install postgres-mcp?

It can be run with Docker using the crystaldba/postgres-mcp image, or installed from PyPI with pipx or uv.

### What does restricted mode do?

Restricted mode limits operations to read-only transactions and applies an execution time limit.

### Does the HTTP transport require authentication?

No. The SSE and Streamable HTTP transports do not authenticate clients, so the port should stay on loopback or sit behind an authenticating proxy.

### Is postgres-mcp free?

Yes. postgres-mcp is open source, so you can use and self-host it for free.

### What are the best alternatives to postgres-mcp?

The closest alternatives to postgres-mcp are PostgreSQL performance Tuner MCP Server, Postgres MCP, MCP Postgres, postgres_mcp and Postgres Scout MCP.

## Where this comes from

- Description: written from the project's README.

## Alternatives

- [PostgreSQL performance Tuner MCP Server](https://ai-powered.com/mcp/postgresql-performance-tuner-mcp-server): PostgreSQL performance Tuner MCP Server is an open-source MCP server for databases.
- [Postgres MCP](https://ai-powered.com/mcp/postgres-mcp-3): Postgres MCP is an open-source MCP server for databases.
- [MCP Postgres](https://ai-powered.com/mcp/mcp-postgres): MCP Postgres is an open-source MCP server for databases.
- [postgres_mcp](https://ai-powered.com/mcp/postgres-mcp-5): postgres_mcp is an open-source MCP server for databases.
- [Postgres Scout MCP](https://ai-powered.com/mcp/postgres-scout-mcp): Postgres Scout MCP is an open-source MCP server for databases.
- [sql-query-mcp](https://ai-powered.com/mcp/sql-query-mcp): sql-query-mcp is an open-source MCP server for databases.
- [mysql_mcp_server_pro](https://ai-powered.com/mcp/mysql-mcp-server-pro): mysql_mcp_server_pro is an open-source MCP server for databases.
- [PostgreSQL MCP Server](https://ai-powered.com/mcp/postgresql-mcp-server-2): PostgreSQL MCP Server is an open-source MCP server for databases.

---
Source: https://ai-powered.com/mcp/postgres-mcp-4
