Reduce overhead of renaming archive status files.
authorFujii Masao <[email protected]>
Tue, 26 Jul 2022 07:00:18 +0000 (16:00 +0900)
committerFujii Masao <[email protected]>
Tue, 26 Jul 2022 07:00:18 +0000 (16:00 +0900)
Presently, archive status files are durably renamed from .ready to
.done to indicate that a file has been archived.  Persisting this
rename to disk accounts for a significant amount of the overhead
associated with archiving.  While durably renaming the file
prevents re-archiving in most cases, archive commands and libraries
must already gracefully handle attempts to re-archive the last
archived file after a crash (e.g., a crash immediately after
archive_command exits but before the server renames the status
file).

This change reduces the amount of overhead associated with
archiving by using rename() instead of durable_rename() to rename
the archive status files.  As a consequence, the server is more
likely to attempt to re-archive files after a crash, but as noted
above, archive commands and modules are already expected to handle
this.  It is also possible that the server will attempt to re-
archive files that have been removed or recycled, but the archiver
already handles this, too.

Author: Nathan Bossart
Reviewed-by: Kyotaro Horiguchi, Fujii Masao
Discussion: https://postgr.es/m/20220222011948.GA3850532@nathanxps13

src/backend/postmaster/pgarch.c

index 25e31c42e1662482c016c40ba155ad742e89a4e7..6ce361707d767110eecbd6340cfb10db635838b5 100644 (file)
@@ -745,7 +745,19 @@ pgarch_archiveDone(char *xlog)
 
    StatusFilePath(rlogready, xlog, ".ready");
    StatusFilePath(rlogdone, xlog, ".done");
-   (void) durable_rename(rlogready, rlogdone, WARNING);
+
+   /*
+    * To avoid extra overhead, we don't durably rename the .ready file to
+    * .done.  Archive commands and libraries must gracefully handle attempts
+    * to re-archive files (e.g., if the server crashes just before this
+    * function is called), so it should be okay if the .ready file reappears
+    * after a crash.
+    */
+   if (rename(rlogready, rlogdone) < 0)
+       ereport(WARNING,
+               (errcode_for_file_access(),
+                errmsg("could not rename file \"%s\" to \"%s\": %m",
+                       rlogready, rlogdone)));
 }