docs/reference/rules/running-statement-while-holding-access-exclusive.md
Diagnostic Category: lint/safety/runningStatementWhileHoldingAccessExclusive
Since: vnext
[!NOTE] This rule is recommended. A diagnostic error will appear when linting your code.
Sources:
Running additional statements while holding an ACCESS EXCLUSIVE lock blocks all table access.
When a transaction acquires an ACCESS EXCLUSIVE lock (e.g., via ALTER TABLE), it blocks all other operations on that table, including reads. Running additional statements in the same transaction extends the duration the lock is held, potentially blocking all database access to that table.
This is particularly problematic because:
To minimize blocking, run the ALTER TABLE in its own transaction and execute other operations in separate transactions.
ALTER TABLE authors ADD COLUMN email TEXT;
SELECT COUNT(*) FROM authors;
-- Run ALTER TABLE alone, other queries in separate transactions
ALTER TABLE authors ADD COLUMN email TEXT;
{
"linter": {
"rules": {
"safety": {
"runningStatementWhileHoldingAccessExclusive": "error"
}
}
}
}