Skip to content

Commit 18724af

Browse files
committed
Remove unnecessary smgrimmedsync() when creating unlogged table.
This became safe after commit 4b4798e. The smgrcreate() call will now register the segment for syncing at the next checkpoint, so we don't need to sync it here. If a checkpoint happens before the creation is WAL-logged, the records will be replayed when starting recovery from the checkpoint. If a checkpoint happens after the WAL logging, the checkpoint will fsync() it. In the passing, clarify a comment in smgrDoPendingSyncs(). Discussion: https://www.postgresql.org/message-id/6e5bbc08-cdfc-b2b3-9e23-1a914b9850a9%40iki.fi Reviewed-by: Robert Haas
1 parent b0ec61c commit 18724af

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

src/backend/access/heap/heapam_handler.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -606,12 +606,9 @@ heapam_relation_set_new_filelocator(Relation rel,
606606

607607
/*
608608
* If required, set up an init fork for an unlogged table so that it can
609-
* be correctly reinitialized on restart. An immediate sync is required
610-
* even if the page has been logged, because the write did not go through
611-
* shared_buffers and therefore a concurrent checkpoint may have moved the
612-
* redo pointer past our xlog record. Recovery may as well remove it
613-
* while replaying, for example, XLOG_DBASE_CREATE* or XLOG_TBLSPC_CREATE
614-
* record. Therefore, logging is necessary even if wal_level=minimal.
609+
* be correctly reinitialized on restart. Recovery may remove it while
610+
* replaying, for example, an XLOG_DBASE_CREATE* or XLOG_TBLSPC_CREATE
611+
* record. Therefore, logging is necessary even if wal_level=minimal.
615612
*/
616613
if (persistence == RELPERSISTENCE_UNLOGGED)
617614
{
@@ -620,7 +617,6 @@ heapam_relation_set_new_filelocator(Relation rel,
620617
rel->rd_rel->relkind == RELKIND_TOASTVALUE);
621618
smgrcreate(srel, INIT_FORKNUM, false);
622619
log_smgrcreate(newrlocator, INIT_FORKNUM);
623-
smgrimmedsync(srel, INIT_FORKNUM);
624620
}
625621

626622
smgrclose(srel);

src/backend/catalog/storage.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,7 @@ smgrDoPendingSyncs(bool isCommit, bool isParallelWorker)
764764
/*
765765
* We emit newpage WAL records for smaller relations.
766766
*
767-
* Small WAL records have a chance to be emitted along with other
767+
* Small WAL records have a chance to be flushed along with other
768768
* backends' WAL records. We emit WAL records instead of syncing for
769769
* files that are smaller than a certain threshold, expecting faster
770770
* commit. The threshold is defined by the GUC wal_skip_threshold.

0 commit comments

Comments
 (0)