home / mcp / mcp postgresql ops server

MCP PostgreSQL Ops Server

πŸ”Professional MCP server for PostgreSQL operations & monitoring: 30+ extension-independent tools for performance analysis, table bloat detection, autovacuum monitoring, schema introspection, and database management. Supports PostgreSQL 12-17.

Installation
Add the following to your MCP client configuration file.

Configuration

View docs
{
  "mcpServers": {
    "call518-mcp-postgresql-ops": {
      "command": "uvx",
      "args": [
        "--python",
        "3.12",
        "mcp-postgresql-ops"
      ],
      "env": {
        "POSTGRES_DB": "ecommerce",
        "POSTGRES_HOST": "127.0.0.1",
        "POSTGRES_PORT": "15432",
        "POSTGRES_USER": "postgres",
        "POSTGRES_PASSWORD": "changeme!@34"
      }
    }
  }
}

You use MCP-PostgreSQL-Ops to run a read-only, production-safe MCP server that connects to PostgreSQL databases for monitoring, analysis, and maintenance recommendations. It supports PostgreSQL 12–17, with optional extensions for enhanced query analytics, and provides natural language queries to explore your databases without running SQL manually.

How to use

To use this MCP server, run it with your MCP client in either standard input/output (stdio) mode or HTTP transport mode. In stdio mode, you interact via the local command line interface and feed prompts directly from your MCP client. In HTTP mode, you expose a REST-like endpoint that clients can call remotely, enabling authentication if you enable bearer tokens.

How to install

Prerequisites: Python 3.12, a supported PostgreSQL server (12–17), and network access to PostgreSQL. You may also prefer to run an MCP server container or install via Python packaging tools.

# 1) Install via PyPI (recommended)
pip install mcp-postgresql-ops

# 2) Or install with uv (faster)
uv add mcp-postgresql-ops

# 3) Verify installation
mcp-postgresql-ops --help
```

```bash
# 4) If building from source
git clone https://github.com/call518/MCP-PostgreSQL-Ops.git
cd MCP-PostgreSQL-Ops
uv sync
uv run mcp-postgresql-ops --help
```

You can also run the MCP server in standalone HTTP mode or stdio mode using the commands shown in the next steps.

Configuration and usage notes

You control access and connections through environment variables and MCP client configuration. The following key settings are used to connect to PostgreSQL and to configure how the MCP server exposes its interface.

Security and authentication

For remote HTTP access, you can enable Bearer token authentication. This protects the MCP server when it is exposed to untrusted networks.

Example queries you can run

Examples you can try with natural language prompts include: Show me the current active connections, What are the slowest queries, Analyze table bloat across all databases, Show database sizes, What tables need VACUUM maintenance.

Available tools

get_server_info

Show PostgreSQL server version and extension status; check available MCP tools for this version.

get_active_connections

Show all active connections and sessions with database and user.

get_postgresql_config

Show all PostgreSQL configuration parameters.

get_database_list

List all databases and their sizes.

get_table_list

List all tables in a database and their sizes.

get_table_schema_info

Show detailed schema information for a specific table, including columns, constraints, and indexes.

get_database_schema_info

Show schema details for a database, including schemas, objects, and permissions.

get_table_relationships

Show foreign key relationships for a given table or across the database.

get_user_list

List database users and their roles.

get_index_usage_stats

Analyze index usage and identify unused indexes.

get_database_size_info

Provide overall database size information and growth trends.

get_table_size_info

Provide size details for tables and indexes.

get_vacuum_analyze_stats

Show VACUUM and ANALYZE activity statistics.

get_current_database_info

Show current database information including encoding, collation, and size.

get_table_bloat_analysis

Analyze table bloat and provide VACUUM recommendations.

get_database_bloat_overview

Provide a high-level view of bloat by schema.

get_autovacuum_status

Monitor autovacuum status, thresholds, and activity.

get_autovacuum_activity

Show autovacuum activity patterns over time.

get_running_vacuum_operations

Show currently running VACUUM/ANALYZE operations.

get_vacuum_effectiveness_analysis

Analyze VACUUM effectiveness and maintenance patterns.

get_lock_monitoring

Show current locks and blocked sessions.

get_wal_status

Show WAL status and archiving information.

get_replication_status

Check replication connections and lag.

get_database_stats

Provide comprehensive performance metrics for databases.

get_bgwriter_stats

Analyze background writer and checkpoint performance.

get_user_functions_stats

Analyze user-defined function performance (requires track_functions).

get_table_io_stats

Analyze table I/O performance and timing (requires track_io_timing).

get_index_io_stats

Analyze index I/O performance (requires track_io_timing).

get_database_conflicts_stats

Check replication conflicts and related statistics.

get_pg_stat_statements_top_queries

Show top slow queries using pg_stat_statements (extension required).