Move the responsibility of writing a "unlogged WAL operation" record from
authorHeikki Linnakangas <[email protected]>
Wed, 3 Feb 2010 10:01:30 +0000 (10:01 +0000)
committerHeikki Linnakangas <[email protected]>
Wed, 3 Feb 2010 10:01:30 +0000 (10:01 +0000)
heap_sync() to the callers, because heap_sync() is sometimes called even
if the operation itself is WAL-logged. This eliminates the bogus unlogged
records from CLUSTER that Simon Riggs reported, patch by Fujii Masao.

src/backend/access/heap/heapam.c
src/backend/access/heap/rewriteheap.c
src/backend/commands/copy.c
src/backend/commands/tablecmds.c
src/backend/executor/execMain.c

index 37d1077f493c1e014ac664bf8a23533b4bc862c7..d09a1fc2648ac81f969b26b1072cc22e3c2fefdd 100644 (file)
@@ -5074,16 +5074,10 @@ heap2_desc(StringInfo buf, uint8 xl_info, char *rec)
 void
 heap_sync(Relation rel)
 {
-   char reason[NAMEDATALEN + 30];
-
    /* temp tables never need fsync */
    if (rel->rd_istemp)
        return;
 
-   snprintf(reason, sizeof(reason), "heap inserts on \"%s\"",
-            RelationGetRelationName(rel));
-   XLogReportUnloggedStatement(reason);
-
    /* main heap */
    FlushRelationBuffers(rel);
    /* FlushRelationBuffers will have opened rd_smgr */
index 99235dae4a5516670338eb4aacb81270da4b595d..25273b0986e96d501d81a6b5b6487be99ed47c28 100644 (file)
@@ -278,6 +278,15 @@ end_heap_rewrite(RewriteState state)
                   (char *) state->rs_buffer, true);
    }
 
+   /* Write an XLOG UNLOGGED record if WAL-logging was skipped */
+   if (!state->rs_use_wal && !state->rs_new_rel->rd_istemp)
+   {
+       char reason[NAMEDATALEN + 30];
+       snprintf(reason, sizeof(reason), "heap rewrite on \"%s\"",
+                RelationGetRelationName(state->rs_new_rel));
+       XLogReportUnloggedStatement(reason);
+   }
+
    /*
     * If the rel isn't temp, must fsync before commit.  We use heap_sync to
     * ensure that the toast table gets fsync'd too.
index 8923610ee9e4cf063dca11fd7b6e3da24f1c9d40..05760a9b2fe5d9bcca138628b0c3aba02a90f546 100644 (file)
@@ -2225,7 +2225,13 @@ CopyFrom(CopyState cstate)
     * indexes since those use WAL anyway)
     */
    if (hi_options & HEAP_INSERT_SKIP_WAL)
+   {
+       char reason[NAMEDATALEN + 30];
+       snprintf(reason, sizeof(reason), "COPY FROM on \"%s\"",
+                RelationGetRelationName(cstate->rel));
+       XLogReportUnloggedStatement(reason);
        heap_sync(cstate->rel);
+   }
 }
 
 
index 37a985adb1220add61baec0aec12cced23c053e0..0d1df7b957ec48231b4b7bb521f8744dd293c875 100644 (file)
@@ -3297,7 +3297,13 @@ ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap)
 
        /* If we skipped writing WAL, then we need to sync the heap. */
        if (hi_options & HEAP_INSERT_SKIP_WAL)
+       {
+           char reason[NAMEDATALEN + 30];
+           snprintf(reason, sizeof(reason), "table rewrite on \"%s\"",
+                    RelationGetRelationName(newrel));
+           XLogReportUnloggedStatement(reason);
            heap_sync(newrel);
+       }
 
        heap_close(newrel, NoLock);
    }
index 5eeb1327a63f17f9a87cfd07d40fd9a32ac20dc4..ad2bac3e0419a73bc9b113161795cff930572a79 100644 (file)
@@ -2240,7 +2240,13 @@ CloseIntoRel(QueryDesc *queryDesc)
 
        /* If we skipped using WAL, must heap_sync before commit */
        if (myState->hi_options & HEAP_INSERT_SKIP_WAL)
+       {
+           char reason[NAMEDATALEN + 30];
+           snprintf(reason, sizeof(reason), "SELECT INTO on \"%s\"",
+                    RelationGetRelationName(myState->rel));
+           XLogReportUnloggedStatement(reason);
            heap_sync(myState->rel);
+       }
 
        /* close rel, but keep lock until commit */
        heap_close(myState->rel, NoLock);