Skip to content
MCP server

postgres-mcp

MCP server giving AI assistants Postgres index tuning, EXPLAIN plans and health checks

Actively maintained

The repository was last updated 3 days ago and is published under MIT.

postgres-mcp is an open-source MCP server for databases. It is available on CLI, API, Self-hosted, Linux, macOS and Windows.

Pricing
Open source
Platforms
CLI, API, Self-hosted
What it can do
Can change data (1 tool)
GitHub stars
3.5K
Last commit

Similar MCP servers

About postgres-mcp

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.

Tools this server provides (9)

Taken from the project documentation; the running server may differ.

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_schemasName suggests: reads
Lists all database schemas available in the PostgreSQL instance.
list_objectsName suggests: reads
Lists database objects (tables, views, sequences, extensions) within a specified schema.
get_object_detailsName suggests: reads
Provides information about a specific database object, such as a table's columns, constraints and indexes.
execute_sqlName suggests: changes
Executes SQL statements, with read-only limitations in restricted mode.
explain_queryName suggests: reads
Gets the execution plan for a SQL query, optionally with hypothetical indexes.
get_top_queriesName suggests: reads
Reports the slowest SQL queries based on pg_stat_statements data.
analyze_workload_indexesName suggests: reads
Analyzes the database workload and recommends indexes for resource-intensive queries.
analyze_query_indexesName suggests: reads
Analyzes a list of specific SQL queries (up to 10) and recommends indexes for them.
analyze_db_healthName suggests: reads
Performs health checks including buffer cache hit rates, connection health, constraint validation, index health, sequence limits and vacuum health.

What it does

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

Pricing

Open source

Free and open source under the MIT license.

More servers for the same service

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

How AIPoweredBot checks servers