当前位置: 首页 > Skill >

Postgres AIops

Postgres AIops

0.13.0 2026.11.14 浏览:283
获取Skill文件查看使用说明
作者:周言许可证:
本文目录展开

Postgres AIops

Disclaimer: Community-maintained open-source project, not affiliated with, endorsed by, or sponsored by the PostgreSQL Global Development Group or any vendor. "PostgreSQL" and related trademarks belong to their owners. Source at github.com/AIops-tools/Postgres-AIops under the MIT license.

Governed PostgreSQL DBA operations — 35 MCP tools, every one wrapped with the bundled @governed_tool harness: a local unified audit log under ~/.postgres-aiops/, token/runaway budget guard, undo-token recording, and descriptive risk-tier labels. The role password is stored encrypted (~/.postgres-aiops/secrets.enc, Fernet + scrypt) — never plaintext on disk.

Standalone: the governance harness is bundled in the package (postgres_aiops.governance) — postgres-aiops has no external skill-family dependency. Beyond the mock suite, the reads plus a governed write and its undo have been exercised against a live PostgreSQL 16.14 instance (see docs/VERIFICATION.md).

What This Skill Does

Domain Tools Count Read or Write
Overview cluster health snapshot 1 1 read
Server version, settings, extensions, databases, roles 5 5 read
Activity sessions, long-running queries, locks 3 3 read
Queries top-N (pg_stat_statements), EXPLAIN 2 2 read
Indexes unused, missing hints, bloat, invalid/duplicate 4 4 read
Tables sizes, dead-tuple bloat, autovacuum status 3 3 read
Replication status/lag, slots, WAL 3 3 read
Analysis (flagship) slow-query RCA, bloat/vacuum, blocking chains 3 3 read
Writes terminate, cancel, drop-index 3 3 write (high)
vacuum, analyze, create-index, reindex, ALTER SYSTEM, reset-stats 6 6 write (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.

Quick Install

uv tool install postgres-aiops
postgres-aiops init       # interactive wizard: connection + encrypted password
postgres-aiops doctor

When to Use This Skill

  • Triage a cluster (overview): version/uptime, connections by state, idle-in-transaction, longest query, worst bloat, replica lag
  • Root-cause a slow query (analyze slow-query / slow_query_rca): the worst pg_stat_statements entry + EXPLAIN → cited cause and action
  • Decide what to vacuum (analyze bloat-vacuum / bloat_and_vacuum_analysis): tables ranked by dead-tuple ratio + autovacuum lag
  • Untangle a lock pile-up (analyze blocking / blocking_lock_chain_rca): the wait-for tree with the root blocker named
  • Find unused / missing / bloated indexes; check autovacuum status and table sizes; inspect replication lag and slots
  • Terminate/cancel a backend, VACUUM/ANALYZE, create/drop an index (reversible), REINDEX, or ALTER SYSTEM SET — all with dry-run + double-confirm

Do NOT use when the target is OT/industrial equipment (use industrial-aiops), a hypervisor, a storage appliance, a backup product, a container cluster, or a non-PostgreSQL database.

Related Skills — Skill Routing

If the user wants… Use
PostgreSQL DBA-ops: slow queries, bloat, locks, index/vacuum maintenance postgres-aiops (this skill)
OT / industrial edge (Modbus, OPC-UA, PLC, PROFINET) the industrial-aiops line
Hypervisor VM lifecycle (power, snapshot, migrate) a hypervisor ops skill
Container/cluster lifecycle a cluster ops skill

Common Workflows

"The app got slow this afternoon" — root-cause and add the missing index

  1. postgres-aiops overview → one-shot cluster picture: connections, database sizes, obvious saturation
  2. postgres-aiops analyze slow-query → the worst pg_stat_statements entry with cited findings (seq scan, low cache-hit ratio, temp spill, high call count) and a concrete action for each
  3. postgres-aiops query explain "<sql>" → confirm the plan yourself; a Seq Scan on a large table is the index signal
  4. postgres-aiops index missing → the tool's own index hints, to cross-check that step 3's conclusion is not a one-off
  5. postgres-aiops remediate create-index <table> <col> --concurrently --dry-run → preview the exact DDL; then run without --dry-run (double confirmation). create_index is reversible — an inverse drop_index is recorded
  6. postgres-aiops query reset then re-run analyze slow-query after a while → confirm the query actually dropped out of the top, rather than assuming
  7. Failure branch: if the new index does not help, or --concurrently left an INVALID index (postgres-aiops index invalid), roll it back with postgres-aiops undo list → postgres-aiops undo apply <id>. An invalid index still costs writes — drop it rather than leaving it behind.

Reclaim table bloat and retire a redundant index (reversible)

  1. postgres-aiops analyze bloat-vacuum → tables ranked by dead-tuple ratio and autovacuum lag, each citing the measured numbers
  2. postgres-aiops table autovacuum → check whether autovacuum is simply behind (last run, thresholds) before doing it by hand
  3. postgres-aiops remediate vacuum <table> --analyze --dry-run → preview; then run for real to VACUUM ANALYZE (double confirmation)
  4. postgres-aiops index unused and postgres-aiops index bloat → find indexes that cost writes and return nothing
  5. postgres-aiops remediate drop-index <name> --concurrently --dry-run, then for real → the tool captures pg_get_indexdef before dropping and records an inverse recreate descriptor
  6. Failure branch: dropped the wrong index — postgres-aiops undo apply <id> recreates it from the captured definition (not a guess). Note --full on remediate vacuum takes an exclusive lock and rewrites the table; it has no undo, so never reach for it as a first response on a live table.

Break a blocking pile-up during an incident

  1. postgres-aiops analyze blocking → the wait-for chain, naming the root blocker pid rather than the visible victims
  2. postgres-aiops activity locks → the raw lock rows behind the chain; confirm the blocker is what the RCA says it is
  3. postgres-aiops activity long --min-seconds 60 → how long the blocker has actually been running, and whether it is idle-in-transaction
  4. postgres-aiops remediate cancel <pid> --dry-run → preview; then for real. Cancel before terminate — cancel ends the query, terminate kills the whole backend and rolls back its transaction
  5. Only if cancel does not clear it: postgres-aiops remediate terminate <pid> (double confirmation)
  6. Failure branch: both cancel_query and terminate_backend declare no undo — a killed session cannot be restored. The audit row in ~/.postgres-aiops/audit.db captures the prior query text and state for the incident write-up. If the same blocker reappears, the fix is upstream (application transaction scope), not another terminate.

Tune a parameter and prove it moved the needle (reversible)

  1. postgres-aiops server settings work_mem → the current value and where it came from
  2. postgres-aiops analyze slow-query → confirm a temp-spill finding is what actually motivates the change
  3. postgres-aiops remediate set work_mem 64MB --dry-run → preview the ALTER SYSTEM SET; then run for real (double confirmation) — the prior value is captured and an inverse update_setting is recorded
  4. Reload/restart per the parameter's context, then postgres-aiops server settings work_mem to confirm the value took effect
  5. Failure branch: if the change causes memory pressure, postgres-aiops undo apply <id> restores the prior value. ALTER SYSTEM only writes postgresql.auto.conf — a parameter with context = postmaster needs a restart, so a "successful" write that did not change behaviour usually means the restart is still pending, not that the tool failed.

Offline analysis (no live cluster)

  1. Export pg_stat_statements, table-bloat, and blocking-pair rows to JSON
  2. Feed them straight to the analysis tools — slow_query_rca(statements=[...]), bloat_and_vacuum_analysis(tables=[...]), blocking_lock_chain_rca(pairs=[...]) — no connection or credentials required
  3. Failure branch: a tool that rejects the injected rows means the export is missing the columns the analysis needs (calls/total_time/rows, dead-tuple counts, blocked/blocking pids) — re-export rather than hand-editing, so the findings stay traceable to the cluster.

Governance & Safety

The skill delivers reads and writes and records them; it does not decide whether a write is permitted. That is your 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) — writes then fail at the server). There is no read-only switch, policy file, or approval gate.

  • Audit is the guarantee, and it is not bypassable. Every operation — MCP and CLI alike — is logged to ~/.postgres-aiops/audit.db (relocatable via POSTGRES_AIOPS_HOME): params, result, status, duration, and the risk tier. The CLI writes the same row the MCP path does.
  • POSTGRES_AUDIT_APPROVED_BY / POSTGRES_AUDIT_RATIONALE are optional annotations recorded on the audit row (who/why); they are never required and never block.
  • Runaway guard — a safety backstop, not authorization: the same call looped in a tight window trips a circuit breaker. Disable with POSTGRES_RUNAWAY_MAX=0.
  • Writes support --dry-run / dry_run=True and double confirmation at the CLI.
  • Reversible writes fetch the real before-state and record an inverse descriptor; irreversible ops (terminate/cancel, vacuum/analyze, reindex, reset stats) record prior stats only.
  • All values are bound query parameters; identifiers that cannot be parameterised are validated and quoted.

