What Does This Tool Do?
pg_cnpg_dr_readiness calculates a weighted DR readiness score from 0 to 100 that measures the actual disaster recovery capability of a CNPG cluster. The tool queries the Kubernetes API for both primary and replica cluster status — across different kubecontexts — and evaluates five critical dimensions:
- Replica Health (30 points) — Are all replicas in the target cluster healthy and in
streamingstate? - WAL Archive Lag (20 points) — Is the last WAL archive less than 5 minutes old?
- Replication Lag (20 points) — Is replication lag under 10 MB?
- Object Store Accessible (15 points) — Is the configured object store (MinIO, S3) reachable?
- Instance Count (15 points) — Is at least one instance running in the DR cluster?
The result is a clear status: READY (score ≥ 80), AT-RISK (score 50–79), or NOT-READY (score < 50).
How Is It Called?
Configuration
DR tools are configuration-driven. Instead of a direct database connection, system and environment are read from the DR config — allowing multiple cluster pairs to be managed:
▶ Calling tools...
→ pg_cnpg_dr_readiness { "system": "hubport", "environment": "lab" }
// Reads primary + replica from ~/.config/mcp-postgres-enterprise/dr/cnpg-dr.json
// Primary: k8s-primary/mcp-test/mcp-test-cnpg (2 instances)
// Replica: k8s-replica/mcp-test/mcp-test-cnpg-replica (1 instance)
Claude CLI (Natural Language)
▶ Calling tools...
→ pg_cnpg_dr_readiness {"system": "hubport", "environment": "production"}
DR Readiness Score: 95/100 — Status: READY
Checks:
✓ Replica Health 30/30 — 1/1 replicas streaming
✓ WAL Archive Lag 20/20 — Last archive 2m 14s ago
✓ Replication Lag 15/20 — 4.2 MB (threshold: 10 MB)
✓ Object Store 15/15 — MinIO reachable
✓ Instance Count 15/15 — 1 instance active in DR cluster
MCP Protocol (Programmatic)
const result = await client.callTool("pg_cnpg_dr_readiness", {"system": "hubport"});
// Response:
{
"score": 95,
"status": "READY",
"checks": [
{
"name": "replica_health",
"weight": 30,
"score": 30,
"pass": true,
"detail": "1/1 replicas streaming"
},
{
"name": "wal_archive_lag",
"weight": 20,
"score": 20,
"pass": true,
"detail": "Last archive 2m 14s ago (< 5m threshold)"
},
{
"name": "replication_lag",
"weight": 20,
"score": 15,
"pass": true,
"detail": "4.2 MB lag (< 10 MB threshold)"
},
{
"name": "object_store",
"weight": 15,
"score": 15,
"pass": true,
"detail": "MinIO reachable at object-store:9000"
},
{
"name": "instance_count",
"weight": 15,
"score": 15,
"pass": true,
"detail": "1 instance running in DR cluster"
}
]
}
What Happens Under the Hood?
This tool executes no SQL. Instead, it uses the Kubernetes CustomObjectsApi to query CNPG cluster status from two different kubecontexts:
- Load DR config — Reads the master reference configuration (system + environment) to determine primary and replica cluster coordinates
- Query primary cluster —
kubectl get cluster/db-primary -n app -o jsonin contextk8s-primary - Query replica cluster —
kubectl get cluster/db-replica -n app -o jsonin contextk8s-replica - Check WAL archive — Reads
.status.lastSuccessfulArchivefrom the CNPG cluster object - Test object store — Verifies reachability of the configured S3/MinIO endpoint
The weighted formula allows partial scores: if replication lag is 4.2 MB (under the 10 MB threshold but not zero), it awards 15 out of 20 possible points instead of the full 20.
Pro Tip: A score of 80+ doesn't mean a DR failover will be painless — it means the technical prerequisites are met. Test actual failover regularly with pg_cnpg_switchover.
Lifecycle Gates
The tool respects the tenant lifecycle:
- provisioning — Read-only access (score is calculated but no actions taken)
- active — Full access, all checks active
- maintenance — Blocked unless override is set
- decommissioned — Fully blocked
Output in Detail
- score — Weighted total score from 0 to 100
- status —
READY(≥ 80),AT-RISK(50–79), orNOT-READY(< 50) - checks — Array with 5 entries, each containing:
- name — Check identifier (
replica_health,wal_archive_lag, etc.) - weight — Maximum points for this check
- score — Actual score achieved
- pass — Boolean indicating whether the check passed
- detail — Human-readable status text
- name — Check identifier (
What Does the Test Suite Validate?
The test suite validates pg_cnpg_dr_readiness against a lab environment with a primary cluster (2 instances) and a replica cluster (1 instance) on separate k3s clusters, with MinIO as WAL archive:
✓ pg_cnpg_dr_readiness > checks array has 5 items
✓ pg_cnpg_dr_readiness > READY when all checks pass
✓ pg_cnpg_dr_readiness > NOT-READY when replica missing
Test Files 1 passed (1)
Tests 4 passed (4)
Duration 1842ms
Test Data Scenario
The lab environment consists of:
- k8s-primary — k3s cluster with CNPG cluster
db-primary(2 instances: 1 primary + 1 replica) - k8s-replica — Separate k3s cluster with CNPG cluster
db-replica(1 instance, WAL replay) - MinIO — Object store for WAL archiving (S3-compatible, port 9000)
- Two kubecontexts — Simulates a real multi-cluster DR topology
Tests validate that:
- The result contains a
score(number) andstatus(string) - The
checksarray has exactly 5 entries (one per dimension) - With healthy clusters the status returns
READY - With a missing replica the status switches to
NOT-READY
Summary
pg_cnpg_dr_readiness is the central tool for DR monitoring in CNPG environments. It replaces manual kubectl checks across multiple clusters with a single weighted score that immediately shows whether a DR failover would be technically feasible.
Combined with pg_cnpg_switchover (→ actual failover) and pg_failover_readiness (→ replication status), it forms the core of the /pg-dr workflow skill.