Skip to content

Commit c40bb11

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 3aa233f commit c40bb11

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
@@ -4980,7 +4980,8 @@ readRecoveryCommandFile(void)
49804980
rtli = (TimeLineID) strtoul(item->value, NULL, 0);
49814981
if (errno == EINVAL || errno == ERANGE)
49824982
ereport(FATAL,
4983-
(errmsg("recovery_target_timeline is not a valid number: \"%s\"",
4983+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4984+
errmsg("recovery_target_timeline is not a valid number: \"%s\"",
49844985
item->value)));
49854986
}
49864987
if (rtli)
@@ -4996,7 +4997,8 @@ readRecoveryCommandFile(void)
49964997
recoveryTargetXid = (TransactionId) strtoul(item->value, NULL, 0);
49974998
if (errno == EINVAL || errno == ERANGE)
49984999
ereport(FATAL,
4999-
(errmsg("recovery_target_xid is not a valid number: \"%s\"",
5000+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5001+
errmsg("recovery_target_xid is not a valid number: \"%s\"",
50005002
item->value)));
50015003
ereport(DEBUG2,
50025004
(errmsg_internal("recovery_target_xid = %u",
@@ -5111,7 +5113,8 @@ readRecoveryCommandFile(void)
51115113
}
51125114
else
51135115
ereport(FATAL,
5114-
(errmsg("unrecognized recovery parameter \"%s\"",
5116+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5117+
errmsg("unrecognized recovery parameter \"%s\"",
51155118
item->name)));
51165119
}
51175120

@@ -5130,7 +5133,8 @@ readRecoveryCommandFile(void)
51305133
{
51315134
if (recoveryRestoreCommand == NULL)
51325135
ereport(FATAL,
5133-
(errmsg("recovery command file \"%s\" must specify restore_command when standby mode is not enabled",
5136+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5137+
errmsg("recovery command file \"%s\" must specify restore_command when standby mode is not enabled",
51345138
RECOVERY_COMMAND_FILE)));
51355139
}
51365140

@@ -5144,6 +5148,15 @@ readRecoveryCommandFile(void)
51445148
!EnableHotStandby)
51455149
recoveryTargetAction = RECOVERY_TARGET_ACTION_SHUTDOWN;
51465150

5151+
/*
5152+
* We don't support standby_mode in standalone backends; that requires
5153+
* other processes such as the WAL receiver to be alive.
5154+
*/
5155+
if (StandbyModeRequested && !IsUnderPostmaster)
5156+
ereport(FATAL,
5157+
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
5158+
errmsg("standby mode is not supported by single-user servers")));
5159+
51475160
/* Enable fetching from archive recovery area */
51485161
ArchiveRecoveryRequested = true;
51495162

@@ -5160,7 +5173,8 @@ readRecoveryCommandFile(void)
51605173
/* Timeline 1 does not have a history file, all else should */
51615174
if (rtli != 1 && !existsTimeLineHistory(rtli))
51625175
ereport(FATAL,
5163-
(errmsg("recovery target timeline %u does not exist",
5176+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5177+
errmsg("recovery target timeline %u does not exist",
51645178
rtli)));
51655179
recoveryTargetTLI = rtli;
51665180
recoveryTargetIsLatest = false;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy