Governed AI-ops for PostgreSQL DBA operations: slow-query RCA, bloat/vacuum & blocking-lock analysis with a built-in governance harness (audit, budget, undo, risk tiers)
Project description
Postgres AIops (preview)
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, policy engine, token/runaway
budget guard, undo-token recording, and graduated-autonomy risk tiers.
Preview — mock-validated only, not run against a live cluster.
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): 33 tools (24 read, 9 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 (33 MCP tools)
| Domain | Tools | Count | R/W |
|---|---|---|---|
| Overview | overview |
1 | read |
| Server | server_version, show_settings, list_extensions, list_databases, list_roles |
5 | read |
| Activity | list_activity, long_running_queries, list_locks |
3 | read |
| Queries | top_queries, explain_query |
2 | read |
| Indexes | unused_indexes, missing_index_hints, index_bloat, invalid_indexes |
4 | read |
| Tables | table_sizes, table_bloat, autovacuum_status |
3 | read |
| Replication | replication_status, replication_slots, wal_status |
3 | read |
| Analysis (flagship) | slow_query_rca, bloat_and_vacuum_analysis, blocking_lock_chain_rca |
3 | read |
| Writes | terminate_backend, cancel_query, drop_index |
3 | write (high) |
run_vacuum, run_analyze, create_index, reindex, update_setting, reset_query_stats |
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 start
uv tool install postgres-aiops # or: pipx install postgres-aiops
postgres-aiops init # wizard: add a target + store the password (encrypted)
postgres-aiops doctor # verify config, secrets, connectivity
postgres-aiops overview # one-shot cluster health snapshot
postgres-aiops analyze slow-query # RCA the worst pg_stat_statements entry
postgres-aiops table bloat # dead-tuple bloat proxy per table
Run as an MCP server (stdio):
export POSTGRES_AIOPS_MASTER_PASSWORD=... # unlock secrets non-interactively
postgres-aiops-mcp
Governance
Every MCP tool passes through the bundled @governed_tool harness:
- Audit — every call (params, result, status, duration, risk tier, approver,
rationale) is logged to
~/.postgres-aiops/audit.db(relocatable viaPOSTGRES_AIOPS_HOME). - Budget / runaway guard — token and call budgets trip a circuit breaker.
- Risk tiers — graduated autonomy; high-risk ops can require a named approver
(
POSTGRES_AUDIT_APPROVED_BY/POSTGRES_AUDIT_RATIONALE— the env-var names the bundled harness reads). - Undo recording — reversible writes record an inverse descriptor built from the fetched before-state.
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
Preview — mock-validated only, not run against a live cluster. The catalog
queries are modelled from the documented pg_catalog / pg_stat_* shapes and
need live verification. postgres-aiops doctor is the fastest live check.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file postgres_aiops-0.1.0.tar.gz.
File metadata
- Download URL: postgres_aiops-0.1.0.tar.gz
- Upload date:
- Size: 145.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
86440d082400fd8af256c384a16816ee845cb88ae5e051d17a779e74aa5ccb8e
|
|
| MD5 |
f5668ce47c0e98996ab2acaf87116a39
|
|
| BLAKE2b-256 |
9f17250fe46c07cbadda32e2ebc6a6de0a5ff4a4b50b7b07173df97467b21a57
|
Provenance
The following attestation bundles were made for postgres_aiops-0.1.0.tar.gz:
Publisher:
publish.yml on AIops-tools/Postgres-AIops
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
postgres_aiops-0.1.0.tar.gz -
Subject digest:
86440d082400fd8af256c384a16816ee845cb88ae5e051d17a779e74aa5ccb8e - Sigstore transparency entry: 2160110952
- Sigstore integration time:
-
Permalink:
AIops-tools/Postgres-AIops@2a7cd07f6950363ee37fba6ab413ce0f63caeb58 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/AIops-tools
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@2a7cd07f6950363ee37fba6ab413ce0f63caeb58 -
Trigger Event:
release
-
Statement type:
File details
Details for the file postgres_aiops-0.1.0-py3-none-any.whl.
File metadata
- Download URL: postgres_aiops-0.1.0-py3-none-any.whl
- Upload date:
- Size: 92.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dab0090abe94d630152b718452d364850377b22b8472abe64597a4e1e9eee2ce
|
|
| MD5 |
60b1d80827f90324e66526e1c013a544
|
|
| BLAKE2b-256 |
357326df683da758517fa930bde94080bef0a0e056c4b5e9f8df449f740d37ed
|
Provenance
The following attestation bundles were made for postgres_aiops-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on AIops-tools/Postgres-AIops
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
postgres_aiops-0.1.0-py3-none-any.whl -
Subject digest:
dab0090abe94d630152b718452d364850377b22b8472abe64597a4e1e9eee2ce - Sigstore transparency entry: 2160111249
- Sigstore integration time:
-
Permalink:
AIops-tools/Postgres-AIops@2a7cd07f6950363ee37fba6ab413ce0f63caeb58 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/AIops-tools
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@2a7cd07f6950363ee37fba6ab413ce0f63caeb58 -
Trigger Event:
release
-
Statement type: