Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 9de778b

Browse files
committed
Move the responsibility of writing a "unlogged WAL operation" record from
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.
1 parent 808969d commit 9de778b

File tree

5 files changed

+32
-11
lines changed

5 files changed

+32
-11
lines changed

src/backend/access/heap/heapam.c

+1-7
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/heap/heapam.c,v 1.284 2010/01/29 17:10:05 sriggs Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/heap/heapam.c,v 1.285 2010/02/03 10:01:29 heikki Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -5074,16 +5074,10 @@ heap2_desc(StringInfo buf, uint8 xl_info, char *rec)
50745074
void
50755075
heap_sync(Relation rel)
50765076
{
5077-
char reason[NAMEDATALEN + 30];
5078-
50795077
/* temp tables never need fsync */
50805078
if (rel->rd_istemp)
50815079
return;
50825080

5083-
snprintf(reason, sizeof(reason), "heap inserts on \"%s\"",
5084-
RelationGetRelationName(rel));
5085-
XLogReportUnloggedStatement(reason);
5086-
50875081
/* main heap */
50885082
FlushRelationBuffers(rel);
50895083
/* FlushRelationBuffers will have opened rd_smgr */

src/backend/access/heap/rewriteheap.c

+10-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
* Portions Copyright (c) 1994-5, Regents of the University of California
9797
*
9898
* IDENTIFICATION
99-
* $PostgreSQL: pgsql/src/backend/access/heap/rewriteheap.c,v 1.19 2010/01/02 16:57:35 momjian Exp $
99+
* $PostgreSQL: pgsql/src/backend/access/heap/rewriteheap.c,v 1.20 2010/02/03 10:01:29 heikki Exp $
100100
*
101101
*-------------------------------------------------------------------------
102102
*/
@@ -278,6 +278,15 @@ end_heap_rewrite(RewriteState state)
278278
(char *) state->rs_buffer, true);
279279
}
280280

281+
/* Write an XLOG UNLOGGED record if WAL-logging was skipped */
282+
if (!state->rs_use_wal && !state->rs_new_rel->rd_istemp)
283+
{
284+
char reason[NAMEDATALEN + 30];
285+
snprintf(reason, sizeof(reason), "heap rewrite on \"%s\"",
286+
RelationGetRelationName(state->rs_new_rel));
287+
XLogReportUnloggedStatement(reason);
288+
}
289+
281290
/*
282291
* If the rel isn't temp, must fsync before commit. We use heap_sync to
283292
* ensure that the toast table gets fsync'd too.

src/backend/commands/copy.c

+7-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/commands/copy.c,v 1.322 2010/01/31 18:15:39 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/commands/copy.c,v 1.323 2010/02/03 10:01:29 heikki Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -2225,7 +2225,13 @@ CopyFrom(CopyState cstate)
22252225
* indexes since those use WAL anyway)
22262226
*/
22272227
if (hi_options & HEAP_INSERT_SKIP_WAL)
2228+
{
2229+
char reason[NAMEDATALEN + 30];
2230+
snprintf(reason, sizeof(reason), "COPY FROM on \"%s\"",
2231+
RelationGetRelationName(cstate->rel));
2232+
XLogReportUnloggedStatement(reason);
22282233
heap_sync(cstate->rel);
2234+
}
22292235
}
22302236

22312237

src/backend/commands/tablecmds.c

+7-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.322 2010/02/03 01:14:16 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.323 2010/02/03 10:01:29 heikki Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -3297,7 +3297,13 @@ ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap)
32973297

32983298
/* If we skipped writing WAL, then we need to sync the heap. */
32993299
if (hi_options & HEAP_INSERT_SKIP_WAL)
3300+
{
3301+
char reason[NAMEDATALEN + 30];
3302+
snprintf(reason, sizeof(reason), "table rewrite on \"%s\"",
3303+
RelationGetRelationName(newrel));
3304+
XLogReportUnloggedStatement(reason);
33003305
heap_sync(newrel);
3306+
}
33013307

33023308
heap_close(newrel, NoLock);
33033309
}

src/backend/executor/execMain.c

+7-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
*
2727
*
2828
* IDENTIFICATION
29-
* $PostgreSQL: pgsql/src/backend/executor/execMain.c,v 1.343 2010/01/28 23:21:11 petere Exp $
29+
* $PostgreSQL: pgsql/src/backend/executor/execMain.c,v 1.344 2010/02/03 10:01:30 heikki Exp $
3030
*
3131
*-------------------------------------------------------------------------
3232
*/
@@ -2240,7 +2240,13 @@ CloseIntoRel(QueryDesc *queryDesc)
22402240

22412241
/* If we skipped using WAL, must heap_sync before commit */
22422242
if (myState->hi_options & HEAP_INSERT_SKIP_WAL)
2243+
{
2244+
char reason[NAMEDATALEN + 30];
2245+
snprintf(reason, sizeof(reason), "SELECT INTO on \"%s\"",
2246+
RelationGetRelationName(myState->rel));
2247+
XLogReportUnloggedStatement(reason);
22432248
heap_sync(myState->rel);
2249+
}
22442250

22452251
/* close rel, but keep lock until commit */
22462252
heap_close(myState->rel, NoLock);

0 commit comments

Comments
 (0)