Pg Doctor
Read-only PostgreSQL diagnostics for AI agents: slow queries, plans, bloat, locks
Pg Doctor is an open-source MCP server for databases. It runs locally on your machine and is started by your AI client.
- Pricing
- Open source
- Platforms
- CLI, Linux, macOS
- Runs
- Locally
- Access
- Needs a secret key or token
- Version
- 0.3.0
- Listing updated
Similar MCP servers
Install
Add with the CLI
Run in a terminal
claude mcp add pg-doctor --env DATABASE_URL='<DATABASE_URL>' -- docker run -i --rm -e DATABASE_URL ghcr.io/alaev-dev/pg-doctor:0.3.0Add --scope user to use it in every project, or --scope project to share it in .mcp.json.
Or share it with your project
Add to .mcp.json
{
"mcpServers": {
"pg-doctor": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"-e",
"DATABASE_URL",
"ghcr.io/alaev-dev/pg-doctor:0.3.0"
],
"env": {
"DATABASE_URL": "<DATABASE_URL>"
}
}
}
}Add to claude_desktop_config.json
{
"mcpServers": {
"pg-doctor": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"-e",
"DATABASE_URL",
"ghcr.io/alaev-dev/pg-doctor:0.3.0"
],
"env": {
"DATABASE_URL": "<DATABASE_URL>"
}
}
}
}Settings → Developer → Edit Config, then quit and reopen Claude Desktop.
Add to ~/.cursor/mcp.json
{
"mcpServers": {
"pg-doctor": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"-e",
"DATABASE_URL",
"ghcr.io/alaev-dev/pg-doctor:0.3.0"
],
"env": {
"DATABASE_URL": "<DATABASE_URL>"
}
}
}
}Use .cursor/mcp.json in a project to share it with the project.
Add to ~/.copilot/mcp-config.json
{
"mcpServers": {
"pg-doctor": {
"type": "stdio",
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"-e",
"DATABASE_URL",
"ghcr.io/alaev-dev/pg-doctor:0.3.0"
],
"env": {
"DATABASE_URL": "<DATABASE_URL>"
}
}
}
}Or put the same entry in .mcp.json at your workspace root to share it.
Add with the CLI
Run in a terminal
codex mcp add pg-doctor --env DATABASE_URL='<DATABASE_URL>' -- docker run -i --rm -e DATABASE_URL ghcr.io/alaev-dev/pg-doctor:0.3.0Or add to config.toml
Add to ~/.codex/config.toml
[mcp_servers.pg-doctor]
command = "docker"
args = ["run", "-i", "--rm", "-e", "DATABASE_URL", "ghcr.io/alaev-dev/pg-doctor:0.3.0"]
env = { DATABASE_URL = "<DATABASE_URL>" }Add to your client's MCP settings (most use this shape)
{
"mcpServers": {
"pg-doctor": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"-e",
"DATABASE_URL",
"ghcr.io/alaev-dev/pg-doctor:0.3.0"
],
"env": {
"DATABASE_URL": "<DATABASE_URL>"
}
}
}
}Gemini CLI and Antigravity
Gemini CLI
Add to ~/.gemini/settings.json
{ "mcpServers": { "pg-doctor": { "command": "docker", "args": [ "run", "-i", "--rm", "-e", "DATABASE_URL", "ghcr.io/alaev-dev/pg-doctor:0.3.0" ], "env": { "DATABASE_URL": "<DATABASE_URL>" } } } }Or run: gemini mcp add -s user -e DATABASE_URL='<DATABASE_URL>' pg-doctor docker -- run -i --rm -e DATABASE_URL ghcr.io/alaev-dev/pg-doctor:0.3.0
Antigravity
Add to ~/.gemini/config/mcp_config.json
{ "mcpServers": { "pg-doctor": { "command": "docker", "args": [ "run", "-i", "--rm", "-e", "DATABASE_URL", "ghcr.io/alaev-dev/pg-doctor:0.3.0" ], "env": { "DATABASE_URL": "<DATABASE_URL>" } } } }Use .agents/mcp_config.json to add it to one workspace only.
Devin Desktop (formerly Windsurf)
Add to ~/.config/devin/mcp_config.json
{ "mcpServers": { "pg-doctor": { "command": "docker", "args": [ "run", "-i", "--rm", "-e", "DATABASE_URL", "ghcr.io/alaev-dev/pg-doctor:0.3.0" ], "env": { "DATABASE_URL": "<DATABASE_URL>" } } } }On Windows the file is %APPDATA%\devin\mcp_config.json. Use .devin/mcp_config.json to share it with a project.
Cline
Add to cline_mcp_settings.json
{ "mcpServers": { "pg-doctor": { "command": "docker", "args": [ "run", "-i", "--rm", "-e", "DATABASE_URL", "ghcr.io/alaev-dev/pg-doctor:0.3.0" ], "env": { "DATABASE_URL": "<DATABASE_URL>" } } } }Open it from the MCP Servers icon → Configure → Configure MCP Servers.
Zed
Add to Zed settings.json
{ "context_servers": { "pg-doctor": { "command": "docker", "args": [ "run", "-i", "--rm", "-e", "DATABASE_URL", "ghcr.io/alaev-dev/pg-doctor:0.3.0" ], "env": { "DATABASE_URL": "<DATABASE_URL>" } } } }Open it with zed: open settings file. Merge context_servers into the settings you already have.
JetBrains AI Assistant and Junie
AI Assistant
Add to Settings → Tools → AI Assistant → Model Context Protocol (MCP) → Add
{ "mcpServers": { "pg-doctor": { "command": "docker", "args": [ "run", "-i", "--rm", "-e", "DATABASE_URL", "ghcr.io/alaev-dev/pg-doctor:0.3.0" ], "env": { "DATABASE_URL": "<DATABASE_URL>" } } } }The AI Assistant docs only show command and args. If the env block is ignored, use Junie for this server.
Junie
Add to ~/.junie/mcp/mcp.json
{ "mcpServers": { "pg-doctor": { "command": "docker", "args": [ "run", "-i", "--rm", "-e", "DATABASE_URL", "ghcr.io/alaev-dev/pg-doctor:0.3.0" ], "env": { "DATABASE_URL": "<DATABASE_URL>" } } } }Use .junie/mcp/mcp.json to share it with a project.
Kiro
Add to ~/.kiro/settings/mcp.json
{ "mcpServers": { "pg-doctor": { "command": "docker", "args": [ "run", "-i", "--rm", "-e", "DATABASE_URL", "ghcr.io/alaev-dev/pg-doctor:0.3.0" ], "env": { "DATABASE_URL": "<DATABASE_URL>" } } } }Use .kiro/settings/mcp.json to add it to one workspace only.
Using several servers? Build one config file with the MCP config generator.
Configuration
DATABASE_URLConnection string of a dedicated PostgreSQL role with pg_monitor; table_bloat and explain_statement also need SELECT on the tables they look atRequired
About Pg Doctor
Pg Doctor is a Go server that gives an AI assistant read-only access to PostgreSQL performance data. Instead of handing the agent a SQL prompt, it offers eight fixed tools built on pg_stat views and system catalogs, so the agent can find the statements that cost the most time, plan them, and check indexes and table health without running queries of its own.
The server runs over stdio from a Docker image or a Go binary, or over Streamable HTTP for shared deployments. Every session is forced into a read-only transaction with a five-second statement timeout, and the database role is expected to hold pg_monitor. Query text comes only from pg_stat_statements with literals already masked, and table or column comments that try to instruct the agent are withheld and flagged.
It suits developers and database operators who use MCP clients such as Claude Code or Cursor and want help tracking down slow pages, lock chains, replica lag or unused indexes. Remote mode adds per-tool scopes, OAuth token introspection, rate limits, an audit log and OpenTelemetry tracing.
Tools this server provides (8)
Taken from the project documentation; the running server may differ.
From the tool list in its README, going by the names, 4 of 8 tools read data; 4 names don't say.
From the server's own tool labels and tool names; not verified by us.
- slow_queries
- Lists the statements that cost the most time, sorted by total or mean time, calls or disk reads.
- explain_statementName suggests: reads
- Plans a recorded statement by queryid using EXPLAIN GENERIC_PLAN without executing it.
- list_tablesName suggests: reads
- Lists tables largest first with heap and index size, row estimate and comment.
- describe_tableName suggests: reads
- Shows a table's columns, indexes, scan counts, dead rows and vacuum and analyze times.
- table_bloat
- Estimates dead space per table from pg_stats without reading the tables.
- blocking_locks
- Shows waiting sessions and root blockers using pg_blocking_pids.
- replication_statusName suggests: reads
- Reports replica lag, replication slots, retained WAL and replay pause state.
- unused_indexes
- Lists indexes not scanned since statistics were reset, excluding constraint-backing indexes.
What it does
- Slow query ranking
- Lists the statements using the most total or mean time from pg_stat_statements, with each one's share of overall load.
- Read-only query plans
- Plans a recorded statement by its queryid using a generic plan without executing it or accepting SQL input.
- Lock chain analysis
- Follows blocking chains to find the root blocker and flags sessions idle inside open transactions.
- Index and table inspection
- Shows table sizes, index usage, sequential versus index scans, dead rows and vacuum history, and finds unused indexes.
- Replication health checks
- Reports replay lag per replica, replication slots, retained WAL and whether replay is paused.
- Scoped remote access
- Limits each token to chosen tool groups and applies per-token rate limits and audit logging in HTTP mode.
Good for
- Finding out why a page that queries the database has become slow
- Spotting the root blocker when requests hang on database locks
- Checking whether replicas are falling behind and how much WAL slots retain
- Identifying indexes that have not been scanned since statistics were reset
- Reviewing table bloat and vacuum status before planning maintenance
Pricing
Open source
Free and open source under the MIT license.
More servers for the same service
Pg Doctor FAQ
Can the agent run arbitrary SQL through Pg Doctor?
No. None of the tools accept SQL, and every session runs as a read-only transaction with a five-second timeout.
What database permissions does Pg Doctor need?
A dedicated role with pg_monitor. table_bloat and explain_statement also need SELECT on the tables they inspect.
Does Pg Doctor return my table rows?
No. It works from statistics and catalogs and does not select from your tables.
Does slow_queries require any setup?
Yes, pg_stat_statements must be in shared_preload_libraries and the extension must be created in the database.
Is Pg Doctor free?
Yes. Pg Doctor is open source, so you can use and self-host it for free.
How do I add Pg Doctor to Claude Code?
Run this command in your terminal: claude mcp add pg-doctor --env DATABASE_URL='<DATABASE_URL>' -- docker run -i --rm -e DATABASE_URL ghcr.io/alaev-dev/pg-doctor:0.3.0
What are the best alternatives to Pg Doctor?
The closest alternatives to Pg Doctor are PostgreSQL Performance (read-only), pgmcp, Pg Checkup, PostgreSQL (hardened, read-only) and Postgres AIops.
Where this comes from
- Description: written from the project's README and its MCP Registry entry.
- Install steps: from the official MCP Registry entry.
