Remove unnecessary smgrimmedsync() when creating unlogged table.
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>
Fri, 15 Sep 2023 14:29:37 +0000 (17:29 +0300)
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>
Fri, 15 Sep 2023 14:29:37 +0000 (17:29 +0300)
This became safe after commit 4b4798e138. 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
src/backend/access/heap/heapam_handler.c
src/backend/catalog/storage.c

index 5a17112c91ea5c1e3f0b0d76a15dc74acb90b83b..7c28dafb7288a7f04989d12603d498a1abc01198 100644 (file)
@@ -606,12 +606,9 @@ heapam_relation_set_new_filelocator(Relation rel,
 
        /*
         * If required, set up an init fork for an unlogged table so that it can
-        * be correctly reinitialized on restart.  An immediate sync is required
-        * even if the page has been logged, because the write did not go through
-        * shared_buffers and therefore a concurrent checkpoint may have moved the
-        * redo pointer past our xlog record.  Recovery may as well remove it
-        * while replaying, for example, XLOG_DBASE_CREATE* or XLOG_TBLSPC_CREATE
-        * record. Therefore, logging is necessary even if wal_level=minimal.
+        * be correctly reinitialized on restart.  Recovery may remove it while
+        * replaying, for example, an XLOG_DBASE_CREATE* or XLOG_TBLSPC_CREATE
+        * record.  Therefore, logging is necessary even if wal_level=minimal.
         */
        if (persistence == RELPERSISTENCE_UNLOGGED)
        {
@@ -620,7 +617,6 @@ heapam_relation_set_new_filelocator(Relation rel,
                           rel->rd_rel->relkind == RELKIND_TOASTVALUE);
                smgrcreate(srel, INIT_FORKNUM, false);
                log_smgrcreate(newrlocator, INIT_FORKNUM);
-               smgrimmedsync(srel, INIT_FORKNUM);
        }
 
        smgrclose(srel);
index 2add0534891ba515954b916d9cf18a36f44f437e..93f07e49b722f8d0ee46c4f1cd8b6104ebc62dc9 100644 (file)
@@ -764,7 +764,7 @@ smgrDoPendingSyncs(bool isCommit, bool isParallelWorker)
                /*
                 * We emit newpage WAL records for smaller relations.
                 *
-                * Small WAL records have a chance to be emitted along with other
+                * Small WAL records have a chance to be flushed along with other
                 * backends' WAL records.  We emit WAL records instead of syncing for
                 * files that are smaller than a certain threshold, expecting faster
                 * commit.  The threshold is defined by the GUC wal_skip_threshold.