Skip to content

Commit 0e0f43d

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 530fb68 commit 0e0f43d

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
@@ -5022,7 +5022,8 @@ readRecoveryCommandFile(void)
50225022
rtli = (TimeLineID) strtoul(item->value, NULL, 0);
50235023
if (errno == EINVAL || errno == ERANGE)
50245024
ereport(FATAL,
5025-
(errmsg("recovery_target_timeline is not a valid number: \"%s\"",
5025+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5026+
errmsg("recovery_target_timeline is not a valid number: \"%s\"",
50265027
item->value)));
50275028
}
50285029
if (rtli)
@@ -5038,7 +5039,8 @@ readRecoveryCommandFile(void)
50385039
recoveryTargetXid = (TransactionId) strtoul(item->value, NULL, 0);
50395040
if (errno == EINVAL || errno == ERANGE)
50405041
ereport(FATAL,
5041-
(errmsg("recovery_target_xid is not a valid number: \"%s\"",
5042+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5043+
errmsg("recovery_target_xid is not a valid number: \"%s\"",
50425044
item->value)));
50435045
ereport(DEBUG2,
50445046
(errmsg_internal("recovery_target_xid = %u",
@@ -5153,7 +5155,8 @@ readRecoveryCommandFile(void)
51535155
}
51545156
else
51555157
ereport(FATAL,
5156-
(errmsg("unrecognized recovery parameter \"%s\"",
5158+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5159+
errmsg("unrecognized recovery parameter \"%s\"",
51575160
item->name)));
51585161
}
51595162

@@ -5172,7 +5175,8 @@ readRecoveryCommandFile(void)
51725175
{
51735176
if (recoveryRestoreCommand == NULL)
51745177
ereport(FATAL,
5175-
(errmsg("recovery command file \"%s\" must specify restore_command when standby mode is not enabled",
5178+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5179+
errmsg("recovery command file \"%s\" must specify restore_command when standby mode is not enabled",
51765180
RECOVERY_COMMAND_FILE)));
51775181
}
51785182

@@ -5186,6 +5190,15 @@ readRecoveryCommandFile(void)
51865190
!EnableHotStandby)
51875191
recoveryTargetAction = RECOVERY_TARGET_ACTION_SHUTDOWN;
51885192

5193+
/*
5194+
* We don't support standby_mode in standalone backends; that requires
5195+
* other processes such as the WAL receiver to be alive.
5196+
*/
5197+
if (StandbyModeRequested && !IsUnderPostmaster)
5198+
ereport(FATAL,
5199+
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
5200+
errmsg("standby mode is not supported by single-user servers")));
5201+
51895202
/* Enable fetching from archive recovery area */
51905203
ArchiveRecoveryRequested = true;
51915204

@@ -5202,7 +5215,8 @@ readRecoveryCommandFile(void)
52025215
/* Timeline 1 does not have a history file, all else should */
52035216
if (rtli != 1 && !existsTimeLineHistory(rtli))
52045217
ereport(FATAL,
5205-
(errmsg("recovery target timeline %u does not exist",
5218+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5219+
errmsg("recovery target timeline %u does not exist",
52065220
rtli)));
52075221
recoveryTargetTLI = rtli;
52085222
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