diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index 6c69eb6dd7..f70447aa1a 100644 *** a/src/backend/access/transam/xlog.c --- b/src/backend/access/transam/xlog.c *************** *** 7596,7602 **** StartupXLOG(void) --- 7596,7605 ---- } else CreateCheckPoint(CHECKPOINT_END_OF_RECOVERY | CHECKPOINT_IMMEDIATE); + } + if (ArchiveRecoveryRequested) + { /* * And finally, execute the recovery_end_command, if any. */ *************** *** 7604,7613 **** StartupXLOG(void) ExecuteRecoveryCommand(recoveryEndCommand, "recovery_end_command", true); - } - if (ArchiveRecoveryRequested) - { /* * We switched to a new timeline. Clean up segments on the old * timeline. --- 7607,7613 ---- diff --git a/src/backend/access/transam/index 9a21f006d1..e14bcf8ea6 100644 *** a/src/backend/access/transam/xlogarchive.c --- b/src/backend/access/transam/xlogarchive.c *************** *** 64,69 **** RestoreArchivedFile(char *path, const char *xlogfname, --- 64,76 ---- 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 || strcmp(recoveryRestoreCommand, "") == 0) goto not_available;