fix_copy_zero_blocks.v1.patch

application/octet-stream

Filename: fix_copy_zero_blocks.v1.patch
Type: application/octet-stream
Part: 1
Message: Re: WAL logging problem in 9.4.3?

Patch

Format: unified
Series: patch v1
File+
src/backend/commands/copy.c 8 1
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;
 	}