Fix FK triggers losing DEFERRABLE/INITIALLY DEFERRED when marked ENFORCED again
Fujii Masao <fujii@postgresql.org>
Fix FK triggers losing DEFERRABLE/INITIALLY DEFERRED when marked ENFORCED again Previously, a foreign key defined as DEFERRABLE INITIALLY DEFERRED could behave as NOT DEFERRABLE after being set to NOT ENFORCED and then back to ENFORCED. This happened because recreating the FK triggers on re-enabling the constraint forgot to restore the tgdeferrable and tginitdeferred fields in pg_trigger. Fix this bug by properly setting those fields when the foreign key constraint is marked ENFORCED again and its triggers are recreated, so the original DEFERRABLE and INITIALLY DEFERRED properties are preserved. Backpatch to v18, where NOT ENFORCED foreign keys were introduced. Author: Yasuo Honda <yasuo.honda@gmail.com> Reviewed-by: Fujii Masao <masao.fujii@gmail.com> Discussion: https://postgr.es/m/CAKmOUTms2nkxEZDdcrsjq5P3b2L_PR266Hv8kW5pANwmVaRJJQ@mail.gmail.com Backpatch-through: 18
Files
| Path | Change | +/− |
|---|---|---|
| src/backend/commands/tablecmds.c | modified | +2 −0 |
| src/test/regress/expected/foreign_key.out | modified | +53 −0 |
| src/test/regress/sql/foreign_key.sql | modified | +37 −0 |
Discussion
- [PATCH] Fix unexpected loss of DEFERRABLE property after toggling NOT ENFORCED / ENFORCED 6 messages · 2026-02-27 → 2026-03-30