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

Commita28d731

Browse files
committed
Mark commit and abort WAL records with XLR_SPECIAL_REL_UPDATE.
If a commit or abort record includes "dropped relfilenodes", then replayingthe record will remove data files. That is surely a "special rel update",but the records were not marked as such. Fix that, teach pg_rewind toexpect and ignore them, and add a test case to cover it.It's always been like this, but no backporting for fear of breakingexisting applications. If an application parsed the WAL but was nothandling commit/abort records, it would stop working. That might be a goodthing if it really needed to handle the dropped rels, but it will be caughtwhen the application is updated to work with PostgreSQL v14 anyway.Discussion:https://www.postgresql.org/message-id/07b33e2c-46a6-86a1-5f9e-a7da73fddb95%40iki.fiReviewed-by: Amit Kapila, Michael Paquier
1 parent3941eb6 commita28d731

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5565,6 +5565,7 @@ XactLogCommitRecord(TimestampTz commit_time,
55655565
{
55665566
xl_xinfo.xinfo |=XACT_XINFO_HAS_RELFILENODES;
55675567
xl_relfilenodes.nrels=nrels;
5568+
info |=XLR_SPECIAL_REL_UPDATE;
55685569
}
55695570

55705571
if (nmsgs>0)
@@ -5697,6 +5698,7 @@ XactLogAbortRecord(TimestampTz abort_time,
56975698
{
56985699
xl_xinfo.xinfo |=XACT_XINFO_HAS_RELFILENODES;
56995700
xl_relfilenodes.nrels=nrels;
5701+
info |=XLR_SPECIAL_REL_UPDATE;
57005702
}
57015703

57025704
if (TransactionIdIsValid(twophase_xid))

‎src/bin/pg_rewind/parsexlog.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include<unistd.h>
1515

1616
#include"access/rmgr.h"
17+
#include"access/xact.h"
1718
#include"access/xlog_internal.h"
1819
#include"access/xlogreader.h"
1920
#include"catalog/pg_control.h"
@@ -397,6 +398,18 @@ extractPageInfo(XLogReaderState *record)
397398
* source system.
398399
*/
399400
}
401+
elseif (rmid==RM_XACT_ID&&
402+
((rminfo&XLOG_XACT_OPMASK)==XLOG_XACT_COMMIT||
403+
(rminfo&XLOG_XACT_OPMASK)==XLOG_XACT_COMMIT_PREPARED||
404+
(rminfo&XLOG_XACT_OPMASK)==XLOG_XACT_ABORT||
405+
(rminfo&XLOG_XACT_OPMASK)==XLOG_XACT_ABORT_PREPARED))
406+
{
407+
/*
408+
* These records can include "dropped rels". We can safely ignore
409+
* them, we will see that they are missing and copy them from the
410+
* source.
411+
*/
412+
}
400413
elseif (info&XLR_SPECIAL_REL_UPDATE)
401414
{
402415
/*

‎src/bin/pg_rewind/t/001_basic.pl

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use strict;
22
use warnings;
33
use TestLib;
4-
use Test::Moretests=>20;
4+
use Test::Moretests=>23;
55

66
use FindBin;
77
use lib$FindBin::RealBin;
@@ -29,6 +29,10 @@ sub run_test
2929
primary_psql("CREATE TABLE tail_tbl (id integer, d text)");
3030
primary_psql("INSERT INTO tail_tbl VALUES (0, 'in primary')");
3131

32+
# This test table is dropped in the old primary after promotion.
33+
primary_psql("CREATE TABLE drop_tbl (d text)");
34+
primary_psql("INSERT INTO drop_tbl VALUES ('in primary')");
35+
3236
primary_psql("CHECKPOINT");
3337

3438
RewindTest::create_standby($test_mode);
@@ -66,6 +70,9 @@ sub run_test
6670
primary_psql("DELETE FROM tail_tbl WHERE id > 10");
6771
primary_psql("VACUUM tail_tbl");
6872

73+
# Drop drop_tbl. pg_rewind should copy it back.
74+
primary_psql("DROP TABLE drop_tbl");
75+
6976
# Before running pg_rewind, do a couple of extra tests with several
7077
# option combinations. As the code paths taken by those tests
7178
# do not change for the "local" and "remote" modes, just run them
@@ -154,6 +161,12 @@ sub run_test
154161
),
155162
'tail-copy');
156163

164+
check_query(
165+
'SELECT * FROM drop_tbl',
166+
qq(in primary
167+
),
168+
'drop');
169+
157170
# Permissions on PGDATA should be default
158171
SKIP:
159172
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp