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 */
(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.
* 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);
+ }
}
/* 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);
}
/* 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);