Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitdc78866

Browse files
committed
Fail if recovery target is not reached
Before, if a recovery target is configured, but the archive endedbefore the target was reached, recovery would end and the server wouldpromote without further notice. That was deemed to be pretty wrong.With this change, if the recovery target is not reached, it is a fatalerror.Based-on-patch-by: Leif Gunnar Erlandsen <leif@lako.no>Reviewed-by: Kyotaro Horiguchi <horikyota.ntt@gmail.com>Discussion:https://www.postgresql.org/message-id/flat/993736dd3f1713ec1f63fc3b653839f5@lako.no
1 parent29e321c commitdc78866

File tree

4 files changed

+73
-8
lines changed

4 files changed

+73
-8
lines changed

‎doc/src/sgml/config.sgml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3571,6 +3571,11 @@ restore_command = 'copy "C:\\server\\archivedir\\%f" "%p"' # Windows
35713571
If <xref linkend="guc-hot-standby"/> is not enabled, a setting of
35723572
<literal>pause</literal> will act the same as <literal>shutdown</literal>.
35733573
</para>
3574+
<para>
3575+
In any case, if a recovery target is configured but the archive
3576+
recovery ends before the target is reached, the server will shut down
3577+
with a fatal error.
3578+
</para>
35743579
</listitem>
35753580
</varlistentry>
35763581

‎src/backend/access/transam/xlog.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6200,7 +6200,7 @@ StartupXLOG(void)
62006200
XLogCtlInsert*Insert;
62016201
CheckPointcheckPoint;
62026202
boolwasShutdown;
6203-
boolreachedStopPoint= false;
6203+
boolreachedRecoveryTarget= false;
62046204
boolhaveBackupLabel= false;
62056205
boolhaveTblspcMap= false;
62066206
XLogRecPtrRecPtr,
@@ -7103,7 +7103,7 @@ StartupXLOG(void)
71037103
*/
71047104
if (recoveryStopsBefore(xlogreader))
71057105
{
7106-
reachedStopPoint= true;/* see below */
7106+
reachedRecoveryTarget= true;
71077107
break;
71087108
}
71097109

@@ -7258,7 +7258,7 @@ StartupXLOG(void)
72587258
/* Exit loop if we reached inclusive recovery target */
72597259
if (recoveryStopsAfter(xlogreader))
72607260
{
7261-
reachedStopPoint= true;
7261+
reachedRecoveryTarget= true;
72627262
break;
72637263
}
72647264

@@ -7270,7 +7270,7 @@ StartupXLOG(void)
72707270
* end of main redo apply loop
72717271
*/
72727272

7273-
if (reachedStopPoint)
7273+
if (reachedRecoveryTarget)
72747274
{
72757275
if (!reachedConsistency)
72767276
ereport(FATAL,
@@ -7327,7 +7327,18 @@ StartupXLOG(void)
73277327
/* there are no WAL records following the checkpoint */
73287328
ereport(LOG,
73297329
(errmsg("redo is not required")));
7330+
73307331
}
7332+
7333+
/*
7334+
* This check is intentionally after the above log messages that
7335+
* indicate how far recovery went.
7336+
*/
7337+
if (ArchiveRecoveryRequested&&
7338+
recoveryTarget!=RECOVERY_TARGET_UNSET&&
7339+
!reachedRecoveryTarget)
7340+
ereport(FATAL,
7341+
(errmsg("recovery ended before configured recovery target was reached")));
73317342
}
73327343

73337344
/*

‎src/test/perl/PostgresNode.pm

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,9 @@ Restoring WAL segments from archives using restore_command can be enabled
653653
by passing the keyword parameter has_restoring => 1. This is disabled by
654654
default.
655655
656+
If has_restoring is used, standby mode is used by default. To use
657+
recovery mode instead, pass the keyword parameter standby => 0.
658+
656659
The backup is copied, leaving the original unmodified. pg_hba.conf is
657660
unconditionally set to enable replication connections.
658661
@@ -669,6 +672,7 @@ sub init_from_backup
669672

670673
$params{has_streaming} = 0unlessdefined$params{has_streaming};
671674
$params{has_restoring} = 0unlessdefined$params{has_restoring};
675+
$params{standby} = 1unlessdefined$params{standby};
672676

673677
print
674678
"# Initializing node\"$node_name\" from backup\"$backup_name\" of node\"$root_name\"\n";
@@ -699,7 +703,7 @@ port = $port
699703
"unix_socket_directories = '$host'");
700704
}
701705
$self->enable_streaming($root_node)if$params{has_streaming};
702-
$self->enable_restoring($root_node)if$params{has_restoring};
706+
$self->enable_restoring($root_node,$params{standby})if$params{has_restoring};
703707
return;
704708
}
705709

@@ -939,7 +943,7 @@ primary_conninfo='$root_connstr'
939943
# Internal routine to enable archive recovery command on a standby node
940944
subenable_restoring
941945
{
942-
my ($self,$root_node) =@_;
946+
my ($self,$root_node,$standby) =@_;
943947
my$path = TestLib::perl2host($root_node->archive_dir);
944948
my$name =$self->name;
945949

@@ -961,7 +965,30 @@ sub enable_restoring
961965
'postgresql.conf',qq(
962966
restore_command = '$copy_command'
963967
));
964-
$self->set_standby_mode();
968+
if ($standby)
969+
{
970+
$self->set_standby_mode();
971+
}
972+
else
973+
{
974+
$self->set_recovery_mode();
975+
}
976+
return;
977+
}
978+
979+
=pod
980+
981+
=item$node->set_recovery_mode()
982+
983+
Place recovery.signal file.
984+
985+
=cut
986+
987+
subset_recovery_mode
988+
{
989+
my ($self) =@_;
990+
991+
$self->append_conf('recovery.signal','');
965992
return;
966993
}
967994

‎src/test/recovery/t/003_recovery_targets.pl

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
use warnings;
44
use PostgresNode;
55
use TestLib;
6-
use Test::Moretests=> 8;
6+
use Test::Moretests=> 9;
7+
use Time::HiResqw(usleep);
78

89
# Create and test a standby from given backup, with a certain recovery target.
910
# Choose $until_lsn later than the transaction commit that causes the row
@@ -145,3 +146,24 @@ sub test_recovery_standby
145146
my$logfile = slurp_file($node_standby->logfile());
146147
ok($logfile =~ qr/multiple recovery targets specified/,
147148
'multiple conflicting settings');
149+
150+
# Check behavior when recovery ends before target is reached
151+
152+
$node_standby = get_new_node('standby_8');
153+
$node_standby->init_from_backup($node_master,'my_backup',
154+
has_restoring=> 1,standby=> 0);
155+
$node_standby->append_conf('postgresql.conf',
156+
"recovery_target_name = 'does_not_exist'");
157+
158+
run_log(['pg_ctl','-D',$node_standby->data_dir,
159+
'-l',$node_standby->logfile,'start']);
160+
161+
# wait up to 10 seconds for postgres to terminate
162+
foreachmy$i (0..100)
163+
{
164+
lastif !-f$node_standby->data_dir .'/postmaster.pid';
165+
usleep(100_000);
166+
}
167+
$logfile = slurp_file($node_standby->logfile());
168+
ok($logfile =~qr/FATAL: recovery ended before configured recovery target was reached/,
169+
'recovery end before target reached is a fatal error');

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp