=== Applying patches on top of PostgreSQL commit ID a1de1b0833b8e940f33fb2c7ab011e841a4d9063 === /etc/rc.d/jail: WARNING: Per-jail configuration via jail_* variables is obsolete. Please consider migrating to /etc/jail.conf. Thu May 29 03:55:20 UTC 2025 On branch cf/5774 nothing to commit, working tree clean === using 'git am' to apply patch ./v1-0001-Skip-FK-Validations-when-Role-is-Replica.patch === Patch format detection failed. === using patch(1) to apply patch ./v1-0001-Skip-FK-Validations-when-Role-is-Replica.patch === patching file src/backend/commands/tablecmds.c Hunk #1 succeeded at 2035 (offset 60 lines). Hunk #2 FAILED at 5924. 1 out of 2 hunks FAILED -- saving rejects to file src/backend/commands/tablecmds.c.rej patching file src/test/regress/expected/foreign_key.out Hunk #1 succeeded at 3355 with fuzz 1 (offset 282 lines). patching file src/test/regress/sql/foreign_key.sql Hunk #1 succeeded at 1208 (offset 57 lines). Hunk #2 succeeded at 2364 with fuzz 1 (offset 183 lines). Unstaged changes after reset: M src/backend/commands/tablecmds.c M src/test/regress/expected/foreign_key.out M src/test/regress/sql/foreign_key.sql Removing src/backend/commands/tablecmds.c.rej === using 'git apply' to apply patch ./v1-0001-Skip-FK-Validations-when-Role-is-Replica.patch === /work/patches/./v1-0001-Skip-FK-Validations-when-Role-is-Replica.patch:9: trailing whitespace. * /work/patches/./v1-0001-Skip-FK-Validations-when-Role-is-Replica.patch:32: trailing whitespace. * /work/patches/./v1-0001-Skip-FK-Validations-when-Role-is-Replica.patch:33: trailing whitespace. * Skip the check when `session_replication_mode = replica` to save time /work/patches/./v1-0001-Skip-FK-Validations-when-Role-is-Replica.patch:34: trailing whitespace. * and to match the FK trigger behaviour in the same situation /work/patches/./v1-0001-Skip-FK-Validations-when-Role-is-Replica.patch:169: trailing whitespace. -- Applied patch to 'src/backend/commands/tablecmds.c' with conflicts. Applied patch to 'src/test/regress/expected/foreign_key.out' cleanly. Applied patch to 'src/test/regress/sql/foreign_key.sql' cleanly. U src/backend/commands/tablecmds.c warning: squelched 1 whitespace error warning: 6 lines add whitespace errors. diff --cc src/backend/commands/tablecmds.c index 54ad38247aa,592a12fa95b..00000000000 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@@ -6044,50 -5924,55 +6050,62 @@@ ATRewriteTables(AlterTableStmt *parsetr * theoretically possible that we have changed both relations of the * foreign key, and we'd better have finished both rewrites before we try * to read the tables. + * + * Skip the check when `session_replication_mode = replica` to save time + * and to match the FK trigger behaviour in the same situation */ - foreach(ltab, *wqueue) + if (SessionReplicationRole != SESSION_REPLICATION_ROLE_REPLICA) { - AlteredTableInfo *tab = (AlteredTableInfo *) lfirst(ltab); - Relation rel = NULL; - ListCell *lcon; - - /* Relations without storage may be ignored here too */ - if (!RELKIND_HAS_STORAGE(tab->relkind)) - continue; - - foreach(lcon, tab->constraints) + foreach(ltab, *wqueue) { - NewConstraint *con = lfirst(lcon); + AlteredTableInfo *tab = (AlteredTableInfo *) lfirst(ltab); + Relation rel = NULL; + ListCell *lcon; - if (con->contype == CONSTR_FOREIGN) + /* Relations without storage may be ignored here too */ + if (!RELKIND_HAS_STORAGE(tab->relkind)) + continue; + + foreach(lcon, tab->constraints) { - Constraint *fkconstraint = (Constraint *) con->qual; - Relation refrel; + NewConstraint *con = lfirst(lcon); - if (rel == NULL) + if (con->contype == CONSTR_FOREIGN) { - /* Long since locked, no need for another */ - rel = table_open(tab->relid, NoLock); - } + Constraint *fkconstraint = (Constraint *) con->qual; + Relation refrel; - refrel = table_open(con->refrelid, RowShareLock); + if (rel == NULL) + { + /* Long since locked, no need for another */ + rel = table_open(tab->relid, NoLock); + } ++<<<<<<< ours + validateForeignKeyConstraint(fkconstraint->conname, rel, refrel, + con->refindid, + con->conid, + con->conwithperiod); ++======= + refrel = table_open(con->refrelid, RowShareLock); ++>>>>>>> theirs - /* - * No need to mark the constraint row as validated, we did - * that when we inserted the row earlier. - */ + validateForeignKeyConstraint(fkconstraint->conname, rel, refrel, + con->refindid, + con->conid); - table_close(refrel, NoLock); + /* + * No need to mark the constraint row as validated, we did + * that when we inserted the row earlier. + */ + + table_close(refrel, NoLock); + } } - } - if (rel) - table_close(rel, NoLock); + if (rel) + table_close(rel, NoLock); + } } /* Finally, run any afterStmts that were queued up */