diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c index 8904676..a91bd9a 100644 --- a/src/backend/commands/copy.c +++ b/src/backend/commands/copy.c @@ -2246,7 +2246,14 @@ CopyFrom(CopyState cstate) cstate->rel->rd_newRelfilenodeSubid != InvalidSubTransactionId) { hi_options |= HEAP_INSERT_SKIP_FSM; - if (!XLogIsNeeded()) + + /* + * We can skip writing WAL if there have been no actions that write an + * init block for any of the buffers we will touch during COPY. Since + * we have no way of knowing at present which ones that is, we must + * use a simple but effective heuristic to ensure safety in all cases. + */ + if (!XLogIsNeeded() && RelationGetNumberOfBlocks(cstate->rel->rd_node) == 0) hi_options |= HEAP_INSERT_SKIP_WAL; }