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

Commitec4b975

Browse files
Reset hot standby xmin on master after restart
Hot_standby_feedback could be reset by reload and worked correctly, but ifthe server was restarted rather than reloaded the xmin was not reset.Force reset always if hot_standby_feedback is enabled at startup.Ants Aasma, Craig RingerReported-by: Ants Aasma
1 parent9d4ca01 commitec4b975

File tree

2 files changed

+34
-8
lines changed

2 files changed

+34
-8
lines changed

‎src/backend/replication/walreceiver.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,7 +1167,10 @@ XLogWalRcvSendReply(bool force, bool requestReply)
11671167
* in case they don't have a watch.
11681168
*
11691169
* If the user disables feedback, send one final message to tell sender
1170-
* to forget about the xmin on this standby.
1170+
* to forget about the xmin on this standby. We also send this message
1171+
* on first connect because a previous connection might have set xmin
1172+
* on a replication slot. (If we're not using a slot it's harmless to
1173+
* send a feedback message explicitly setting InvalidTransactionId).
11711174
*/
11721175
staticvoid
11731176
XLogWalRcvSendHSFeedback(boolimmed)
@@ -1177,7 +1180,8 @@ XLogWalRcvSendHSFeedback(bool immed)
11771180
uint32nextEpoch;
11781181
TransactionIdxmin;
11791182
staticTimestampTzsendTime=0;
1180-
staticboolmaster_has_standby_xmin= false;
1183+
/* initially true so we always send at least one feedback message */
1184+
staticboolmaster_has_standby_xmin= true;
11811185

11821186
/*
11831187
* If the user doesn't want status to be reported to the master, be sure
@@ -1202,14 +1206,17 @@ XLogWalRcvSendHSFeedback(bool immed)
12021206
}
12031207

12041208
/*
1205-
* If Hot Standby is not yet active there is nothing to send. Check this
1206-
* after the interval has expired to reduce number of calls.
1209+
* If Hot Standby is not yet accepting connections there is nothing to
1210+
* send. Check this after the interval has expired to reduce number of
1211+
* calls.
1212+
*
1213+
* Bailing out here also ensures that we don't send feedback until we've
1214+
* read our own replication slot state, so we don't tell the master to
1215+
* discard needed xmin or catalog_xmin from any slots that may exist
1216+
* on this replica.
12071217
*/
12081218
if (!HotStandbyActive())
1209-
{
1210-
Assert(!master_has_standby_xmin);
12111219
return;
1212-
}
12131220

12141221
/*
12151222
* Make the expensive call to get the oldest xmin once we are certain

‎src/test/recovery/t/001_stream_rep.pl

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use warnings;
44
use PostgresNode;
55
use TestLib;
6-
use Test::Moretests=>22;
6+
use Test::Moretests=>24;
77

88
# Initialize master node
99
my$node_master = get_new_node('master');
@@ -161,3 +161,22 @@ sub replay_check
161161
($xmin,$catalog_xmin) = get_slot_xmins($node_standby_1,$slotname_2);
162162
is($xmin,'','cascaded slot xmin null with hs feedback reset');
163163
is($catalog_xmin,'','cascaded slot xmin still null with hs_feedback reset');
164+
165+
diag"re-enabling hot_standby_feedback and disabling while stopped";
166+
$node_standby_2->safe_psql('postgres','ALTER SYSTEM SET hot_standby_feedback = on;');
167+
$node_standby_2->reload;
168+
169+
$node_master->safe_psql('postgres',qq[INSERT INTO tab_int VALUES (11000);]);
170+
replay_check();
171+
172+
$node_standby_2->safe_psql('postgres','ALTER SYSTEM SET hot_standby_feedback = off;');
173+
$node_standby_2->stop;
174+
175+
($xmin,$catalog_xmin) = get_slot_xmins($node_standby_1,$slotname_2);
176+
isnt($xmin,'','cascaded slot xmin non-null with postgres shut down');
177+
178+
# Xmin from a previous run should be cleared on startup.
179+
$node_standby_2->start;
180+
181+
($xmin,$catalog_xmin) = get_slot_xmins($node_standby_1,$slotname_2);
182+
is($xmin,'','cascaded slot xmin reset after startup with hs feedback reset');

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp