Provides comprehensive PostgreSQL database management tools including schema inspection, SQL execution, query explanation with EXPLAIN plans, index tuning recommendations, workload analysis, and database health checks with support for pg_stat_statements and hypopg extensions.
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@pgsql-mcpshow me the top 5 slowest queries from the last hour"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
pgsql-mcp
A PostgreSQL MCP server with index tuning, explain plans, health checks, and safe SQL execution.
Features
Database Health - analyze index health, connection utilization, buffer cache, vacuum health, and more
Index Tuning - find optimal indexes for your workload using industrial-strength algorithms
Query Plans - review EXPLAIN plans and simulate hypothetical indexes
Schema Intelligence - context-aware SQL generation
Safe SQL Execution - configurable read-only mode for production use
Quick Start
Claude Code / Cloud IDEs
For Claude Code or cloud-based IDEs, add to your MCP configuration:
{
"mcpServers": {
"postgres": {
"command": "uvx",
"args": ["pgsql-mcp", "--access-mode=unrestricted"],
"env": {
"DATABASE_URI": "postgresql://username:password@localhost:5432/dbname"
}
}
}
}VS Code / Cursor / Windsurf
Using SSE (recommended for IDEs):
Start the server:
docker run -p 8000:8000 \
-e DATABASE_URI=postgresql://username:password@localhost:5432/dbname \
pgsql-mcp --access-mode=unrestricted --transport=sseAdd to your MCP config (
mcp.jsonfor Cursor,mcp_config.jsonfor Windsurf):
{
"mcpServers": {
"postgres": {
"type": "sse",
"url": "http://localhost:8000/sse"
}
}
}Note: Windsurf uses
serverUrlinstead ofurl.
Using stdio:
{
"mcpServers": {
"postgres": {
"command": "docker",
"args": [
"run", "-i", "--rm",
"-e", "DATABASE_URI",
"pgsql-mcp",
"--access-mode=unrestricted"
],
"env": {
"DATABASE_URI": "postgresql://username:password@localhost:5432/dbname"
}
}
}
}Docker
docker pull pgsql-mcpRun with stdio:
docker run -i --rm \
-e DATABASE_URI=postgresql://username:password@localhost:5432/dbname \
pgsql-mcp --access-mode=unrestrictedRun with SSE:
docker run -p 8000:8000 \
-e DATABASE_URI=postgresql://username:password@localhost:5432/dbname \
pgsql-mcp --access-mode=unrestricted --transport=ssePython Installation
pipx install pgsql-mcp
# or
uv pip install pgsql-mcpAccess Modes
--access-mode=unrestricted- Full read/write access (development)--access-mode=restricted- Read-only with resource limits (production)
Optional: Postgres Extensions
For full index tuning capabilities, install these extensions:
CREATE EXTENSION IF NOT EXISTS pg_stat_statements;
CREATE EXTENSION IF NOT EXISTS hypopg;Available Tools
Tool | Description |
| List all database schemas |
| List tables, views, sequences in a schema |
| Get columns, constraints, indexes for an object |
| Execute SQL (read-only in restricted mode) |
| Get query execution plans with hypothetical index support |
| Find slowest queries via pg_stat_statements |
| Recommend indexes for your workload |
| Recommend indexes for specific queries |
| Run comprehensive health checks |
License
MIT
This server cannot be installed
Resources
Looking for Admin?
Admins can modify the Dockerfile, update the server description, and track usage metrics. If you are the server author, to access the admin panel.