Transaction & Policy Checks
Beyond DDL, pgfence enforces operational best practices that prevent silent production incidents.
Transaction Checks
| # | Pattern | Severity |
|---|---|---|
| 25 | NOT VALID + VALIDATE CONSTRAINT in the same transaction | error |
| 26 | Multiple ACCESS EXCLUSIVE statements compounding | warning |
| 27 | CREATE INDEX CONCURRENTLY inside a transaction | error |
| 28 | Bulk UPDATE without WHERE in migration | warning |
| 29 | Wide lock window: ACCESS EXCLUSIVE on multiple tables in same transaction | warning |
Policy Checks
- Missing
SET lock_timeout: prevents lock queue death spirals - Missing
SET statement_timeout: forces the server to abort statements that run past the threshold instead of holding locks indefinitely - Missing
SET application_name: enablespg_stat_activityvisibility - Missing
SET idle_in_transaction_session_timeout: prevents orphaned locks lock_timeoutset after dangerous DDL: ordering violation, timeout must be set before any statement that acquires a dangerous locklock_timeout/statement_timeoutvalue exceeds threshold: warns when timeout values are too permissive (defaults: lock_timeout > 5s, statement_timeout > 10min)
Inline Ignore
Suppress a specific check on a statement with a comment directive:
sql
-- pgfence-ignore: add-column-not-null-no-default
ALTER TABLE users ADD COLUMN status TEXT NOT NULL;
-- pgfence-ignore
DROP TABLE legacy_sessions; -- suppress all checks See Configuration → Inline Ignore for the full syntax reference, including a reason and an expiry date on each ignore and -- pgfence-ignore-file for a whole file.
Rule reference
Every finding links here by rule id. There are 15 rules on this page.
| Rule | Title | Description |
|---|---|---|
concurrent-in-transaction | CONCURRENTLY inside a transaction | CREATE INDEX CONCURRENTLY and similar commands fail inside a transaction block. Run them outside a transaction. |
lock-timeout-after-dangerous-statement | lock_timeout set after a dangerous statement | The timeout must be set before any statement that acquires a dangerous lock, or it does not protect that statement. |
lock-timeout-too-long | lock_timeout above the configured maximum | A long lock_timeout lets a blocked migration hold up every query queued behind it. |
lock-timeout-zero | lock_timeout set to 0 | A lock_timeout of 0 disables the timeout. |
missing-application-name | Missing SET application_name | Setting application_name makes migration sessions identifiable in pg_stat_activity. |
missing-idle-timeout | Missing SET idle_in_transaction_session_timeout | Without it, a stalled migration session can hold locks indefinitely. |
missing-lock-timeout | Missing SET lock_timeout | Without a lock_timeout a migration can queue behind a long transaction and block all traffic to the table behind it. |
missing-statement-timeout | Missing SET statement_timeout | Without a statement_timeout a long operation can hold its locks indefinitely. |
non-transactional-in-transaction | Command that cannot run inside a transaction | VACUUM, ALTER SYSTEM, CREATE or DROP DATABASE and TABLESPACE, database-wide CLUSTER and REINDEX SCHEMA, DATABASE or SYSTEM fail inside a transaction block. Run them outside the migration transaction. |
not-valid-validate-same-tx | NOT VALID and VALIDATE CONSTRAINT in one transaction | Validating in the same transaction that added the constraint keeps the strong lock for the whole scan and defeats the purpose of NOT VALID. |
statement-after-access-exclusive | Statement after ACCESS EXCLUSIVE in the same transaction | Every further statement in the transaction runs while the ACCESS EXCLUSIVE lock is still held, which lengthens the window in which reads and writes are blocked. |
statement-timeout-too-long | statement_timeout above the configured maximum | A long statement_timeout lets a runaway statement hold its locks for a long time. |
unclosed-transaction | Transaction left open | A BEGIN without a matching COMMIT or ROLLBACK leaves the transaction open at the end of the migration file. |
update-in-migration | Bulk UPDATE in a migration | A large UPDATE holds row locks for the whole transaction. Backfill out of band, in batches. |
wide-lock-window | ACCESS EXCLUSIVE locks on several tables in one transaction | Locks are held until commit, so every table locked earlier stays blocked while later statements run. |