DBA Checkup

v0.2.0
io.github.vickm26/dba-checkup-mcp Checked 1 day ago Published 1 day ago

Read-only PostgreSQL and Oracle health checks for AI assistants: fixed DBA checks, no free-form SQL.

Read-only health checks for PostgreSQL and Oracle Database, for AI assistants, over the Model Context Protocol. Point Claude (or any MCP client) at a database and ask *"is anything wrong with this database?"*. Instead of letting the model write SQL against production, this server gives it a fixed set of checks a DBA would run: blocking locks, long-running work and sessions idle inside a transaction, top statements, broken and missing indexes, maintenance problems, space, archiving and replication. Every check explains what it found in plain words, most serious first.

Summary extracted from the README.

dba-checkup-mcp

CI

Read-only health checks for PostgreSQL and Oracle Database, for AI assistants, over the Model Context Protocol.

Point Claude (or any MCP client) at a database and ask "is anything wrong with this database?". Instead of letting the model write SQL against production, this server gives it a fixed set of checks a DBA would run: blocking locks, long-running work and sessions idle inside a transaction, top statements, broken and missing indexes, maintenance problems, space, archiving and replication. Every check explains what it found in plain words, most serious first.

Built by a DBA with 20+ years of Oracle, SQL Server and PostgreSQL production support.

Why fixed checks instead of free-form SQL

  • Nothing can change. Every statement runs inside a read-only transaction with a timeout, through a login that can't write. Tests prove writes are refused, even through an admin login.
  • No surprise queries. The model picks from known checks; it never writes SQL against your database. The optional explain_query tool (PostgreSQL) only plans a single SELECT and is off unless you turn it on.
  • Customer data stays out of the chat. Statement text is masked by default: every string and number literal becomes ?, so WHERE email = 'ana@example.com' shows as WHERE email = ?.
  • Credentials never pass through the AI. The connection comes from the environment only.
  • Database text is treated as data. Results are fenced and labeled, and the server tells the model never to follow instructions that appear inside query text or application names.
  • Everything is audited. Each call is appended to a local JSONL log with timing and outcome.
  • Least privilege. PostgreSQL uses the built-in pg_monitor role; Oracle uses CREATE SESSION plus SELECT_CATALOG_ROLE. Neither can read your application tables. overview warns if you connect with a superuser or DBA-level login.

Oracle without the Diagnostics Pack

The Oracle checks read only v$ and dba_ views that come with every Oracle Database license. They never query AWR or ASH (DBA_HIST_*, V$ACTIVE_SESSION_HISTORY) or SQL Monitor, which need the extra-cost Diagnostics and Tuning Packs. It is built so that running it never uses a pack-licensed view. (Check your own license terms; this is not legal advice.)

The trade-off: it is a live check-up, not history. It sees what is happening now and what is still cached in the shared pool. For "what happened at 2 a.m. last Tuesday" you still need AWR (Diagnostics Pack) or Statspack.

It connects with node-oracledb in Thin mode, so no Oracle Client install is needed. It is tested on Oracle AI Database 26ai Free (release 23.26) and written for 19c and later.

Tools

The same tools for both databases; each one runs the checks that make sense for its engine.

Tool PostgreSQL Oracle
health_report Runs every check and lists what needs attention, most serious first. Start here. Same.
overview Version, uptime, connections vs max_connections, cache hit ratio, database sizes, login safety. Version, role and open mode, uptime, sessions and processes vs their limits, buffer cache hit ratio, login safety.
active_sessions Work running now; long statements; sessions idle inside an open transaction. The same, from v$session and v$transaction.
blocking_locks Who blocks whom, how long, and the root blockers (pg_blocking_pids). The same across RAC instances (gv$session.blocking_session).
top_queries Statements using the most time (pg_stat_statements). Statements using the most elapsed time in the shared pool (v$sqlarea).
storage Largest tables and materialized views, with index size. Tablespace fullness against max size (counting autoextend), largest segments.
index_health Invalid indexes, unused indexes, big tables read by full scans. UNUSABLE indexes and partitions, big tables read by full scans in cached plans.
maintenance Autovacuum, dead rows, last vacuum/analyze, transaction ID wraparound age. Auto statistics job, stale or missing optimizer statistics, invalid objects.
replication_backup WAL archiving failures, replica lag, slots holding back WAL. ARCHIVELOG mode, archive destination errors, fast recovery area, Data Guard lag, last RMAN backup.
explain_query (off by default) The plan for one SELECT, without running it. Not offered: EXPLAIN PLAN writes to PLAN_TABLE, and this tool never writes.

Quick start

1. Create a monitoring login

PostgreSQL, as a superuser (sql/create_monitor_role.postgres.sql):

