2

While understanding the logical replication process, one thing is still not clear to me.

When the decoding process will start?

What is my understanding is, Lets say i have a publication and a slot. But no subscribers. In this case, slots will just maintain the wal info that is required for sync but the actual wal data wont be decoded until a subscriber starts.

Once the subscriber activated then the slot will tell from which wal lsn then the actual decode processing will start.

Please correct if the statement is wrong.

2 Answers 2

0

In logical decoding, a replication slot determines the logical decoding plugin, a restart log sequence number (LSN) and the minimal transaction IDs required for decoding. These correspont to the columns plugin, restart_lsn, xmin, and catalog_xmin in pg_replication_slots.

The replication slot itself does nothing and stores nothing beyond these data. It is a marker that tells PostgreSQL not do discard any WAL that is more recent than the restart_lsn and not to VACUUM away any data more recent than xmin and catalog_xmin.

Decoding only happens when a replication connection is established and the standby sends the replication command START_REPLICATION SLOT slot_name LOGICAL.

So yes, you are correct. While it is the standby that determines from where to replicate in physical streaming replication, in the case of logical replication the starting point is determined by the replication slot.

1
  • Thanks for your answer, I have just done a small poc and got the expected results.
    – TheDataGuy
    Commented Dec 19, 2022 at 8:58
1

I have analyzed it with a small setup. The Decoding process will start after the consumers connected and the state is in active.

To reproduce this,I just disabled the subscription and starting inserting some random bulk data. Then after a few mins enabled the subscription.

You can see the CPU consumption and IOPS consumption after enabling the subscription.

enter image description here

enter image description here

1
  • An experiment is always good. Understanding what is actually going on is key. Commented Dec 19, 2022 at 9:00

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.