
Postgres AIops
io.github.AIops-tools由 GitHub 账号 AIops-tools 发布v0.13.0更新于 Oct 30, 2026
Governed PostgreSQL DBA ops: slow-query RCA, bloat/vacuum & blocking-lock analysis; 35 MCP tools.
概览
受治理的 PostgreSQL DBA 运维 MCP 服务器:35 个工具,涵盖慢查询根因分析、膨胀/清理与锁链分析,以及带审计和撤销的维护写操作。
- 可以做什么
- 查看服务器、活动与查询:版本、设置、扩展、数据库、角色、会话、长事务查询、锁、高频查询与执行计划
- 分析索引与表:未使用、缺失、膨胀、失效索引,表大小、表膨胀与自动清理状态
- 执行旗舰根因分析:慢查询 RCA、膨胀与 vacuum 建议、阻塞锁链根阻塞者定位
- 检查复制:复制状态、复制槽与 WAL 状态
- 执行受控写操作:终止后端、取消查询、创建/删除索引、vacuum、analyze、reindex、修改设置、重置查询统计,均支持 dry-run 预览
- 查看并应用已记录的撤销条目,回滚可逆写操作
- 适用场景
- 适合让助手协助诊断 PostgreSQL 集群问题,如慢查询、表膨胀、vacuum 调优、阻塞锁与复制延迟,或执行日常 DBA 维护并留下审计记录。适合希望每次操作都被记录、可逆写操作可撤销的 DBA。
- 运行要求
- 本地 Python 包(postgres-aiops),通过 stdio 运行,可用 uv 或 pipx 安装。需用 init 向导配置目标并保存角色密码,通过 POSTGRES_AIOPS_MASTER_PASSWORD 或交互式提示解锁。查询分析需要 pg_stat_statements 扩展和具备 pg_monitor 权限的只读角色。需在 ~/.postgres-aiops 写入加密凭据库与审计数据库。
安装
在 SourceWeft 中
- 打开 控制台中的 Postgres AIops,将其添加到工作区。
- 为需要使用其工具的对话启用该服务。
Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。
其他 MCP 客户端
参照 仓库 中的启动说明。
README
Postgres AIops
Audit availability: Real writes require a committed
pendingaudit row and stop before contacting the platform if storage is unavailable. Reads and previews may continue with a warning; new audit rows store outcome summaries rather than full responses.
Disclaimer: Community-maintained open-source project. Not affiliated with, endorsed by, or sponsored by the PostgreSQL Global Development Group or any vendor. "PostgreSQL" and the elephant logo are trademarks of the PostgreSQL Community Association; all product/trademark names belong to their respective owners. MIT licensed.
Governed AI-ops for PostgreSQL DBA operations — connecting to a server with
psycopg 3 and reading the system catalogs and pg_stat_* views — with a
built-in governance harness: unified audit log, token/runaway
budget guard, undo-token recording, and descriptive risk-tier labels.
Beyond the mock test suite, the reads, a governed write, and its undo have been
exercised against a live PostgreSQL 16.14 instance — see docs/VERIFICATION.md.
What it does
Three flagship signature analyses, plus the guarded reads and writes around them:
- Slow-query RCA — take the worst
pg_stat_statementsentry (plus an optionalEXPLAINplan) and map its numbers — mean time, cache-hit ratio, temp spill, call count, plan node types — to a cited cause and a concrete action. Every finding carries its measured number, not a black-box verdict. - Bloat & vacuum analysis — combine per-table dead-tuple ratio and autovacuum recency into a ranked, cited recommendation (VACUUM / tune autovacuum).
- Blocking lock-chain RCA — build the wait-for tree from
pg_blocking_pids, name the root blocker (blocks others, waits on none), and give the action; a cycle is flagged as a likely deadlock.
What works
- CLI (
postgres-aiops ...):init,overview,server,activity,query,index,table,repl,analyze,remediate,secret,doctor,mcp. - MCP server (
postgres-aiops mcporpostgres-aiops-mcp): 35 tools (25 read, 10 write), every one wrapped with the bundled@governed_toolharness. - Encrypted credentials: the role password lives in an encrypted store
~/.postgres-aiops/secrets.enc(Fernet + scrypt) — never plaintext on disk. Unlock with a master password fromPOSTGRES_AIOPS_MASTER_PASSWORD(MCP/CI) or an interactive prompt (CLI). - Reversibility: mutating writes fetch the real before-state first and record a faithful inverse —
create_index↔drop_index;drop_indexcapturespg_get_indexdefso undo recreates it exactly;update_settingcaptures the prior value so undo sets it back. Irreversible ops (terminate_backend,cancel_query,run_vacuum,run_analyze,reindex,reset_query_stats) record prior stats for audit but declare no undo. - Safety: every state-changing CLI op supports
--dry-runand requires double confirmation; every write MCP tool takes adry_runpreview. All identifiers that cannot be parameterised (table/index/GUC names) are validated and quoted; all values are bound query parameters.
Capability matrix (35 MCP tools)
The flagship analyses accept injected records for pure/offline analysis, or pull
live from a configured target. top_queries/slow_query_rca require the
pg_stat_statements extension; the read role should have pg_monitor.
What this tool does, and does not, decide
It delivers PostgreSQL DBA operations — reads and writes — accurately and efficiently, and records every one of them. It does not decide whether a write is allowed to happen. That is the agent's judgement, or the permission of the account you connect it with: connect with a PostgreSQL role that has no write privileges (a read-only role, or one without INSERT/UPDATE/DELETE/DDL), and the writes fail at the server — the place that actually owns the permission.
So there is no read-only switch, no policy file, no approval gate to configure.
The one thing the tool guarantees is that nothing is silent: every call, over
MCP and over the CLI alike, lands an audit row in ~/.postgres-aiops/audit.db,
and destructive writes still capture their before-state and record an inverse
where one exists.
Each tool declares a
risk_level, carried into the audit row as a descriptive tier (none/confirm/review) — so a reviewer can see at a glance that a row was a high-risk delete. It is a label, not a gate.
Running a smaller / local model? See agent-guardrails.md — it lists the guardrails this tool now enforces for you (so you don't spend prompt budget restating them) and gives a ready-made system prompt for what's left.
Quick start
As a Claude Code plugin
One install gives an agent both the skill and the MCP server:
The MCP server is fetched with uv and pinned to the
package version this plugin declares, so an audit row can be traced back to the
code that wrote it. Credentials are still configured with postgres-aiops init — see below.
As an OpenClaw plugin
The same bundle is published on ClawHub, where one install delivers the skill and its MCP server together:
Restart the OpenClaw gateway afterwards so it loads the plugin. The MCP server is
fetched with uv, pinned to this exact release, so
uvx has to be on PATH — without it the skill still installs but reports
Visible to model: no. Credentials are configured exactly as below.
As a CLI or standalone MCP server
Run as an MCP server (stdio):
Where that password then lives: an exported variable is readable by every process this shell starts and is recorded by shell history. On a shared or long-lived host, prefer the interactive prompt, or inject it from a secret manager for the life of the one command that needs it.
Governance
Every MCP tool passes through the bundled @governed_tool harness:
- Audit — every call (params, outcome summary, status, duration, risk tier, and any
operator-supplied approver/rationale) is logged to
~/.postgres-aiops/audit.db(relocatable viaPOSTGRES_AIOPS_HOME). The CLI writes the same row the MCP path does — there is no unaudited entry point. - Runaway guard — a safety backstop, not an authorization gate: the same call
hammered in a tight loop trips a circuit breaker. Disable with
POSTGRES_RUNAWAY_MAX=0; optional hard ceilings viaPOSTGRES_MAX_TOOL_CALLS/POSTGRES_MAX_TOOL_SECONDS. - Undo recording — reversible writes record an inverse descriptor built from the fetched before-state.
- Risk tier — a descriptive label on the audit row derived from
risk_level; it gates nothing.
Scope
This is the PostgreSQL DBA-ops member of the AIops-tools family (governed
AI-ops with audit + budget + undo + risk tiers). Do NOT use it for OT /
industrial edge (Modbus, OPC-UA, PROFINET) — see the separate industrial-aiops
line — nor for application-schema migrations or ORM management.
Missing a capability?
Coverage is intentionally a curated subset of PostgreSQL's catalogs and maintenance surface. Missing a view, a metric, or a maintenance command? Open an issue or PR — contributions welcome.
Status
The mock test suite is complemented by a live run: the catalog / pg_stat_*
reads, the bloat_and_vacuum_analysis RCA, and the create_index / drop_index
governed write path (audit + undo, with drop_index capturing
pg_get_indexdef first) were exercised against a live PostgreSQL 16.14 instance running in
Docker. docs/VERIFICATION.md records exactly what was
and was not covered. postgres-aiops doctor is the fastest live check.
来源:README.md,提交 bc4deaf
工具
0版本历史
4- v0.13.0最新Oct 30, 2026
- v0.12.0Oct 15, 2026
- v0.11.0Oct 15, 2026
- v0.10.3Sep 16, 2026
评分
已满足适用检查项的 50%
该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。
- 近 30 天内可连通25 分
请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。
- 已声明认证方式10 分
请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。
- 已列出工具15 分
请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。
- 描述必需15 分
- 图标10 分
- 文档15 分
- 许可证10 分