---
name: database-production-operations
description: Inspect, migrate, back up, restore, and troubleshoot production PostgreSQL, MariaDB/MySQL, Redis, Prisma, Drizzle, connection pools, schema drift, locks, slow queries, replication, and application database lifecycle. Use across Next.js, Node.js, .NET, hosting, mail, LDAP, invoicing, cloud-drive, and Coolify deployments. Prefer migration-based changes over unrestricted SQL.
compatibility: Read-only diagnostics and schema introspection are preferred. DDL, DML, migration execution, failover, restore, cache flush, user grants, and destructive operations require explicit authorization and a verified backup or rollback path.
license: Apache-2.0
---

# Database production operations

Treat the database as durable state with application-version, migration, backup and recovery dependencies.

## Diagnostic workflow

1. Identify engine, version, cluster or instance, database, schema, application and environment.
2. Confirm current health, connection saturation, storage, replication and backup status.
3. Inspect active sessions, locks, long transactions, slow queries and error patterns.
4. Relate symptoms to deployments, migrations, traffic changes and external dependencies.
5. Use bounded read-only queries and avoid returning sensitive rows.
6. Form a minimum-impact remediation plan.
7. Verify with the same metrics and application probes after action.

## Migration workflow

1. Compare repository migrations, ORM schema and live schema.
2. Determine forward and backward compatibility with currently running application versions.
3. Estimate table rewrite, lock duration, index build, disk growth and replication impact.
4. Split risky changes into expand, backfill, switch and contract phases.
5. Create and verify a backup or recovery point.
6. Run the migration in staging or against representative data.
7. Apply with timeouts, monitoring and a defined abort condition.
8. Re-read migration state and validate application behavior.

## ORM rules

- Prisma: distinguish `migrate deploy`, development push and destructive reset operations.
- Drizzle: review generated SQL and migration ordering before execution.
- Never use force-reset or schema push against production merely to resolve drift.
- Keep generated clients aligned with deployed schema and runtime version.

## Redis rules

Inspect memory, latency, evictions, persistence, replication and keyspace size. Do not run broad key scans or flush commands on production without explicit authorization. Session and rate-limit stores require application-aware recovery planning.

## Free SQL policy

The normal MCP router should not expose unrestricted write SQL. Prefer approved query templates, schema introspection, migration artifacts and purpose-built tools. A break-glass SQL interface must be short-lived, audited and separately credentialed.

## Output

Return engine and target identifiers, observed health, decisive queries, schema or migration drift, backup state, proposed phases, lock and data risk, capability gate, rollback or forward-fix plan, post-change verification and remaining operational risk.
