Which is the last write on primary that is replicated to the standby?

I am setting up streaming replication with three nodes using the PostgreSQL Percona distribution. My goal is to measure the performance of the replication by calculating how much extra time the secondary server takes to reach a consistent state after the primary server finishes its work.

As shown in the image, I calculate synchronization time by measuring the difference between the commit time on the primary server and the time the secondary server comes to a consistent state. Currently, I am using the commit time on the primary server as the “finishing point.”

However, after every commit, the primary server performs six additional writes, i don’t know which of them are replicated to the secondary server. I’ve categorized these writes as the “dying phase” in the image.

My concern is: what are those six writes? what if one of these six writes represents the true “end” of the operation on the primary server? If that’s the case, my synchronization time calculation could be off and should be reduced further, right?

I want to confirm if my current understanding of the primary server’s “finishing point” is accurate or if I should consider one of these six writes as the actual end for better measurement.

You may consider, those next writes are technically negligible for the performance calculation. Because they are happening in the next milli seconds. But i need to know what are those writes.

Hi,

For the sake of a constructive response, I’m going to assume you’re using postgres 16.

I suggest you start by reviewing the documentation regarding runtime parameters synchronous_commit and log_replication_commands respectively.

Instead of reading the PRIMARY logs, read the REPLICA logs instead.

Hope this helps.