Diagnostic Queries
Symptoms
An ALTER TABLE could not proceed because the table has pending (deferred) trigger events from the current transaction. PostgreSQL raises SQLSTATE 55006 (object_in_use).
- Deferred constraint/trigger events are queued for the table.
- ALTER TABLE conflicts with those pending events.
- Common when altering inside a transaction that touched the table.
What the server log shows
ERROR: cannot ALTER TABLE "orders" because it has pending trigger events
Why PostgreSQL raises this — what the manual says
As the ALTER TABLE reference explains:
ALTER TABLE cannot run while the current transaction still has unfired (deferred) trigger events queued against the table, because the pending row changes would be invalidated by the schema change; those events must be resolved first.
Deferred triggers/constraints queue events to run at commit. Altering the table’s structure while such events are pending would leave them inconsistent, so PostgreSQL blocks the ALTER with 55006.
Common causes
- Deferred constraint checks queued earlier in the same transaction.
- Altering a table you just modified within an open transaction.
- AFTER triggers with deferred firing.
How to fix it
- Commit or roll back the current transaction first, then run ALTER TABLE.
- Run the ALTER in its own transaction before touching the table’s data.
- Use
SET CONSTRAINTS … IMMEDIATEto flush deferred checks before altering.
Related & next steps
Reference: PostgreSQL 18 — ALTER TABLE.
Thanks — noted. This helps keep the database accurate.