Commit b85e43fe authored by Peter Eisentraut's avatar Peter Eisentraut

More precise errors from initial pg_control check

Use a separate error message for invalid checkpoint location and
invalid state instead of just "invalid data" for both.
Reviewed-by: default avatarMichael Paquier <michael@paquier.xyz>
Discussion: https://www.postgresql.org/message-id/20191107041630.GK1768@paquier.xyz
parent e86c8ef2
...@@ -6231,45 +6231,59 @@ StartupXLOG(void) ...@@ -6231,45 +6231,59 @@ StartupXLOG(void)
CurrentResourceOwner = AuxProcessResourceOwner; CurrentResourceOwner = AuxProcessResourceOwner;
/* /*
* Verify XLOG status looks valid. * Check that contents look valid.
*/ */
if (ControlFile->state < DB_SHUTDOWNED || if (!XRecOffIsValid(ControlFile->checkPoint))
ControlFile->state > DB_IN_PRODUCTION ||
!XRecOffIsValid(ControlFile->checkPoint))
ereport(FATAL, ereport(FATAL,
(errmsg("control file contains invalid data"))); (errmsg("control file contains invalid checkpoint location")));
if (ControlFile->state == DB_SHUTDOWNED) switch (ControlFile->state)
{ {
/* This is the expected case, so don't be chatty in standalone mode */ case DB_SHUTDOWNED:
ereport(IsPostmasterEnvironment ? LOG : NOTICE, /* This is the expected case, so don't be chatty in standalone mode */
(errmsg("database system was shut down at %s", ereport(IsPostmasterEnvironment ? LOG : NOTICE,
str_time(ControlFile->time)))); (errmsg("database system was shut down at %s",
str_time(ControlFile->time))));
break;
case DB_SHUTDOWNED_IN_RECOVERY:
ereport(LOG,
(errmsg("database system was shut down in recovery at %s",
str_time(ControlFile->time))));
break;
case DB_SHUTDOWNING:
ereport(LOG,
(errmsg("database system shutdown was interrupted; last known up at %s",
str_time(ControlFile->time))));
break;
case DB_IN_CRASH_RECOVERY:
ereport(LOG,
(errmsg("database system was interrupted while in recovery at %s",
str_time(ControlFile->time)),
errhint("This probably means that some data is corrupted and"
" you will have to use the last backup for recovery.")));
break;
case DB_IN_ARCHIVE_RECOVERY:
ereport(LOG,
(errmsg("database system was interrupted while in recovery at log time %s",
str_time(ControlFile->checkPointCopy.time)),
errhint("If this has occurred more than once some data might be corrupted"
" and you might need to choose an earlier recovery target.")));
break;
case DB_IN_PRODUCTION:
ereport(LOG,
(errmsg("database system was interrupted; last known up at %s",
str_time(ControlFile->time))));
break;
default:
ereport(FATAL,
(errmsg("control file contains invalid database cluster state")));
} }
else if (ControlFile->state == DB_SHUTDOWNED_IN_RECOVERY)
ereport(LOG,
(errmsg("database system was shut down in recovery at %s",
str_time(ControlFile->time))));
else if (ControlFile->state == DB_SHUTDOWNING)
ereport(LOG,
(errmsg("database system shutdown was interrupted; last known up at %s",
str_time(ControlFile->time))));
else if (ControlFile->state == DB_IN_CRASH_RECOVERY)
ereport(LOG,
(errmsg("database system was interrupted while in recovery at %s",
str_time(ControlFile->time)),
errhint("This probably means that some data is corrupted and"
" you will have to use the last backup for recovery.")));
else if (ControlFile->state == DB_IN_ARCHIVE_RECOVERY)
ereport(LOG,
(errmsg("database system was interrupted while in recovery at log time %s",
str_time(ControlFile->checkPointCopy.time)),
errhint("If this has occurred more than once some data might be corrupted"
" and you might need to choose an earlier recovery target.")));
else if (ControlFile->state == DB_IN_PRODUCTION)
ereport(LOG,
(errmsg("database system was interrupted; last known up at %s",
str_time(ControlFile->time))));
/* This is just to allow attaching to startup process with a debugger */ /* This is just to allow attaching to startup process with a debugger */
#ifdef XLOG_REPLAY_DELAY #ifdef XLOG_REPLAY_DELAY
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment