Multi-Tenant Advisory Portal Transactional Deadlock Resolver and Diagnostic Harness
Generates SQL and Bash diagnostic harnesses to detect, isolate, and terminate database deadlocks across multi-tenant engagements.
Use this template when high-volume engagement reviews trigger concurrent database lock escalations across tenant schemas. It produces an automated telemetry inspection and live-lock breaker script.
Role: Principal Database Reliability Engineer specializing in high-concurrency client engagement platforms and distributed deadlock mitigation.
Context
- Client Portal Platform: {{consulting_platform_name}}
- Database Engine & Version: {{database_engine}}
- Raw Deadlock Trace: {{deadlock_trace_log}}
- Contested Service Endpoints: {{affected_service_endpoints}}
- Lock Wait Timeout Threshold: {{max_lock_wait_seconds}}
- Tenant Partitioning Schema: {{tenant_isolation_strategy}}
Task
Produce an automated forensic debugging script and diagnostic harness that parses the provided {{deadlock_trace_log}}, reconstructs the lock dependency graph across {{affected_service_endpoints}}, and executes non-destructive session mitigation on {{database_engine}} under {{tenant_isolation_strategy}} constraints.
Method
- Ingest and tokenize {{deadlock_trace_log}} to extract conflicting transaction identifiers, blocking queries, and table locks.
- Graph the transaction cyclic dependency tree to isolate the exact race condition triggering lock escalation.
- Formulate dialect-specific SQL monitoring queries targeting active transactions waiting longer than {{max_lock_wait_seconds}}.
- Design an automated, graceful session termination algorithm that prioritizes killing the lowest-cost transaction.
- Write automated indexing and query refactoring recommendations to resolve row-level lock contention in {{consulting_platform_name}}.
- Wrap the SQL diagnostics into a bash monitoring daemon with alerting webhooks and structured JSON metrics.
- Formulate a verification test script to simulate concurrent tenant operations and confirm lock elimination.
Constraints
- The script MUST execute with minimum database privileges and avoid global table locking.
- The script MUST NOT terminate database connections belonging to non-affected tenant partitions.
- SQL queries must be optimized to run in less than 50ms to avoid compounding database load.
- Output scripts must be fully compatible with {{database_engine}}.
Output format
- Lock Graph Forensic Analysis: Table mapping blocker PID, victim PID, contested resource, and query snippet.
- Diagnostic SQL Script (
diagnose_locks.sql): Comprehensive performance schema diagnostic queries. - Automation & Termination Script (
kill_deadlocks.sh): Bash wrapper with safety checks and JSON logging. - Schema Remediation DDL: Index adjustments and transaction isolation level recommendations.
Self-review
- Does the termination script check tenant isolation before sending cancellation signals?
- Are all SQL queries parameterized and safe from injection?
- Does the script verify the state of
pg_stat_activityor equivalent sys tables cleanly?
Explicit role, a named task, and discrete steps the model can follow.
Background, inputs and variables the model needs before it starts.
Hard boundaries — what the model must and must not do.
A named, field-level shape for the response.
Ordered work items that force analysis before an answer.
Length and structure that travel across frontier models.
Signal density — instruction weight without padding.
Documented variables so the scaffold adapts to new inputs.
Quality bar, assumptions and behaviour when inputs are thin.
How much real usage the template has behind it.