CREATE ROLE dba_checkup LOGIN PASSWORD 'choose-a-strong-password';
GRANT pg_monitor TO dba_checkup;
GRANT CONNECT ON DATABASE your_database TO dba_checkup;

Oracle, as a DBA in the database or PDB you want checked (sql/create_monitor_role.oracle.sql):

CREATE USER dba_checkup IDENTIFIED BY "choose-a-strong-password";
GRANT CREATE SESSION, SELECT_CATALOG_ROLE TO dba_checkup;

2. Add it to your MCP client

Claude Desktop (claude_desktop_config.json):

{
  "mcpServers": {
    "dba-checkup": {
      "command": "npx",
      "args": ["-y", "dba-checkup-mcp"],
      "env": { "DBA_CHECKUP_DATABASE_URL": "oracle://dba_checkup:PASSWORD@dbhost:1521/ORCLPDB1" }
    }
  }
}

For PostgreSQL use postgres://dba_checkup:PASSWORD@host:5432/your_database.

Claude Code:

claude mcp add dba-checkup -e DBA_CHECKUP_DATABASE_URL=oracle://dba_checkup:PASSWORD@dbhost:1521/ORCLPDB1 -- npx -y dba-checkup-mcp

For Oracle connections that need a TNS alias or a full connect descriptor, set DBA_CHECKUP_ORACLE_CONNECT_STRING, DBA_CHECKUP_ORACLE_USER and DBA_CHECKUP_ORACLE_PASSWORD instead of the URL.

3. Ask

"Run a health report on this database and tell me what to fix first."

It also works without an AI, for cron, Nagios or a quick look:

DBA_CHECKUP_DATABASE_URL=oracle://... npx -y dba-checkup-mcp --report

Exit codes follow the Nagios plugin convention: 0 healthy, 1 warnings, 2 critical, 3 when a check could not run.

Settings

Variable Default Meaning
DBA_CHECKUP_DATABASE_URL (required) postgres://... or oracle://user:password@host:port/service. For PostgreSQL the standard PG* variables also work.
DBA_CHECKUP_ORACLE_CONNECT_STRING Oracle TNS alias or connect descriptor, with DBA_CHECKUP_ORACLE_USER and DBA_CHECKUP_ORACLE_PASSWORD.
DBA_CHECKUP_QUERY_TEXT masked masked, full or off: how much statement text to show.
DBA_CHECKUP_ALLOW_EXPLAIN off 1 registers explain_query (PostgreSQL). Planning needs SELECT on the tables involved; grant it only where you want it.
DBA_CHECKUP_MAX_ROWS 25 Rows per check (max 200).
DBA_CHECKUP_TIMEOUT_MS 10000 Statement timeout (Oracle: per round trip).
DBA_CHECKUP_AUDIT_LOG ~/.dba-checkup-mcp/audit.jsonl Audit file, or off.
DBA_CHECKUP_LONG_QUERY_SECONDS 300 Warning threshold for a running statement (..._VERY_LONG_... = 1800 for critical).
DBA_CHECKUP_IDLE_IN_TX_SECONDS 300 Warning threshold for sessions idle inside an open transaction.
DBA_CHECKUP_CONNECTIONS_WARN_PCT / _CRITICAL_PCT 80 / 95 Connection use (Oracle: sessions and processes limits).
DBA_CHECKUP_SPACE_WARN_PCT / _CRITICAL_PCT 85 / 95 Oracle tablespace and fast recovery area use.
DBA_CHECKUP_XID_AGE_WARN / _CRITICAL 1.0 / 1.5 billion PostgreSQL transaction ID age.

What it does not see

  • PostgreSQL: free disk space, and backups taken by external tools (pgBackRest, Barman, snapshots), are not visible from SQL.
  • Oracle: history (AWR, ASH), backups taken outside RMAN, and the disk or ASM space under autoextending datafiles. On Autonomous Database, Oracle manages archiving and backups and hides those views; the report lists what it could not see instead of guessing.

Roadmap

  • SQL Server.
  • Oracle: plans for statements already in the shared pool (DBMS_XPLAN.DISPLAY_CURSOR), which is read-only.

Development

npm install
npm run build
TEST_DATABASE_URL=postgres://postgres:postgres@localhost:5432/postgres npm test
ORACLE_TEST_URL=oracle://system:PASSWORD@localhost:1521/FREEPDB1 npm test

The tests build databases with real problems and check that each one is found: a blocked session, a long-running statement, an idle transaction, an invalid or unusable index, a table read by full scans, dead rows or stale statistics, an invalid view. They also check that literals are masked and that writes are refused. CI runs PostgreSQL 16 and 17 on Node 20, 22 and 24, and Oracle AI Database 26ai Free on Node 20 and 24.

License

MIT