References

  • references/capabilities.md — full tool + field reference
  • references/cli-reference.md — CLI command reference
  • references/setup-guide.md — onboarding, credentials, and connectivity

推荐文章

更多
PHP时间戳与日期字符串相互转换方法详解

本文介绍PHP中时间数值(Unix时间戳)与日期字符串之间的相互转换方法。通过strtotime和date函数,实现将当前时间、指定日期转换为时间戳,以及将时间戳格式化为可读的日期时间字符串,并提供相关在线计算工具推荐。

2025.11.30 1,033
PHP日期转时间戳时区偏差怎么解决

在 PHP 中将日期字符串转换为时间戳时,若未显式指定时区,默认使用脚本配置的 date.timezone 或系统时区。当服务器时区与业务逻辑预期(如 UTC )不一致时,会产生偏差。解决核心是确保输入字符串携带明确时区信息,或在转换前统一设置时区上下文。

2026.10.24 1,031
PHP跨域配置:怎么安全地允许指定域名而非使用通配符

在 PHP 中安全地允许指定域名跨域,核心是解析请求头中的 Origin ,验证其是否在白名单内,然后动态设置 Access-Control-Allow-Origin 响应头。不要使用通配符 * ,也不要硬编码单一域名。

2025.03.29 1,018
JavaScript中利用replace结合正则实现replaceAll效果

