home / mcp / 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.
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.
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.
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.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.
For remote HTTP access, you can enable Bearer token authentication. This protects the MCP server when it is exposed to untrusted networks.
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.
Show PostgreSQL server version and extension status; check available MCP tools for this version.
Show all active connections and sessions with database and user.
Show all PostgreSQL configuration parameters.
List all databases and their sizes.
List all tables in a database and their sizes.
Show detailed schema information for a specific table, including columns, constraints, and indexes.
Show schema details for a database, including schemas, objects, and permissions.
Show foreign key relationships for a given table or across the database.
List database users and their roles.
Analyze index usage and identify unused indexes.
Provide overall database size information and growth trends.
Provide size details for tables and indexes.
Show VACUUM and ANALYZE activity statistics.
Show current database information including encoding, collation, and size.
Analyze table bloat and provide VACUUM recommendations.
Provide a high-level view of bloat by schema.
Monitor autovacuum status, thresholds, and activity.
Show autovacuum activity patterns over time.
Show currently running VACUUM/ANALYZE operations.
Analyze VACUUM effectiveness and maintenance patterns.
Show current locks and blocked sessions.
Show WAL status and archiving information.
Check replication connections and lag.
Provide comprehensive performance metrics for databases.
Analyze background writer and checkpoint performance.
Analyze user-defined function performance (requires track_functions).
Analyze table I/O performance and timing (requires track_io_timing).
Analyze index I/O performance (requires track_io_timing).
Check replication conflicts and related statistics.
Show top slow queries using pg_stat_statements (extension required).