Postgres MCP Pro 是谁开发的?是官方项目吗?
它由 Crystal DBA 创建和维护。它不是 PostgreSQL 官方项目,也与已归档的参考版 Postgres MCP 服务器是不同的项目。
@crystaldba
基本信息
Postgres MCP Pro 为你和你的 AI 智能体提供可配置的读写访问和性能分析。
使用下面的配置,将此服务器添加到你的 MCP 客户端。
{
"mcpServers": {
"postgres-mcp": {
"command": "docker",
"args": [
"pull",
"crystaldba/postgres-mcp"
]
}
}
}工具列表暂未提供
当前收录暂时没有可展示的工具列表,不代表服务没有工具。请查阅项目文档了解支持的能力。
工具是从 README 中自动提取的。维护者可以在 ## Tools 标题下列出工具,即可填充这部分内容。
Postgres MCP Pro 是 Crystal DBA 推出的开源 postgres mcp server,为 AI 智能体提供面向 PostgreSQL 的安全 SQL 执行、schema 智能、EXPLAIN 执行计划、数据库健康检查和索引调优。
它不只是对数据库连接的简单封装。除了执行查询,它还提供用于性能优化的确定性工具:借助 pg_stat_statements 找出慢查询,借助 hypopg 模拟假设索引,并为你的工作负载搜索合适的索引配置。受限的只读访问模式让它也可以用于生产数据库。它采用 MIT 许可证,在 PyPI 上以 postgres-mcp 发布,在 Docker Hub 上以 crystaldba/postgres-mcp 发布,同时支持 stdio 和 SSE 两种传输方式。
前提条件:一个 PostgreSQL 连接 URI(先用 psql 或 pgAdmin 确认它可用),以及 Docker 或 Python 3.12+。维护者通常推荐 Docker,因为 Python 安装更容易遇到与环境相关的问题。
选择一种方式安装:
docker pull crystaldba/postgres-mcp
# or
pipx install postgres-mcp
# or
uv pip install postgres-mcp
选择访问模式:--access-mode=unrestricted 允许对数据和 schema 进行完整读写(用于开发环境);--access-mode=restricted 将智能体限制在只读事务中,并限制执行时间(用于生产环境)。
编辑 claude_desktop_config.json(macOS:~/Library/Application Support/Claude/claude_desktop_config.json;Windows:%APPDATA%/Claude/claude_desktop_config.json)。使用 Docker 时:
{
"mcpServers": {
"postgres": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"-e",
"DATABASE_URI",
"crystaldba/postgres-mcp",
"--access-mode=unrestricted"
],
"env": {
"DATABASE_URI": "postgresql://username:password@localhost:5432/dbname"
}
}
}
}
Docker 镜像会自动重映射 localhost(macOS/Windows 上使用 host.docker.internal,Linux 上使用 172.17.0.1 或合适的主机地址)。改用 uvx 时:
{
"mcpServers": {
"postgres": {
"command": "uvx",
"args": ["postgres-mcp", "--access-mode=restricted"],
"env": {
"DATABASE_URI": "postgresql://username:password@localhost:5432/dbname"
}
}
}
}
如果用 pipx 安装,使用 "command": "postgres-mcp";如果用 uv,使用 "command": "uv" 和 "args": ["run", "postgres-mcp", "--access-mode=unrestricted"]。
用 Claude Code CLI 添加同样的 stdio 命令:
claude mcp add postgres \
-e DATABASE_URI=postgresql://username:password@localhost:5432/dbname \
-- uvx postgres-mcp --access-mode=restricted
从命令面板打开 Cursor Settings,进入 MCP 标签页,粘贴上面任意一个 mcpServers 配置块。Windsurf(Open Windsurf Settings Page)、Goose(goose configure → Add Extension)和 Qodo Gen 也使用相同的配置。
使用 --transport=sse 启动服务器:
docker run -p 8000:8000 \
-e DATABASE_URI=postgresql://username:password@localhost:5432/dbname \
crystaldba/postgres-mcp --access-mode=unrestricted --transport=sse
然后在 Cursor(mcp.json)或 Cline 中用 {"type": "sse", "url": "http://localhost:8000/sse"} 指向它。Windsurf 使用 serverUrl 而不是 url。
如需索引调优和工作负载分析,请启用 pg_stat_statements 和 hypopg。在 AWS RDS、Azure 或 Google Cloud SQL 等托管服务上,它们通常已经可用:
CREATE EXTENSION IF NOT EXISTS pg_stat_statements;
CREATE EXTENSION IF NOT EXISTS hypopg;
list_schemas、list_objects(表、视图、序列、扩展)和 get_object_details(列、约束、索引)。execute_sql,在 restricted 模式下为只读。explain_query 返回执行计划,并可包含假设索引。get_top_queries 根据 pg_stat_statements 报告最慢的查询;analyze_workload_indexes 为整个工作负载推荐索引;analyze_query_indexes 为最多 10 条指定查询推荐索引。analyze_db_health 运行全部健康检查。postgres-mcp)主要用于执行查询和列出表。安装前请核对包名和作者。localhost,但请先在主机上用 psql 确认 URI 可用,并确认 Postgres 接受来自 Docker 网络的连接。pg_stat_statements 和 hypopg。在自行管理的 Postgres 上,pg_stat_statements 必须列在 shared_preload_libraries 中,hypopg 可能需要通过系统包安装。--access-mode=unrestricted。-p 8000:8000),客户端使用 /sse 路径;Windsurf 需要使用 serverUrl。它由 Crystal DBA 创建和维护。它不是 PostgreSQL 官方项目,也与已归档的参考版 Postgres MCP 服务器是不同的项目。
免费。它以 MIT 许可证开源,运行在你自己的机器或基础设施上。
请使用 `--access-mode=restricted`。它将智能体限制在只读事务中,并限制执行时间。unrestricted 模式允许修改数据和 schema,适用于开发环境。
目前的测试主要针对 Postgres 15、16 和 17;维护者计划支持 13 到 17。
可以。它通过标准连接 URI 连接,README 也介绍了如何在 AWS RDS、Azure SQL 和 Google Cloud SQL 上用 `CREATE EXTENSION` 启用扩展。
README 给出了 Claude Desktop 的完整步骤,以及 Cursor、Windsurf、Goose、Qodo Gen 和 Cline 的说明。其他能运行 stdio 或 SSE MCP 服务器的客户端(包括 Claude Code)都可以使用相同的命令。
默认通过 stdio 在本地运行。使用 `--transport=sse` 时,它可以作为共享服务器运行,供多个客户端通过 HTTP 连接。
不需要。它只需要你的 PostgreSQL 数据库的 `DATABASE_URI`。

Model Context Protocol Servers
MCP server for interacting with Neon Management API and databases
An official Qdrant Model Context Protocol (MCP) server implementation
A Model Context Protocol server that provides read-only access to MySQL databases. This server enables LLMs to inspect database schemas and execute read-only queries.
A MCP (model context protocol) server that gives the LLM access to and knowledge about relational databases like SQLite, Postgresql, MySQL & MariaDB, Oracle, and MS-SQL.
评论