原型 · 预览版:收录官方注册中心里的全部服务器,每 30 分钟同步一次。评价和账户功能将在后续阶段推出。
PopNx MCP为使用 AI 的人准备的 MCP 服务器 · 用大白话讲清楚

Postgres DBA MCP

作者:a-lafon版本 0.3.3i★ –i在你的电脑上运行
注册名称io.github.a-lafon/postgres-dba-mcp

安装

概览

作者提供的说明(英文原文)

Bounded, read-only PostgreSQL access for AI assistants: nine DBA tools, compact CSV output

PopNx MCP 的三大支柱

这三项永远不会合并成一个分数:意见、测量和人气是不同的东西。

它能帮你做什么

我们还没有为它写通俗的介绍。下面是我们从注册中心读取到的事实。

  • 连接方式: 在你的电脑上运行
  • 传输方式: stdio
  • 分类: 数据库与数据集
  • 你需要填写:DATABASE_URI

安装

选择你使用的 AI 应用,然后复制设置。

安装之前

标为机密的值是你账户的钥匙。千万不要分享给别人,也不要粘贴到聊天里。

你需要

你用的是哪个应用?

在上方选择你的应用。我们会记住它,下次按钮会显示“安装到 …”。

打开 Claude Desktop → Settings → Developer → Edit Config,把下面的内容粘贴到 claude_desktop_config.json

{
  "mcpServers": {
    "postgres-dba": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "-e",
        "DATABASE_URI",
        "ghcr.io/a-lafon/postgres-dba-mcp:0.3.3"
      ],
      "env": {
        "DATABASE_URI": "your-value"
      }
    }
  }
}

在终端中运行这条命令

claude mcp add postgres-dba --env DATABASE_URI=your-value -- docker run -i --rm -e DATABASE_URI ghcr.io/a-lafon/postgres-dba-mcp:0.3.3

运行前请先填写空着的值。

在 Cursor 中打开

或者自己复制设置

粘贴到项目中的 .cursor/mcp.json,或 ~/.cursor/mcp.json

{
  "mcpServers": {
    "postgres-dba": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "-e",
        "DATABASE_URI",
        "ghcr.io/a-lafon/postgres-dba-mcp:0.3.3"
      ],
      "env": {
        "DATABASE_URI": "your-value"
      }
    }
  }
}

浏览器会先询问是否打开应用,然后应用会显示设置并请你确认。密钥的值会留空,由你自己填写。

在 VS Code 中打开

或者自己复制设置

粘贴到项目中的 .vscode/mcp.json

{
  "servers": {
    "postgres-dba": {
      "type": "stdio",
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "-e",
        "DATABASE_URI",
        "ghcr.io/a-lafon/postgres-dba-mcp:0.3.3"
      ],
      "env": {
        "DATABASE_URI": "your-value"
      }
    }
  }
}

浏览器会先询问是否打开应用,然后应用会显示设置并请你确认。密钥的值会留空,由你自己填写。

这个服务器在你的电脑上运行,而 ChatGPT 只能连接互联网上的服务器。请选择其他应用。

你的选择通过 Cookie 保存在这台设备上,无需账户。

需要你填写的值

  • DATABASE_URI 机密 必填 env
    PostgreSQL connection URI of the database to serve

这些设置是根据作者在注册中心的条目生成的。如果 README 的写法不同,请以 README 为准。

它能做什么

它在你的电脑上运行;安装后,工具列表会显示在你的 AI 应用中。

基础检查i

我们检查的是任何人都能看到的信息;我们没有阅读代码。不适用的检查项不计入总数。 · 检查于 2026年11月6日

  • ✓ 通过

    作者与仓库一致

    注册名称已通过 GitHub 账户 a-lafon 验证,该账户拥有此仓库

  • … 尚未检查

    仍在维护

    我们还没有从 GitHub 读取这个仓库

  • … 尚未检查

    有许可证

    我们还没有从 GitHub 读取这个仓库

  • – 不适用

    端点有响应

    它在你的电脑上运行,没有互联网端点

  • – 不适用

    使用 OAuth 登录

    在你的电脑上运行,改用本地设置

  • … 尚未检查

    工具描述中没有隐藏指令

    它在你的电脑上运行;我们只能读取互联网端点的工具列表

