8000 Prevent starting a standalone backend with standby_mode on. · s-monk/postgres@f4e4053 · GitHub
[go: up one dir, main page]

Skip to content

Commit f4e4053

Browse files
committed
Prevent starting a standalone backend with standby_mode on.
This can't really work because standby_mode expects there to be more WAL arriving, which there will not ever be because there's no WAL receiver process to fetch it. Moreover, if standby_mode is on then hot standby might also be turned on, causing even more strangeness because that expects read-only sessions to be executing in parallel. Bernd Helmle reported a case where btree_xlog_delete_get_latestRemovedXid got confused, but rather than band-aiding individual problems it seems best to prevent getting anywhere near this state in the first place. Back-patch to all supported branches. In passing, also fix some omissions of errcodes in other ereport's in readRecoveryCommandFile(). Michael Paquier (errcode hacking by me) Discussion: <00F0B2CEF6D0CEF8A90119D4@eje.credativ.lan>
1 parent 314a25f commit f4e4053

File tree

1 file changed

+19
-5
lines changed
  • src/backend/access/transam

1 file changed

+19
-5
lines changed

src/backend/access/transam/xlog.c

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5152,7 +5152,8 @@ readRecoveryCommandFile(void)
51525152
rtli = (TimeLineID) strtoul(item->value, NULL, 0);
51535153
if (errno == EINVAL || errno == ERANGE)
51545154
ereport(FATAL,
5155-
(errmsg("recovery_target_timeline is not a valid number: \"%s\"",
5155+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5156+
errmsg("recovery_target_timeline is not a valid number: \"%s\"",
51565157
item->value)));
51575158
}
51585159
if (rtli)
@@ -5168,7 +5169,8 @@ readRecoveryCommandFile(void)
51685169
recoveryTargetXid = (TransactionId) strtoul(item->value, NULL, 0);
51695170
if (errno == EINVAL || errno == ERANGE)
51705171
ereport(FATAL,
5171-
(errmsg("recovery_target_xid is not a valid number: \"%s\"",
5172+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5173+
errmsg("recovery_target_xid is not a valid number: \"%s\"",
51725174
item->value)));
51735175
ereport(DEBUG2,
51745176
(errmsg_internal("recovery_target_xid = %u",
@@ -5281,7 +5283,8 @@ readRecoveryCommandFile(void)
52815283
}
52825284
else
52835285
ereport(FATAL,
5284-
(errmsg("unrecognized recovery parameter \"%s\"",
5286+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5287+
errmsg("unrecognized recovery parameter \"%s\"",
52855288
item->name)));
52865289
}
52875290

@@ -5300,10 +5303,20 @@ readRecoveryCommandFile(void)
53005303
{
53015304
if (recoveryRestoreCommand == NULL)
53025305
ereport(FATAL,
5303-
(errmsg("recovery command file \"%s\" must specify restore_command when standby mode is not enabled",
5306+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5307+
errmsg("recovery command file \"%s\" must specify restore_command when standby mode is not enabled",
53045308
RECOVERY_COMMAND_FILE)));
53055309
}
53065310

5311+
/*
5312+
* We don't support standby_mode in standalone backends; that requires
5313+
* other processes such as the WAL receiver to be alive.
5314+
*/
5315+
if (StandbyModeRequested && !IsUnderPostmaster)
5316+
ereport(FATAL,
5317+
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
5318+
errmsg("standby mode is not supported by single-user servers")));
5319+
53075320
/* Enable fetching from archive recovery area */
53085321
ArchiveRecoveryRequested = true;
53095322

@@ -5320,7 +5333,8 @@ readRecoveryCommandFile(void)
53205333
/* Timeline 1 does not have a history file, all else should */
53215334
if (rtli != 1 && !existsTimeLineHistory(rtli))
53225335
ereport(FATAL,
5323-
(errmsg("recovery target timeline %u does not exist",
5336+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5337+
errmsg("recovery target timeline %u does not exist",
53245338
rtli)));
53255339
recoveryTargetTLI = rtli;
53265340
recoveryTargetIsLatest = false;

0 commit comments

Comments
 (0)
0