JavaScript原生仅支持replace()进行单次或全局替换,缺乏类似Java的replaceAll()便捷方法。本文总结四种在JS中实现全量替换的方案:使用带g标志的正则、带gm标志的正则、扩展String原型以及split后join。通过对比代码示例,展示各方法的实现细节与适用场景,帮助开发者根据需求选择最优解。

2025.04.29 1,016
OpenAI的Jalapeno芯片未落地,教你分辨300兆瓦算力消息

OpenAI计划在SB Energy租赁的数据中心部署约300兆瓦自研Jalapeno推理芯片,但目前双方仍处于洽谈阶段,交易细节与上线时间表均未公布。本文带你按报道原文核实项目所处阶段,厘清芯片发布、电力功率与实际推理算力的边界,并将融资意向与签约、开工、投运节点分开追踪,避免误将规划容量计入现有算力。

2026.12.02 1,012
PHP实现基础文件上传:HTML表单与$_FILES处理流程

在 HTML 表单中设置 enctype="multipart/form-data" ,并在 PHP 后端通过 $_FILES 数组接收文件,调用 move_uploaded_file() 将临时文件移动到目标目录即可完成上传。

2026.09.07 1,012
Skill 文件
  • SKILL.md
    • Postgres AIops
    • What This Skill Does
    • Quick Install
    • When to Use This Skill
    • Related Skills — Skill Routing
    • Common Workflows
      • "The app got slow this afternoon" — root-cause and add the missing index
      • Reclaim table bloat and retire a redundant index (reversible)
      • Break a blocking pile-up during an incident
      • Tune a parameter and prove it moved the needle (reversible)
      • Offline analysis (no live cluster)
    • Governance & Safety
    • References
  • 项目或源文件

相关 Skill

更多
Alibabacloud Rds Postgresql Inspection Alibabacloud Rds Postgresql Inspection 批量健康检查阿里云RDS PostgreSQL实例,生成包含资源使用、告警、慢日志、长事务和复制等信息的详细HTML报告。
Claimable Postgres Claimable Postgres 通过 Neon 的 Claimable Postgres (neon.new) 即时创建临时 Postgres 数据库,无需登录、注册或信用卡,支持 REST API、CLI 等方式。
postgresql-skill postgresql-skill 使用psycopg2执行PostgreSQL数据库操作,列出表、描述模式、执行SQL查询。
Add Postgres-native vector retrieval to agent and RAG workflows with pgvector Add Postgres-native vector retrieval to agent and RAG workflows with pgvector 将嵌入向量存储在 Postgres 中的应用数据旁边,创建向量索引,并查询最近邻以进行语义搜索、RAG、推荐或代理内存检索。
MySQL to PostgreSQL Migration MySQL to PostgreSQL Migration 在将项目数据库层从MySQL迁移到PostgreSQL时使用此技能。覆盖SQL方言转换(MyBatis XML/原始SQL)和ORM配置等...