aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/cluster.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2007-03-29 00:15:39 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2007-03-29 00:15:39 +0000
commitfba8113c1b74b9508cf2e6b7a18b0fb3637d9ba0 (patch)
treeb70081c09aa6f06b442f4f43313e738a693de7ea /src/backend/commands/cluster.c
parent4591fb1aa8c0f8c2d724c2a83e1a336650cca933 (diff)
downloadpostgresql-fba8113c1b74b9508cf2e6b7a18b0fb3637d9ba0.tar.gz
postgresql-fba8113c1b74b9508cf2e6b7a18b0fb3637d9ba0.zip
Teach CLUSTER to skip writing WAL if not needed (ie, not using archiving)
--- Simon. Also, code review and cleanup for the previous COPY-no-WAL patches --- Tom.
Diffstat (limited to 'src/backend/commands/cluster.c')
-rw-r--r--src/backend/commands/cluster.c20
1 files changed, 18 insertions, 2 deletions
diff --git a/src/backend/commands/cluster.c b/src/backend/commands/cluster.c
index aa911369409..ac771b77a60 100644
--- a/src/backend/commands/cluster.c
+++ b/src/backend/commands/cluster.c
@@ -11,7 +11,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/commands/cluster.c,v 1.157 2007/03/13 00:33:39 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/commands/cluster.c,v 1.158 2007/03/29 00:15:37 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -653,6 +653,8 @@ copy_heap_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex)
char *nulls;
IndexScanDesc scan;
HeapTuple tuple;
+ CommandId mycid = GetCurrentCommandId();
+ bool use_wal;
/*
* Open the relations we need.
@@ -676,6 +678,17 @@ copy_heap_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex)
memset(nulls, 'n', natts * sizeof(char));
/*
+ * We need to log the copied data in WAL iff WAL archiving is enabled AND
+ * it's not a temp rel. (Since we know the target relation is new and
+ * can't have any FSM data, we can always tell heap_insert to ignore FSM,
+ * even when using WAL.)
+ */
+ use_wal = XLogArchivingActive() && !NewHeap->rd_istemp;
+
+ /* use_wal off requires rd_targblock be initially invalid */
+ Assert(NewHeap->rd_targblock == InvalidBlockNumber);
+
+ /*
* Scan through the OldHeap on the OldIndex and copy each tuple into the
* NewHeap.
*/
@@ -722,7 +735,7 @@ copy_heap_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex)
if (NewHeap->rd_rel->relhasoids)
HeapTupleSetOid(copiedTuple, HeapTupleGetOid(tuple));
- simple_heap_insert(NewHeap, copiedTuple);
+ heap_insert(NewHeap, copiedTuple, mycid, use_wal, false);
heap_freetuple(copiedTuple);
@@ -734,6 +747,9 @@ copy_heap_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex)
pfree(values);
pfree(nulls);
+ if (!use_wal)
+ heap_sync(NewHeap);
+
index_close(OldIndex, NoLock);
heap_close(OldHeap, NoLock);
heap_close(NewHeap, NoLock);