aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/createas.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/commands/createas.c')
-rw-r--r--src/backend/commands/createas.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1f99b5ceec7..3d82edbf581 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -562,13 +562,16 @@ intorel_startup(DestReceiver *self, int operation, TupleDesc typeinfo)
myState->rel = intoRelationDesc;
myState->reladdr = intoRelationAddr;
myState->output_cid = GetCurrentCommandId(true);
- myState->hi_options = HEAP_INSERT_SKIP_FSM;
- myState->bistate = GetBulkInsertState();
/*
- * Valid smgr_targblock implies something already wrote to the relation.
- * This may be harmless, but this function hasn't planned for it.
+ * We can skip WAL-logging the insertions, unless PITR or streaming
+ * replication is in use. We can skip the FSM in any case.
*/
+ myState->hi_options = HEAP_INSERT_SKIP_FSM |
+ (XLogIsNeeded() ? 0 : HEAP_INSERT_SKIP_WAL);
+ myState->bistate = GetBulkInsertState();
+
+ /* Not using WAL requires smgr_targblock be initially invalid */
Assert(RelationGetTargetBlock(intoRelationDesc) == InvalidBlockNumber);
}
@@ -614,6 +617,10 @@ intorel_shutdown(DestReceiver *self)
FreeBulkInsertState(myState->bistate);
+ /* If we skipped using WAL, must heap_sync before commit */
+ if (myState->hi_options & HEAP_INSERT_SKIP_WAL)
+ heap_sync(myState->rel);
+
/* close rel, but keep lock until commit */
heap_close(myState->rel, NoLock);
myState->rel = NULL;