/*
* Set backupStartPoint if we're starting recovery from a base backup.
*
- * Set backupEndPoint and use minRecoveryPoint as the backup end
+ * Also set backupEndPoint and use minRecoveryPoint as the backup end
* location if we're starting recovery from a base backup which was
- * taken from the standby. In this case, the database system status in
- * pg_control must indicate DB_IN_ARCHIVE_RECOVERY. If not, which
- * means that backup is corrupted, so we cancel recovery.
+ * taken from a standby. In this case, the database system status in
+ * pg_control must indicate that the database was already in
+ * recovery. Usually that will be DB_IN_ARCHIVE_RECOVERY but also can
+ * be DB_SHUTDOWNED_IN_RECOVERY if recovery previously was interrupted
+ * before reaching this point; e.g. because restore_command or
+ * primary_conninfo were faulty.
+ *
+ * Any other state indicates that the backup somehow became corrupted
+ * and we can't sensibly continue with recovery.
*/
if (haveBackupLabel)
{
if (backupFromStandby)
{
- if (dbstate_at_startup != DB_IN_ARCHIVE_RECOVERY)
+ if (dbstate_at_startup != DB_IN_ARCHIVE_RECOVERY &&
+ dbstate_at_startup != DB_SHUTDOWNED_IN_RECOVERY)
ereport(FATAL,
(errmsg("backup_label contains data inconsistent with control file"),
errhint("This means that the backup is corrupted and you will "