8000 Reset hot standby xmin after restart · intobs/postgres@800d89a · GitHub
[go: up one dir, main page]

Skip to content

Commit 800d89a

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 2c1976a commit 800d89a

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
@@ -1098,7 +1098,10 @@ XLogWalRcvSendReply(bool force, bool requestReply)
10981098
* in case they don't have a watch.
10991099
*
11001100
* If the user disables feedback, send one final message to tell sender
1101-
* to forget about the xmin on this standby.
1101+
* to forget about the xmin on this standby. We also send this message
1102+
* on first connect because a previous connection might have set xmin
1103+
* on a replication slot. (If we're not using a slot it's harmless to
1104+
* send a feedback message explicitly setting InvalidTransactionId).
11021105
*/
11031106
static void
11041107
XLogWalRcvSendHSFeedback(bool immed)
@@ -1108,7 +1111,8 @@ XLogWalRcvSendHSFeedback(bool immed)
11081111
uint32 nextEpoch;
11091112
TransactionId xmin;
11101113
static TimestampTz sendTime = 0;
1111-
static bool master_has_standby_xmin = false;
1114+
/* initially true so we always send at least one feedback message */
1115+
static bool master_has_standby_xmin = true;
11121116

11131117
/*
11141118
* If the user doesn't want status to be reported to the master, be sure
@@ -1133,14 +1137,17 @@ XLogWalRcvSendHSFeedback(bool immed)
11331137
}
11341138

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

11451152
/*
11461153
* Make the expensive call to get the oldest xmin once we are certain

0 commit comments

Comments
 (0)
0