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

Skip to content

Commit e3439a4

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 934630c commit e3439a4

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
@@ -5347,7 +5347,8 @@ readRecoveryCommandFile(void)
53475347
rtli = (TimeLineID) strtoul(item->value, NULL, 0);
53485348
if (errno == EINVAL || errno == ERANGE)
53495349
ereport(FATAL,
5350-
(errmsg("recovery_target_timeline is not a valid number: \"%s\"",
5350+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5351+
errmsg("recovery_target_timeline is not a valid number: \"%s\"",
53515352
item->value)));
53525353
}
53535354
if (rtli)
@@ -5363,7 +5364,8 @@ readRecoveryCommandFile(void)
53635364
recoveryTargetXid = (TransactionId) strtoul(item->value, NULL, 0);
53645365
if (errno == EINVAL || errno == ERANGE)
53655366
ereport(FATAL,
5366-
(errmsg("recovery_target_xid is not a valid number: \"%s\"",
5367+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5368+
errmsg("recovery_target_xid is not a valid number: \"%s\"",
53675369
item->value)));
53685370
ereport(DEBUG2,
53695371
(errmsg_internal("recovery_target_xid = %u",
@@ -5454,7 +5456,8 @@ readRecoveryCommandFile(void)
54545456
}
54555457
else
54565458
ereport(FATAL,
5457-
(errmsg("unrecognized recovery parameter \"%s\"",
5459+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5460+
errmsg("unrecognized recovery parameter \"%s\"",
54585461
item->name)));
54595462
}
54605463

@@ -5473,10 +5476,20 @@ readRecoveryCommandFile(void)
54735476
{
54745477
if (recoveryRestoreCommand == NULL)
54755478
ereport(FATAL,
5476-
(errmsg("recovery command file \"%s\" must specify restore_command when standby mode is not enabled",
5479+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5480+
errmsg("recovery command file \"%s\" must specify restore_command when standby mode is not enabled",
54775481
RECOVERY_COMMAND_FILE)));
54785482
}
54795483

5484 AE73 +
/*
5485+
* We don't support standby_mode in standalone backends; that requires
5486+
* other processes such as the WAL receiver to be alive.
5487+
*/
5488+
if (StandbyMode && !IsUnderPostmaster)
5489+
ereport(FATAL,
5490+
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
5491+
errmsg("standby mode is not supported by single-user servers")));
5492+
54805493
/* Enable fetching from archive recovery area */
54815494
InArchiveRecovery = true;
54825495

@@ -5493,7 +5506,8 @@ readRecoveryCommandFile(void)
54935506
/* Timeline 1 does not have a history file, all else should */
54945507
if (rtli != 1 && !existsTimeLineHistory(rtli))
54955508
ereport(FATAL,
5496-
(errmsg("recovery target timeline %u does not exist",
5509+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5510+
errmsg("recovery target timeline %u does not exist",
54975511
rtli)));
54985512
recoveryTargetTLI = rtli;
54995513
recoveryTargetIsLatest = false;

0 commit comments

Comments
 (0)
0