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

Skip to content

Commit 823df40

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 da14d46 commit 823df40

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
@@ -5604,7 +5604,8 @@ readRecoveryCommandFile(void)
56045604
rtli = (TimeLineID) strtoul(item->value, NULL, 0);
56055605
if (errno == EINVAL || errno == ERANGE)
56065606
ereport(FATAL,
5607-
(errmsg("recovery_target_timeline is not a valid number: \"%s\"",
5607+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5608+
errmsg("recovery_target_timeline is not a valid number: \"%s\"",
56085609
item->value)));
56095610
}
56105611
if (rtli)
@@ -5620,7 +5621,8 @@ readRecoveryCommandFile(void)
56205621
recoveryTargetXid = (TransactionId) strtoul(item->value, NULL, 0);
56215622
if (errno == EINVAL || errno == ERANGE)
56225623
ereport(FATAL,
5623-
(errmsg("recovery_target_xid is not a valid number: \"%s\"",
5624+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5625+
errmsg("recovery_target_xid is not a valid number: \"%s\"",
56245626
item->value)));
56255627
ereport(DEBUG2,
56265628
(errmsg_internal("recovery_target_xid = %u",
@@ -5711,7 +5713,8 @@ readRecoveryCommandFile(void)
57115713
}
57125714
else
57135715
ereport(FATAL,
5714-
(errmsg("unrecognized recovery parameter \"%s\"",
5716+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5717+
errmsg("unrecognized recovery parameter \"%s\"",
57155718
item->name)));
57165719
}
57175720

@@ -5730,10 +5733,20 @@ readRecoveryCommandFile(void)
57305733
{
57315734
if (recoveryRestoreCommand == NULL)
57325735
ereport(FATAL,
5733-
(errmsg("recovery command file \"%s\" must specify restore_command when standby mode is not enabled",
5736+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5737+
errmsg("recovery command file \"%s\" must specify restore_command when standby mode is not enabled",
57345738
RECOVERY_COMMAND_FILE)));
57355739
}
57365740

5741+
/*
5742+
* We don't support standby_mode in standalone backends; that requires
5743+
* other processes such as the WAL receiver to be alive.
5744+
*/
5745+
if (StandbyModeRequested && !IsUnderPostmaster)
5746+
ereport(FATAL,
5747+
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
5748+
errmsg("standby mode is not supported by single-user servers")));
5749+
57375750
/* Enable fetching from archive recovery area */
57385751
ArchiveRecoveryRequested = true;
57395752

@@ -5750,7 +5763,8 @@ readRecoveryCommandFile(void)
57505763
/* Timeline 1 does not have a history file, all else should */
57515764
if (rtli != 1 && !existsTimeLineHistory(rtli))
57525765
ereport(FATAL,
5753-
(errmsg("recovery target timeline %u does not exist",
5766+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5767+
errmsg("recovery target timeline %u does not exist",
57545768
rtli)));
57555769
recoveryTargetTLI = rtli;
57565770
recoveryTargetIsLatest = false;

0 commit comments

Comments
 (0)
0