pg_basebackup: Skip a few more fsyncs if --no-sync is specified.
authorAndres Freund
Sun, 23 Jan 2022 21:59:23 +0000 (13:59 -0800)
committerAndres Freund
Sun, 23 Jan 2022 22:09:27 +0000 (14:09 -0800)
This is mostly interesting for running the regression tests on machines with
slow / overloaded IO.

Discussion: https://postgr.es/m/20220119041646[email protected]

src/bin/pg_basebackup/pg_basebackup.c
src/bin/pg_basebackup/walmethods.c

index 7a56ebb2c9228aff4a078d26b2e86ceab8bcf72e..221cc4caf233dafc3e197586e35334a3d1f2915a 100644 (file)
@@ -2201,9 +2201,21 @@ BaseBackup(void)
        snprintf(tmp_filename, MAXPGPATH, "%s/backup_manifest.tmp", basedir);
        snprintf(filename, MAXPGPATH, "%s/backup_manifest", basedir);
 
-       /* durable_rename emits its own log message in case of failure */
-       if (durable_rename(tmp_filename, filename) != 0)
-           exit(1);
+       if (do_sync)
+       {
+           /* durable_rename emits its own log message in case of failure */
+           if (durable_rename(tmp_filename, filename) != 0)
+               exit(1);
+       }
+       else
+       {
+           if (rename(tmp_filename, filename) != 0)
+           {
+               pg_log_error("could not rename file \"%s\" to \"%s\": %m",
+                            tmp_filename, filename);
+               exit(1);
+           }
+       }
    }
 
    if (verbose)
index f74bd13315c52e6853f90c3858a83c3a008f2568..a6d08c1270ad6bf94b0e8afa3ddb8875524df2d6 100644 (file)
@@ -445,7 +445,17 @@ dir_close(Walfile f, WalCloseMethod method)
            snprintf(tmppath2, sizeof(tmppath2), "%s/%s",
                     dir_data->basedir, filename2);
            pg_free(filename2);
-           r = durable_rename(tmppath, tmppath2);
+           if (dir_data->sync)
+               r = durable_rename(tmppath, tmppath2);
+           else
+           {
+               if (rename(tmppath, tmppath2) != 0)
+               {
+                   pg_log_error("could not rename file \"%s\" to \"%s\": %m",
+                                tmppath, tmppath2);
+                   r = -1;
+               }
+           }
        }
        else if (method == CLOSE_UNLINK)
        {