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.

已驗證STDIO僅桌面資料庫安全與監控

概覽

AI 產生的概覽

受治理的 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 寫入加密憑證庫與稽核資料庫。
安裝前請注意
包含 10 個會改變叢集狀態的寫入工具:終止後端、取消查詢、建立或刪除索引、vacuum/analyze/reindex、修改設定、重設查詢統計。沒有唯讀開關或審批關卡,風險等級僅為標籤,應以所連線角色的權限加以限制。主密碼環境變數可被其他行程與 shell 歷史讀取。每次呼叫都會寫入本機稽核資料庫。

安裝

在 SourceWeft 中

  1. 開啟 儀表板中的 Postgres AIops,將其新增到工作區。
  2. 為需要使用其工具的對話啟用該服務。

Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。

其他 MCP 客戶端

參照 儲存庫 中的啟動說明。

README

Postgres AIops

Audit availability: Real writes require a committed pending audit 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_statements entry (plus an optional EXPLAIN plan) 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 mcp or postgres-aiops-mcp): 35 tools (25 read, 10 write), every one wrapped with the bundled @governed_tool harness.
  • 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 from POSTGRES_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_index captures pg_get_indexdef so undo recreates it exactly; update_setting captures 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-run and requires double confirmation; every write MCP tool takes a dry_run preview. 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)

DomainToolsCountR/W
Overviewoverview1read
Serverserver_version, show_settings, list_extensions, list_databases, list_roles5read
Activitylist_activity, long_running_queries, list_locks3read
Queriestop_queries, explain_query2read
Indexesunused_indexes, missing_index_hints, index_bloat, invalid_indexes4read
Tablestable_sizes, table_bloat, autovacuum_status3read
Replicationreplication_status, replication_slots, wal_status3read
Analysis (flagship)slow_query_rca, bloat_and_vacuum_analysis, blocking_lock_chain_rca3read
Writesterminate_backend, cancel_query, drop_index3write (high)
run_vacuum, run_analyze, create_index, reindex, update_setting, reset_query_stats6write (medium)
Undoundo_list1read
undo_apply1write (medium)

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:

/plugin marketplace add AIops-tools/marketplace/plugin install postgres-aiops@aiops-tools

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:

bash
openclaw plugins install clawhub:@zw008/postgres-aiopsopenclaw skills info postgres-aiops          # expect: Visible to model: yes

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

bash
uv tool install postgres-aiops             # or: pipx install postgres-aiopspostgres-aiops init                        # wizard: add a target + store the password (encrypted)postgres-aiops doctor                      # verify config, secrets, connectivitypostgres-aiops overview                    # one-shot cluster health snapshotpostgres-aiops analyze slow-query          # RCA the worst pg_stat_statements entrypostgres-aiops table bloat                 # dead-tuple bloat proxy per table

Run as an MCP server (stdio):

bash
export POSTGRES_AIOPS_MASTER_PASSWORD=...  # unlock secrets non-interactivelypostgres-aiops-mcp

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 via POSTGRES_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 via POSTGRES_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
SourceWeft 曾在隔離沙箱中以無憑證方式啟動該軟體包一次,以列出其工具,但未能完成:伺服器未能啟動。

版本歷史

4
  1. v0.13.0最新Oct 30, 2026
  2. v0.12.0Oct 15, 2026
  3. v0.11.0Oct 15, 2026
  4. v0.10.3Sep 16, 2026

評分

已滿足適用檢查項的 50%

該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。

  • 近 30 天內可連通25 分

    請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。

  • 已宣告認證方式10 分

    請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。

  • 已列出工具15 分

    請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。

  • 描述必需15 分
  • 圖示10 分
  • 文件15 分
  • 授權條款10 分