Handle fsync failures in pg_receivewal and pg_recvlogical
authorPeter Eisentraut <peter@eisentraut.org>
Mon, 29 Jul 2019 05:41:06 +0000 (07:41 +0200)
committerPeter Eisentraut <peter@eisentraut.org>
Mon, 29 Jul 2019 05:54:57 +0000 (07:54 +0200)
It is not safe to simply report an fsync error and continue.  We must
exit the program instead.

Reviewed-by: Michael Paquier <michael@paquier.xyz>
Reviewed-by: Sehrope Sarkuni <sehrope@jackdb.com>
Discussion: https://www.postgresql.org/message-id/flat/9b49fe44-8f3e-eca9-5914-29e9e99030bf@2ndquadrant.com

src/bin/pg_basebackup/pg_recvlogical.c
src/bin/pg_basebackup/receivelog.c
src/bin/pg_basebackup/walmethods.c

index 90a3f41bbbe41433dfb0855775e1790ea4ae6bec..af29dd7651a4cefecb2c2225d43d456b0659ceb8 100644 (file)
@@ -192,8 +192,8 @@ OutputFsync(TimestampTz now)
 
    if (fsync(outfd) != 0)
    {
-       pg_log_error("could not fsync file \"%s\": %m", outfile);
-       return false;
+       pg_log_fatal("could not fsync file \"%s\": %m", outfile);
+       exit(1);
    }
 
    return true;
index 2fd16421aa75c1ab3d659457d01c3562807e8518..d73f6145c1a5e4841cf571ecdd015a0d72c11cf3 100644 (file)
@@ -134,10 +134,10 @@ open_walfile(StreamCtl *stream, XLogRecPtr startpoint)
            /* fsync file in case of a previous crash */
            if (stream->walmethod->sync(f) != 0)
            {
-               pg_log_error("could not fsync existing write-ahead log file \"%s\": %s",
+               pg_log_fatal("could not fsync existing write-ahead log file \"%s\": %s",
                             fn, stream->walmethod->getlasterror());
                stream->walmethod->close(f, CLOSE_UNLINK);
-               return false;
+               exit(1);
            }
 
            walfile = f;
@@ -763,9 +763,9 @@ HandleCopyStream(PGconn *conn, StreamCtl *stream,
        {
            if (stream->walmethod->sync(walfile) != 0)
            {
-               pg_log_error("could not fsync file \"%s\": %s",
+               pg_log_fatal("could not fsync file \"%s\": %s",
                             current_walfile_name, stream->walmethod->getlasterror());
-               goto error;
+               exit(1);
            }
            lastFlushPosition = blockpos;
 
@@ -1015,9 +1015,9 @@ ProcessKeepaliveMsg(PGconn *conn, StreamCtl *stream, char *copybuf, int len,
             */
            if (stream->walmethod->sync(walfile) != 0)
            {
-               pg_log_error("could not fsync file \"%s\": %s",
+               pg_log_fatal("could not fsync file \"%s\": %s",
                             current_walfile_name, stream->walmethod->getlasterror());
-               return false;
+               exit(1);
            }
            lastFlushPosition = blockpos;
        }
index 83b520898beff1961041e9c0a440a67277907d55..8ec12e6f723c32507751da0ca019fafcac849bce 100644 (file)
@@ -864,7 +864,7 @@ tar_close(Walfile f, WalCloseMethod method)
 
    /* Always fsync on close, so the padding gets fsynced */
    if (tar_sync(f) < 0)
-       return -1;
+       exit(1);
 
    /* Clean up and done */
    pg_free(tf->pathname);