]> granicus.if.org Git - postgresql/blobdiff - src/backend/access/transam/xlogarchive.c
Fix initialization of fake LSN for unlogged relations
[postgresql] / src / backend / access / transam / xlogarchive.c
index f64f04cfaf53b133efa7668f9d39e3c937ae7824..e14bcf8ea6092fb40a7618ba1a6b76ba4411bbad 100644 (file)
@@ -4,7 +4,7 @@
  *             Functions for archiving WAL files and restoring from the archive.
  *
  *
- * Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * src/backend/access/transam/xlogarchive.c
@@ -59,14 +59,20 @@ RestoreArchivedFile(char *path, const char *xlogfname,
        char       *endp;
        const char *sp;
        int                     rc;
-       bool            signaled;
        struct stat stat_buf;
        XLogSegNo       restartSegNo;
        XLogRecPtr      restartRedoPtr;
        TimeLineID      restartTli;
 
+       /*
+        * Ignore restore_command when not in archive recovery (meaning
+        * we are in crash recovery).
+        */
+       if (!ArchiveRecoveryRequested)
+               goto not_available;
+
        /* In standby mode, restore_command might not be supplied */
-       if (recoveryRestoreCommand == NULL)
+       if (recoveryRestoreCommand == NULL || strcmp(recoveryRestoreCommand, "") == 0)
                goto not_available;
 
        /*
@@ -289,17 +295,12 @@ RestoreArchivedFile(char *path, const char *xlogfname,
         * will perform an immediate shutdown when it sees us exiting
         * unexpectedly.
         *
-        * Per the Single Unix Spec, shells report exit status > 128 when a called
-        * command died on a signal.  Also, 126 and 127 are used to report
-        * problems such as an unfindable command; treat those as fatal errors
-        * too.
+        * We treat hard shell errors such as "command not found" as fatal, too.
         */
-       if (WIFSIGNALED(rc) && WTERMSIG(rc) == SIGTERM)
+       if (wait_result_is_signal(rc, SIGTERM))
                proc_exit(1);
 
-       signaled = WIFSIGNALED(rc) || WEXITSTATUS(rc) > 125;
-
-       ereport(signaled ? FATAL : DEBUG2,
+       ereport(wait_result_is_any_signal(rc, true) ? FATAL : DEBUG2,
                        (errmsg("could not restore file \"%s\" from archive: %s",
                                        xlogfname, wait_result_to_str(rc))));
 
@@ -327,7 +328,7 @@ not_available:
  * This is currently used for recovery_end_command and archive_cleanup_command.
  */
 void
-ExecuteRecoveryCommand(char *command, char *commandName, bool failOnSignal)
+ExecuteRecoveryCommand(const char *command, const char *commandName, bool failOnSignal)
 {
        char            xlogRecoveryCmd[MAXPGPATH];
        char            lastRestartPointFname[MAXPGPATH];
@@ -335,7 +336,6 @@ ExecuteRecoveryCommand(char *command, char *commandName, bool failOnSignal)
        char       *endp;
        const char *sp;
        int                     rc;
-       bool            signaled;
        XLogSegNo       restartSegNo;
        XLogRecPtr      restartRedoPtr;
        TimeLineID      restartTli;
@@ -403,14 +403,11 @@ ExecuteRecoveryCommand(char *command, char *commandName, bool failOnSignal)
        {
                /*
                 * If the failure was due to any sort of signal, it's best to punt and
-                * abort recovery. See also detailed comments on signals in
-                * RestoreArchivedFile().
+                * abort recovery.  See comments in RestoreArchivedFile().
                 */
-               signaled = WIFSIGNALED(rc) || WEXITSTATUS(rc) > 125;
-
-               ereport((signaled && failOnSignal) ? FATAL : WARNING,
+               ereport((failOnSignal && wait_result_is_any_signal(rc, true)) ? FATAL : WARNING,
                /*------
-                  translator: First %s represents a recovery.conf parameter name like
+                  translator: First %s represents a postgresql.conf parameter name like
                  "recovery_end_command", the 2nd is the value of that parameter, the
                  third an already translated error message. */
                                (errmsg("%s \"%s\": %s", commandName,
@@ -422,10 +419,10 @@ ExecuteRecoveryCommand(char *command, char *commandName, bool failOnSignal)
 /*
  * A file was restored from the archive under a temporary filename (path),
  * and now we want to keep it. Rename it under the permanent filename in
- * in pg_wal (xlogfname), replacing any existing file with the same name.
+ * pg_wal (xlogfname), replacing any existing file with the same name.
  */
 void
-KeepFileRestoredFromArchive(char *path, char *xlogfname)
+KeepFileRestoredFromArchive(const char *path, const char *xlogfname)
 {
        char            xlogfpath[MAXPGPATH];
        bool            reload = false;
@@ -620,9 +617,16 @@ XLogArchiveCheckDone(const char *xlog)
 {
        char            archiveStatusPath[MAXPGPATH];
        struct stat stat_buf;
+       bool            inRecovery = RecoveryInProgress();
 
-       /* Always deletable if archiving is off */
-       if (!XLogArchivingActive())
+       /*
+        * The file is always deletable if archive_mode is "off".  On standbys
+        * archiving is disabled if archive_mode is "on", and enabled with
+        * "always".  On a primary, archiving is enabled if archive_mode is "on"
+        * or "always".
+        */
+       if (!((XLogArchivingActive() && !inRecovery) ||
+                 (XLogArchivingAlways() && inRecovery)))
                return true;
 
        /* First check for .done --- this means archiver is done with it */