Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit df86e52

Browse files
committed
Remove temporary WAL and history files at the end of archive recovery
cbc55da has reworked the order of some actions at the end of archive recovery. Unfortunately this overlooked the fact that the startup process needs to remove RECOVERYXLOG (for temporary WAL segment newly recovered from archives) and RECOVERYHISTORY (for temporary history file) at this step, leaving the files around even after recovery ended. Backpatch to 9.5, like the previous commit. Author: Sawada Masahiko Reviewed-by: Fujii Masao, Michael Paquier Discussion: https://postgr.es/m/CAD21AoBO_eDQub6zojFnWtnmutRBWvYf7=cW4Hsqj+U_R26w3Q@mail.gmail.com Backpatch-through: 9.5
1 parent 9555cc8 commit df86e52

File tree

2 files changed

+36
-13
lines changed

2 files changed

+36
-13
lines changed

src/backend/access/transam/xlog.c

+12-12
Original file line numberDiff line numberDiff line change
@@ -5461,7 +5461,6 @@ validateRecoveryParameters(void)
54615461
static void
54625462
exitArchiveRecovery(TimeLineID endTLI, XLogRecPtr endOfLog)
54635463
{
5464-
char recoveryPath[MAXPGPATH];
54655464
char xlogfname[MAXFNAMELEN];
54665465
XLogSegNo endLogSegNo;
54675466
XLogSegNo startLogSegNo;
@@ -5541,17 +5540,6 @@ exitArchiveRecovery(TimeLineID endTLI, XLogRecPtr endOfLog)
55415540
XLogFileName(xlogfname, ThisTimeLineID, startLogSegNo, wal_segment_size);
55425541
XLogArchiveCleanup(xlogfname);
55435542

5544-
/*
5545-
* Since there might be a partial WAL segment named RECOVERYXLOG, get rid
5546-
* of it.
5547-
*/
5548-
snprintf(recoveryPath, MAXPGPATH, XLOGDIR "/RECOVERYXLOG");
5549-
unlink(recoveryPath); /* ignore any error */
5550-
5551-
/* Get rid of any remaining recovered timeline-history file, too */
5552-
snprintf(recoveryPath, MAXPGPATH, XLOGDIR "/RECOVERYHISTORY");
5553-
unlink(recoveryPath); /* ignore any error */
5554-
55555543
/*
55565544
* Remove the signal files out of the way, so that we don't accidentally
55575545
* re-enter archive recovery mode in a subsequent crash.
@@ -7433,6 +7421,7 @@ StartupXLOG(void)
74337421
if (ArchiveRecoveryRequested)
74347422
{
74357423
char reason[200];
7424+
char recoveryPath[MAXPGPATH];
74367425

74377426
Assert(InArchiveRecovery);
74387427

@@ -7489,6 +7478,17 @@ StartupXLOG(void)
74897478
*/
74907479
writeTimeLineHistory(ThisTimeLineID, recoveryTargetTLI,
74917480
EndRecPtr, reason);
7481+
7482+
/*
7483+
* Since there might be a partial WAL segment named RECOVERYXLOG, get
7484+
* rid of it.
7485+
*/
7486+
snprintf(recoveryPath, MAXPGPATH, XLOGDIR "/RECOVERYXLOG");
7487+
unlink(recoveryPath); /* ignore any error */
7488+
7489+
/* Get rid of any remaining recovered timeline-history file, too */
7490+
snprintf(recoveryPath, MAXPGPATH, XLOGDIR "/RECOVERYHISTORY");
7491+
unlink(recoveryPath); /* ignore any error */
74927492
}
74937493

74947494
/* Save the selected TimeLineID in shared memory, too */

src/test/recovery/t/002_archiving.pl

+24-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use warnings;
44
use PostgresNode;
55
use TestLib;
6-
use Test::More tests => 1;
6+
use Test::More tests => 3;
77
use File::Copy;
88

99
# Initialize master node, doing archives
@@ -49,3 +49,26 @@
4949
my $result =
5050
$node_standby->safe_psql('postgres', "SELECT count(*) FROM tab_int");
5151
is($result, qq(1000), 'check content from archives');
52+
53+
# Check the presence of temporary files specifically generated during
54+
# archive recovery. To ensure the presence of the temporary history
55+
# file, switch to a timeline large enough to allow a standby to recover
56+
# a history file from an archive. As this requires at least two timeline
57+
# switches, promote the existing standby first. Then create a second
58+
# standby based on the promoted one. Finally, the second standby is
59+
# promoted.
60+
$node_standby->promote;
61+
62+
my $node_standby2 = get_new_node('standby2');
63+
$node_standby2->init_from_backup($node_master, $backup_name,
64+
has_restoring => 1);
65+
$node_standby2->start;
66+
67+
# Now promote standby2, and check that temporary files specifically
68+
# generated during archive recovery are removed by the end of recovery.
69+
$node_standby2->promote;
70+
my $node_standby2_data = $node_standby2->data_dir;
71+
ok( !-f "$node_standby2_data/pg_wal/RECOVERYHISTORY",
72+
"RECOVERYHISTORY removed after promotion");
73+
ok( !-f "$node_standby2_data/pg_wal/RECOVERYXLOG",
74+
"RECOVERYXLOG removed after promotion");

0 commit comments

Comments
 (0)