AI compatibility
AI can draft the refactor, but a DBA needs to own the business logic calls.
Workable, but read the conditions.
Average across 1 submission.
The honest read
AI can meaningfully assist with this refactoring work — reading PL/pgSQL, spotting deadlock-prone patterns like nested transactions, and generating inline comments — but the hardest parts require human judgment. Inferring undocumented business logic from opaque code written by a contractor is genuinely risky, and incorrect refactoring of production stored procedures can cause silent data corruption or outages. A skilled human DBA should own this, with AI as a capable assistant rather than the sole executor.
Aggregated across 1 submission.
The five dimensions
Repeatability
MediumThe mechanical parts — detecting nested transaction patterns, reformatting code, adding comment scaffolding — are structurally repeatable. But each procedure likely encodes unique business logic that requires fresh judgment to interpret correctly, making the task non-uniform across all 50+ procedures.
Ambiguity Tolerance
LowSuccess criteria are poorly defined: 'clarity' and 'business logic comments' are subjective, and correctness of the refactored logic cannot be verified without knowing the original intent. An agent cannot reliably know when it has gotten the business logic right versus plausibly wrong.
Data & Tool Availability
MediumThe agent can be given the raw SQL source files, which is sufficient for static analysis and pattern detection. However, it lacks access to runtime behavior, query plans, lock graphs, or the contractor's original intent — all of which are critical for diagnosing real deadlock causes.
Error Cost
HighIncorrectly refactored stored procedures in a production PostgreSQL database can cause data corruption, silent logic errors, or new deadlocks that are harder to trace. These errors may not surface immediately and can be difficult to reverse if the original procedures weren't versioned carefully.
Human Judgment Required
HighReconstructing business logic from undocumented code written by a third party is a high-judgment task — AI will frequently hallucinate plausible-sounding but incorrect intent. Deadlock resolution also requires understanding transaction semantics in the context of the full application, not just the procedure in isolation.
What an agent would need
- Full source code of all 50+ stored procedures as readable SQL/PL/pgSQL files
- Database schema (tables, indexes, foreign keys) to understand data relationships
- Access to deadlock logs or pg_locks output to identify actual contention patterns
- A code execution or review environment to validate refactored procedures before deployment
- A human DBA or domain expert to review and approve inferred business logic before any production changes
Best-matched agent type
The kind of agent this work would call for if it were a fit. For this task, it isn't.
Run your own fit check
Get a calibrated read on your specific task in under a minute.