与“数据库与数据集”中的其他服务器比较i

  • 星标数多于此分类中其他 952 个服务器的 0%
  • 发布到注册中心的时间比此分类中其他 952 个服务器的 85% 更新
  • 基础检查结果等于或优于此分类中其他 952 个服务器的 100%

与注册中心里这个分类中所有活跃的服务器比较。只有当发布者拥有该仓库时,星标数才计入。

常见问题

Postgres DBA MCP 安全吗?

它在 1 项适用的基础检查中通过了 1 项。我们没有阅读代码。在添加密钥或令牌之前,请先看看这个服务器要求哪些权限,并使用只具备所需权限的密钥。

它需要哪些密钥或代码?

你需要填写:DATABASE_URI

它在我的电脑上运行还是在云端?

它在你的电脑上运行。你的 AI 应用会在需要时启动它,数据不会经过作者的服务器(除非它自己调用在线服务)。

它还在维护吗?

GitHub 仓库最后更新于–,最新版本(0.3.3)于7天前进入注册中心。

哪些应用可以使用它?

支持 MCP 的应用,例如 Claude Desktop、Claude Code、Cursor 和 VS Code。你的电脑上还需要有 Docker。

有什么可以替代它?

同一分类中有:Supabase, MongoDB MCP Server, Elasticsearch MCP Server

替代选择

同一分类中其他作者的服务器,按星标数排序。

如何看卡片:★ GitHub 星标i三大支柱:评价 · 检查 · 使用情况i更新 = 最新版本发布到注册中心的时间i

Supabase

作者:supabase

MCP server for interacting with the Supabase platform

电脑或云端★ 2,993Apache-2.0今天更新
安装

MongoDB MCP Server

作者:mongodb-js

MongoDB Model Context Protocol Server

在你的电脑上运行★ 1,157Apache-2.0前天更新
安装

MCP server for interacting with Elasticsearch

在你的电脑上运行★ 315Apache-2.014个月前更新
安装

作者的 README

打开 README

按原文从作者的仓库复制。PopNx MCP 没有审查或背书其内容。HTML、图片和脚本已被移除。链接会离开本站。

Bounded, read-only PostgreSQL access for AI assistants.

Let Claude Code, Codex or any MCP client explore a PostgreSQL database, run SQL, read query plans, test hypothetical indexes, find the slowest queries and check the database's health, without flooding the model's context or escaping read-only mode.

A Model Context Protocol server that gives an AI client compact, bounded access to one PostgreSQL database. It is a drop-in replacement for crystaldba/postgres-mcp 0.3.0, with its nine tools under the same names and the same parameters, plus analyze_locks of its own, in one static binary. Switching is one line of client configuration; what the model receives changes (compact CSV, bounded results, one statement per call), as listed in MIGRATION.md.

Why

crystaldba/postgres-mcp gives an assistant the right DBA tools: schema, SQL, plans with hypothetical indexes, top queries, health checks, index advice. Three things got in the way of using it every day:

  • Unbounded, verbose results. Rows come back as Python repr with no size limit. A plain SELECT on a big table returns hundreds of thousands of tokens, or fails.
  • A restricted mode that can be bypassed. Function names are not checked in FROM, so a "read-only" call can still run functions such as pg_read_file or pg_advisory_lock (CVE-2026-85620).
  • Weight. A Python container of about 300 MB that sits at about 250 MB of memory.

What the model receives changes:

  • compact CSV with an explicit footer, every result capped in rows, bytes and cell length, and every cut announced;
  • a restricted mode, on by default, that parses each statement with PostgreSQL's own parser (libpg_query) and checks every function call anywhere in it, inside a read-only transaction;
  • one static Go binary that starts in milliseconds.

Measured

Against crystaldba/postgres-mcp 0.3.0 on the same PostgreSQL 17 database and the same read-only role, measured on 959bb72 on 2026-11-01, except the agent tasks:

  • 61 % fewer tokens per execute_sql response: median of the 4 scenarios both servers answered (S01, S04, S05, S06). Every result is capped at 32 kB, where crystaldba returns up to 268k tokens or fails;
  • 131 of 131 attack statements refused in restricted mode, where crystaldba executes 10;
  • 9 MB of memory against 246 MB, both in a Linux container; cold start of 13 ms for the binary run directly, against 2.3 s for crystaldba including docker run;
  • 27 of 27 agent tasks solved with Claude Code, against 25 of 27 — the one dated measure here: 2026-10-22, on 0.1.0, before the volatility gate and before analyze_locks.

