# Postgres MCP Pro — Index Tuning + Safe SQL Tools > Postgres MCP Pro is an MCP server for PostgreSQL that runs safe SQL, explains plans, and recommends indexes so agents can tune databases faster. ## Install Merge the JSON below into your `.mcp.json`: ## Quick Use 1. Install (choose one): ```bash docker pull crystaldba/postgres-mcp # or pipx install postgres-mcp ``` 2. Configure Claude Desktop (`claude_desktop_config.json`): ```json { "mcpServers": { "postgres": { "command": "postgres-mcp", "args": ["--access-mode=unrestricted"], "env": { "DATABASE_URI": "postgresql://username:password@localhost:5432/dbname" } } } } ``` 3. Verify: ask Claude to `list_schemas`, then run an `explain_query` for a slow SQL statement. ## Intro Postgres MCP Pro is an MCP server for PostgreSQL that runs safe SQL, explains plans, and recommends indexes so agents can tune databases faster. - **Best for:** teams that want an AI-safe Postgres copilot for schema exploration, plan analysis, and index tuning - **Works with:** PostgreSQL, stdio/SSE MCP clients (Claude Desktop, Cursor), Docker or Python 3.12+ - **Setup time:** 10-25 minutes ## Practical Notes - Quant: GitHub stars and forks indicate broad usage; treat this as a production-grade starting point for DB copilots. - Quant: start in read-only, then add write access only after you can replay the same query-analysis prompt 3 times with identical outputs. ## Why it matters Postgres MCP Pro is useful when you want agents to do real database work (plans, health, indexes) without turning your production DB into an unguarded tool. - Install paths cover Docker and Python package managers, making it easy to standardize across developer machines. - The repo documents a concrete Claude Desktop `mcpServers` configuration, which reduces integration guesswork. - The toolset is explicitly positioned around query plans and index tuning rather than only ad-hoc SQL execution. ## Rollout pattern - Point it at a staging replica first, and validate schema + EXPLAIN flows end-to-end before touching production. - Adopt a playbook: (1) schema snapshot, (2) EXPLAIN, (3) index hypothesis, (4) verify with a before/after benchmark. - Keep a human approval rule for any action that changes indexes or constraints. ## Watchouts Avoid giving unrestricted write access on day 1. Keep credentials scoped, start with read-only, and review any index recommendations with real workload evidence. ### FAQ **Q: Does it require Docker?** A: No. The README shows Docker and Python installs (pipx/uv). Use Docker when you want fewer environment surprises. **Q: How do I keep it safe?** A: Prefer read-only and a least-privilege DB user. Add writes only with an explicit approval gate. **Q: What is a good first task?** A: Ask the agent to list schemas/tables, then run an EXPLAIN for one slow query and propose one index hypothesis. ## Source & Thanks > Source: https://github.com/crystaldba/postgres-mcp > License: MIT > GitHub stars: 2,730 · forks: 299 --- ## 快速使用 1. 安装(二选一): ```bash docker pull crystaldba/postgres-mcp # 或 pipx install postgres-mcp ``` 2. 配置 Claude Desktop(`claude_desktop_config.json`): ```json { "mcpServers": { "postgres": { "command": "postgres-mcp", "args": ["--access-mode=unrestricted"], "env": { "DATABASE_URI": "postgresql://username:password@localhost:5432/dbname" } } } } ``` 3. 验证:先让 Claude 调 `list_schemas`,再对一条慢 SQL 跑 `explain_query` 看计划。 ## 简介 Postgres MCP Pro 是面向 PostgreSQL 的 MCP Server,提供安全 SQL 执行、EXPLAIN 分析与索引建议,让 Agent 能以更低风险、更高速度定位并优化数据库问题。 - **适合谁:** 希望用“可控、可审计”的方式让 Agent 帮你查库、看执行计划并做索引调优的团队 - **可搭配:** PostgreSQL、支持 MCP 的客户端(Claude Desktop / Cursor 等)、Docker 或 Python 3.12+ - **准备时间:** 10-25 分钟 ## 实战建议 - 量化信息:Stars/Forks 代表社区采用度;适合当作“可上生产”的 DB copilot 起点。 - 量化信息:先只读运行;当你能把同一条诊断提示复现 3 次且输出一致后,再逐步开放写权限。 ## 为什么值得收录 当你希望 Agent 真的能做数据库工作(执行计划、健康检查、索引优化),又不想把生产库变成“裸奔工具”时,Postgres MCP Pro 的价值会很明显。 - 同时提供 Docker 与 Python 包管理器安装路径,便于团队统一落地。 - README 给出了 Claude Desktop 的 `mcpServers` 配置示例,集成成本更低。 - 能力重点围绕执行计划与索引优化,而不是只做随意 SQL 执行。 ## 落地路径 - 先连 staging/只读副本,跑通 schema 与 EXPLAIN 全链路再考虑生产。 - 固定一个调优模板:1) schema 快照 2) EXPLAIN 3) 索引假设 4) before/after 基准验证。 - 任何会改变索引/约束的操作都建议加人工审批闸门。 ## 注意事项 不要一上来就开放不受限写权限:先最小权限 + 只读起步,并用真实 workload 证据去验证任何索引建议。 ### FAQ **一定要用 Docker 吗?** 答:不需要。README 同时提供 Docker 与 pipx/uv 的安装方式;想少踩环境坑就用 Docker。 **如何把风险降到最低?** 答:优先只读 + 最小权限 DB 用户;需要写操作时加明确的审批闸门。 **第一件该做什么?** 答:先列出 schema/table,再对一条慢 SQL 跑 EXPLAIN,并让 Agent 给出 1 个索引假设。 ## 来源与感谢 > Source: https://github.com/crystaldba/postgres-mcp > License: MIT > GitHub stars: 2,730 · forks: 299 --- Source: https://tokrepo.com/en/workflows/postgres-mcp-pro-index-tuning-safe-sql-tools Author: MCP Hub