diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml index e4a01699e4..aff56891e6 100644 *** a/doc/src/sgml/config.sgml --- b/doc/src/sgml/config.sgml *************** *** 6502,6508 **** COPY postgres_log FROM '/full/path/to/logfile.csv' WITH csv; Controls firing of replication-related triggers and rules for the ! current session. Setting this variable requires superuser privilege and results in discarding any previously cached query plans. Possible values are origin (the default), replica and local. --- 6502,6510 ---- Controls firing of replication-related triggers and rules for the ! current session. When set to replica it also ! disables all the foreign key checks, which can leave the data in an ! inconsistent state if improperly used. Setting this variable requires superuser privilege and results in discarding any previously cached query plans. Possible values are origin (the default), replica and local. diff --git a/src/backend/commanindex d979ce266d..296807849f 100644 *** a/src/backend/commands/tablecmds.c --- b/src/backend/commands/tablecmds.c *************** *** 1341,1356 **** ExecuteTruncate(TruncateStmt *stmt) } /* ! * Check foreign key references. In CASCADE mode, this should be ! * unnecessary since we just pulled in all the references; but as a ! * cross-check, do it anyway if in an Assert-enabled build. */ #ifdef USE_ASSERT_CHECKING - heap_truncate_check_FKs(rels, false); - #else - if (stmt->behavior == DROP_RESTRICT) heap_truncate_check_FKs(rels, false); #endif /* * If we are asked to restart sequences, find all the sequences, lock them --- 1341,1364 ---- } /* ! * Suppress foreign key references check if session replication role is ! * set to REPLICA. */ + if (SessionReplicationRole != SESSION_REPLICATION_ROLE_REPLICA) + { + + /* + * Check foreign key references. In CASCADE mode, this should be + * unnecessary since we just pulled in all the references; but as a + * cross-check, do it anyway if in an Assert-enabled build. + */ #ifdef USE_ASSERT_CHECKING heap_truncate_check_FKs(rels, false); + #else + if (stmt->behavior == DROP_RESTRICT) + heap_truncate_check_FKs(rels, false); #endif + } /* * If we are asked to restart sequences, find all the sequences, lock them