Skip to content

Commit 7f72fd8

Browse files
committed
When renaming a column that participates in a foreign key, we must
force relcache rebuild for the other table as well as the column's own table. Otherwise, already-cached foreign key triggers will stop working. Per example from Alexander Pravking.
1 parent 694b9ef commit 7f72fd8

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/backend/commands/tablecmds.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.119 2004/07/11 23:13:53 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.120 2004/07/17 17:28:29 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -1706,6 +1706,20 @@ update_ri_trigger_args(Oid relid,
17061706

17071707
CatalogUpdateIndexes(tgrel, tuple);
17081708

1709+
/*
1710+
* Invalidate trigger's relation's relcache entry so that other
1711+
* backends (and this one too!) are sent SI message to make them
1712+
* rebuild relcache entries. (Ideally this should happen
1713+
* automatically...)
1714+
*
1715+
* We can skip this for triggers on relid itself, since that
1716+
* relcache flush will happen anyway due to the table or column
1717+
* rename. We just need to catch the far ends of RI relationships.
1718+
*/
1719+
pg_trigger = (Form_pg_trigger) GETSTRUCT(tuple);
1720+
if (pg_trigger->tgrelid != relid)
1721+
CacheInvalidateRelcacheByRelid(pg_trigger->tgrelid);
1722+
17091723
/* free up our scratch memory */
17101724
pfree(newtgargs);
17111725
heap_freetuple(tuple);

0 commit comments

Comments
 (0)