Skip to content

Commit 048d441

Browse files
Reset hot standby xmin after restart
Hot_standby_feedback could be reset by reload and worked correctly, but if the 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 Ringer Reported-by: Ants Aasma
1 parent 2e024f8 commit 048d441

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/backend/replication/walreceiver.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,7 +1095,10 @@ XLogWalRcvSendReply(bool force, bool requestReply)
10951095
* in case they don't have a watch.
10961096
*
10971097
* If the user disables feedback, send one final message to tell sender
1098-
* to forget about the xmin on this standby.
1098+
* to forget about the xmin on this standby. We also send this message
1099+
* on first connect because a previous connection might have set xmin
1100+
* on a replication slot. (If we're not using a slot it's harmless to
1101+
* send a feedback message explicitly setting InvalidTransactionId).
10991102
*/
11001103
static void
11011104
XLogWalRcvSendHSFeedback(bool immed)
@@ -1105,7 +1108,8 @@ XLogWalRcvSendHSFeedback(bool immed)
11051108
uint32 nextEpoch;
11061109
TransactionId xmin;
11071110
static TimestampTz sendTime = 0;
1108-
static bool master_has_standby_xmin = false;
1111+
/* initially true so we always send at least one feedback message */
1112+
static bool master_has_standby_xmin = true;
11091113

11101114
/*
11111115
* If the user doesn't want status to be reported to the master, be sure
@@ -1130,14 +1134,17 @@ XLogWalRcvSendHSFeedback(bool immed)
11301134
}
11311135

11321136
/*
1133-
* If Hot Standby is not yet active there is nothing to send. Check this
1134-
* after the interval has expired to reduce number of calls.
1137+
* If Hot Standby is not yet accepting connections there is nothing to
1138+
* send. Check this after the interval has expired to reduce number of
1139+
* calls.
1140+
*
1141+
* Bailing out here also ensures that we don't send feedback until we've
1142+
* read our own replication slot state, so we don't tell the master to
1143+
* discard needed xmin or catalog_xmin from any slots that may exist
1144+
* on this replica.
11351145
*/
11361146
if (!HotStandbyActive())
1137-
{
1138-
Assert(!master_has_standby_xmin);
11391147
return;
1140-
}
11411148

11421149
/*
11431150
* Make the expensive call to get the oldest xmin once we are certain

0 commit comments

Comments
 (0)