# AIops-tools/Postgres-AIops [Health: Active]

**Category:** 🗄️ Databases  
**Repository:** https://github.com/AIops-tools/Postgres-AIops  
**GitHub Stars:** 0  
**Views:** 4  
**Installs:** 0  
**Upvotes:** 0  
**Directory Page:** https://allmcps.com/mcp/aiops-tools-postgres-aiops

## Description
Governed PostgreSQL DBA operations — slow-query, bloat, and blocking-lock RCA, index management, vacuum/analyze, and replication lag (35 tools) with unbypassable audit logging (MCP + CLI), budget/runaway guards, dry-run, and undo/rollback.

## Claude Desktop Quick Installation
Install path detected from listing signals. Uses `uvx` (confidence: high):

```json
"mcpServers": {
  "postgres-aiops": {
    "command": "uvx",
    "args": ["postgres-aiops"],
    "env": {
      "POSTGRES_AIOPS_MASTER_PASSWORD": "",
      "POSTGRES_AIOPS_HOME": "",
      "POSTGRES_RUNAWAY_MAX": "",
      "POSTGRES_MAX_TOOL_CALLS": "",
      "POSTGRES_MAX_TOOL_SECONDS": ""
    }
  }
}
```

**Requires environment variables:** `POSTGRES_AIOPS_MASTER_PASSWORD`, `POSTGRES_AIOPS_HOME`, `POSTGRES_RUNAWAY_MAX`, `POSTGRES_MAX_TOOL_CALLS`, `POSTGRES_MAX_TOOL_SECONDS` — the values above are empty placeholders; fill in real credentials before running (see the repository for what each one is for).

## Documentation

## What AIops-tools/Postgres-AIops MCP server does

AIops-tools/Postgres-AIops MCP server connects to PostgreSQL through psycopg 3 and reads system catalogs plus `pg_stat_*` views. Its 35 tools include 25 read operations and 10 write or undo operations. Read coverage includes server metadata, databases, roles, extensions, sessions, locks, query activity, indexes, table size and bloat, autovacuum, replication, WAL, and query plans.

Three analysis tools turn database measurements into cited findings: `slow_query_rca` examines the worst `pg_stat_statements` entry and can include an `EXPLAIN` plan; `bloat_and_vacuum_analysis` ranks tables using dead-tuple ratios and autovacuum timing; and `blocking_lock_chain_rca` constructs a wait-for tree, identifies the root blocker, and flags cycles as possible deadlocks. The analyses can use live database data or injected records for offline testing.

## How it works

AIops-tools/Postgres-AIops MCP server runs over stdio using `postgres-aiops-mcp`, or through the `postgres-aiops mcp` command. Each call passes through a governance wrapper. The wrapper records parameters, result, status, duration, risk label, and optional operator rationale in `~/.postgres-aiops/audit.db`; `POSTGRES_AIOPS_HOME` can relocate that data. CLI calls use the same audit path, so the command-line interface does not bypass logging.

State-changing tools accept a dry-run request. CLI mutations also require two confirmations. Identifiers such as table, index, and configuration names are validated and quoted, while values use bound parameters. Reversible operations fetch the actual prior state and save an inverse description. For example, dropping an index stores its definition for recreation, and changing a setting records the previous value. Backend termination, query cancellation, vacuum, analyze, reindex, and query-statistics reset are recorded but do not provide an undo operation.

The runaway guard can trip a circuit breaker when the same call is repeated rapidly. Optional ceilings limit total tool calls or execution time. Risk levels are descriptive audit labels, not permission gates. PostgreSQL permissions remain the enforcement point; connecting with a read-only role makes writes fail at the database.

## Setup and configuration

Install the package with `uv tool install postgres-aiops` or `pipx install postgres-aiops`. Run `postgres-aiops init` to add a target and store its password in the encrypted `~/.postgres-aiops/secrets.enc` store, then use `postgres-aiops doctor` to check configuration, secrets, and connectivity. The password store uses Fernet and scrypt rather than plaintext files.

For noninteractive MCP or CI use, provide `POSTGRES_AIOPS_MASTER_PASSWORD`; the CLI can instead request the master password interactively. Start the stdio server with `postgres-aiops-mcp`. The exported password is visible to child processes and may enter shell history, so a short-lived secret injection or interactive prompt is safer on shared hosts.

The `top_queries` and `slow_query_rca` tools require the `pg_stat_statements` extension. The read role should have the `pg_monitor` privilege. This project targets PostgreSQL DBA operations and is not intended for industrial protocols, application-schema migrations, or ORM management.

_Full upstream README: https://allmcps.com/mcp/aiops-tools-postgres-aiops/readme_