The other side: the tool definitions are 39 % larger (2732 tokens for ten tools against 1962 for crystaldba's nine), and the tokens of a whole agent task are comparable. Drop locks from --tools to get the 0.3.0 tool set exactly.

Method, every number (including where postgres-dba-mcp does worse) and charts: BENCHMARK.md. The harness that produced them is in bench, with its inputs: the data set in bench/data, the attack and legitimate corpora in testdata/safesql, and the scenarios and tasks listed in BENCHMARK.md. cd bench && go run ./cmd/bench all redoes the security, memory, cold start and scenario measures with no model account; exact token counts take --tokens=claude or an ANTHROPIC_API_KEY, and the agent tasks and their judge need the claude CLI. Prerequisites and what each level needs: bench/README.md.

What the model receives

The same SELECT * FROM types through both servers. crystaldba 0.3.0:

[{'id': 1, 'txt': 'hello', 'empty': '', 'num': Decimal('532.10'), 'arr': [1, 2], 'iv': datetime.timedelta(days=1, seconds=7200), 'ts': datetime.datetime(2026, 3, 2, 10, 14, tzinfo=zoneinfo.ZoneInfo(key='Etc/UTC')), 'bin': b'\xde\xad\xbe\xef'}, {'id': 2, 'txt': None, 'empty': None, 'num': None, 'arr': None, 'iv': None, 'ts': None, 'bin': None}]

postgres-dba-mcp:

id,txt,empty,num,arr,iv,ts,bin

1,hello,"",532.10,"{1,2}",1 day 02:00:00,2026-03-02 10:14:00+00,\xdeadbeef 2,\N,\N,\N,\N,\N,\N,\N -- 2 rows, 2 ms

Values keep their PostgreSQL text form, NULL (\N) stays distinct from an empty string, and the footer says how many rows came back and whether anything was cut.

Install

With Homebrew (macOS and Linux):

brew install a-lafon/tap/postgres-dba-mcp

With the install script (macOS and Linux, amd64 and arm64): it downloads the release archive, checks it against checksums.txt and puts the binary in ~/.local/bin (POSTGRES_DBA_MCP_INSTALL_DIR to change it, POSTGRES_DBA_MCP_VERSION=v0.1.0 for a given release):

curl -fsSL https://raw.githubusercontent.com/a-lafon/postgres-dba-mcp/main/install.sh | sh

With Docker (linux/amd64 and linux/arm64, non-root, no shell):

docker run -i --rm -e DATABASE_URI ghcr.io/a-lafon/postgres-dba-mcp:latest

localhost in the URI then means the container itself: on Docker Desktop use host.docker.internal, on Linux --network=host (see below).

From a release archive, Windows included: download the archive for your system from the releases page (darwin, linux and windows on amd64; darwin and linux also on arm64), check it against checksums.txt (SHA-256), and put the postgres-dba-mcp binary on your PATH.

With the Go toolchain (Go 1.26 or later): go install github.com/a-lafon/postgres-dba-mcp/cmd/postgres-dba-mcp@latest.

The Linux binaries and the image parse SQL with the native PostgreSQL parser (about 20 MB at start). The macOS and Windows binaries, and a plain go install, use a WASM copy of it, which peaks near 300 MB of memory at start and hands it back afterwards. With a C compiler, CGO_ENABLED=1 go install -tags pgquery_cgo,netgo,osusergo github.com/a-lafon/postgres-dba-mcp/cmd/postgres-dba-mcp@latest builds the native one.

Check the install with postgres-dba-mcp --version. When the shell does not find it, ~/.local/bin is not on your PATH: add it, or register the server with the full path.

Quick start with Claude Code

Register the server with the database URI in its environment:

claude mcp add pg --env DATABASE_URI=postgres://pgdba_ro:secret@localhost:5432/pgdba -- postgres-dba-mcp

Or put it in .mcp.json:

{

"mcpServers": { "pg": { "command": "postgres-dba-mcp", "env": { "DATABASE_URI": "${DATABASE_URI}" } } } }

The URI can also be the first argument (postgres-dba-mcp postgres://...). When both are given, DATABASE_URI wins. The server starts without connecting: the first tool call opens the connection.

Connection options in the URI (sslmode, sslrootcert, connect_timeout, …) are honoured, and so is search_path, which is applied to every transaction rather than sent at connection time, because a transaction pooler refuses it there. A server setting such as timezone is reported as ignored for the same reason. A misspelled TLS option is refused at startup instead: left alone it would read as a server setting, and the connection would fall back to an unchecked certificate.

Through Docker, localhost inside the container is the container itself, and the image does not rewrite it. On Docker Desktop use host.docker.internal in the URI; on Linux use --network=host or the address of the host on the bridge network.

{

"mcpServers": { "pg": { "command": "docker", "args": ["run", "-i", "--rm", "-e", "DATABASE_URI", "ghcr.io/a-lafon/postgres-dba-mcp:latest"], "env": { "DATABASE_URI": "postgres://pgdba_ro:secret@host.docker.internal:5432/pgdba" } } } }

Quick start with Codex

Register the server with the database URI in its environment:

codex mcp add pg --env DATABASE_URI=postgres://pgdba_ro:secret@localhost:5432/pgdba -- postgres-dba-mcp

Or put it in ~/.codex/config.toml:

[mcp_servers.pg]

command = "postgres-dba-mcp" env = { DATABASE_URI = "postgres://pgdba_ro:secret@localhost:5432/pgdba" }

Codex stops waiting for a tool after tool_timeout_sec (60 s by default). If you raise --statement-timeout above that, raise tool_timeout_sec in the same entry too.

Several databases

One process serves one database. To use several, add one server entry per database. Each entry gets its own tools, so you can write permission rules per server. Use a read-only role everywhere, and --access-mode=unrestricted only where writes are intended.

{

"mcpServers": { "pg-prod": { "command": "postgres-dba-mcp", "env": { "DATABASE_URI": "${PROD_DATABASE_URI}" } }, "pg-staging": { "command": "postgres-dba-mcp", "args": ["--access-mode=unrestricted"], "env": { "DATABASE_URI": "${STAGING_DATABASE_URI}" } } } }

In Claude Code, permission rules name the server, so the two entries above can be treated differently. For example, in .claude/settings.json, allow every tool of pg-prod and ask before each execute_sql on pg-staging:

{

"permissions": { "allow": ["mcppg-prod"], "ask": ["mcppg-staging__execute_sql"] } }

Credentials outside the URI

You do not have to put the password in the URI or in .mcp.json. The driver (pgx) reads the standard libpq sources itself; this server adds no option for them.

A URI without a password, with the password read from ~/.pgpass (or the file named by PGPASSFILE) or from PGPASSWORD:

DATABASE_URI=postgres://pgdba_ro@db.example.com:5432/pgdba

A ~/.pgpass line has the form host:port:database:user:password, and the file must not be readable by others (chmod 600). PGPASSWORD=... postgres-dba-mcp works the same way.

A named service from pg_service.conf (or the file named by PGSERVICEFILE):

DATABASE_URI="service=prod"
[prod]

host=db.example.com port=5432 dbname=pgdba user=pgdba_ro sslmode=verify-full

The password never appears in the server's log: the startup line shows user@host:port/db only.

Read-only role

In restricted mode the server refuses writes, but the Postgres role is the real barrier. Give the server a role that can only read:

CREATE ROLE pgdba_ro LOGIN PASSWORD 'change-me';

GRANT pg_read_all_stats TO pgdba_ro; -- pg_stat_statements text and other sessions' statistics GRANT USAGE ON SCHEMA public TO pgdba_ro; GRANT SELECT ON ALL TABLES IN SCHEMA public TO pgdba_ro; ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO pgdba_ro; -- tables created later

Without pg_read_all_stats, analyze_locks still reports the pids, the locks and the chains, but the waits, states, transaction ages and query texts of other roles' sessions come back as \N and it says so in a -- session details hidden: grant pg_read_all_stats to … line. From PostgreSQL 15 on, a NOINHERIT member of pg_read_all_stats reads nothing either, and is reported the same way; PostgreSQL 14 grants it on membership alone. Either way the line appears only when the report really hides something.

Repeat the USAGE, SELECT and ALTER DEFAULT PRIVILEGES lines for every other schema

只显示了开头部分;其余内容请在仓库中阅读

问 PopNx