0

I have seen in source code (https://github.com/postgres/postgres/blob/914e72e6e8d3e94346f3495dac36d46aa9912bb5/src/backend/replication/walreceiver.c#L1191) regarding XLogWalRcvSendHSFeedback function it computes the oldest xmin and sends it to the wal sender of primary.

But my question is..

Does WAL receiver process send any information regarding snapshots of the queries(select queries) in standby to WAL sender of primary to delay the vaccuum process?.If yes,how?possible share the source code reference.

1 Answer 1

2

You are looking at an old version of the source code, but this has not changed fundamentally. The standby loops through all sessions, and for those that have a snapshot or an open transaction, it will consider backend_xid and backend_xmin (as shown in pg_stat_activity) and calculate the minimum of these. If there are any replication slots with older xmin or catalog_xmin, they are also taken into account.

See the function ComputeXidHorizons() in src/backend/storage/ipc/procarray.c.

7
  • Currently we are using PostgreSQL version 11.From your answer can i conclude and understand that standby will also consider the snapshot data [xmin:xmax:xip_list] of select queries in determining the oldest xmin that needs to be reported to primary to delay vacuum?
    – manjunath
    Jul 10, 2023 at 9:43
  • Yes, that's the idea. We cannot remove any data on the standby that are still needed for queries, unless we cancel those queries. Jul 10, 2023 at 10:53
  • Consider a situation where hot_standby_feedback is off and i have physical replication slot in primary.Does the primary still knows about the taken snapshot data of select queries?I am asking this question because replication slots aids in preventing the removal of rows which are required by standby right?
    – manjunath
    Jul 11, 2023 at 12:13
  • No, not at all. A replication slot keeps the primary from discarding WAL that is still needed for replication. That is completely unrelated. Jul 11, 2023 at 12:22
  • Then can i understand that when hot_standby_feedback is off and even if i have replication slot,auto vacuum can remove the rows which are required by select queries?
    – manjunath
    Jul 11, 2023 at 12:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.