How to check for in-progress transactions - Mailing list pgsql-hackers

From Tejasvi Kashi
Subject How to check for in-progress transactions
Date
Msg-id CAJWWkarMfiCaD_+NQ2-zRtcfW1g29mhc6W6VT5Q=VUjj_uJKLQ@mail.gmail.com
Whole thread Raw
Responses Re: How to check for in-progress transactions  (Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>)
List pgsql-hackers
Hi everyone,

I'm Tej, a grad student poking around postgres for a project.

For my use case, I'm trying to ascertain if there are any in-flight transactions that are yet to be replicated to synchronous standbys (in a synchronous streaming replication setting)

The first way to do this would be to check the WalSndCtl->lsn[] array to see if the current max lsn of the system has replicated or not. This works well when postgres is running and being actively used. However, when postgres has just started up, WalSndCtl->lsn[] values could be 0, but there could still be transactions waiting to replicate.

The second way to do it would be to scan ProcGlobal to check for active xids. However, the issue is that I'm calling ProcArrayEndTransaction() before calling SyncRepWaitForLSN() to ensure that the transaction becomes visible to other transactions before it begins to wait in the SyncRep queue. 

So, with this change, if I scan ProcGlobal, I would not see transactions that have been committed locally but are yet to be replicated to synchronous standbys because ProcArrayEndTransaction() would have marked the transaction as completed.

I've been looking at sent_lsn, write_lsn, flush_lsn etc., of the walsender, but with no success. Considering the visibility change added above, is there a way for me to check for transactions that have been committed locally but are waiting for replication?

I would appreciate it if someone could point me in the right direction!

Sincerely,

Tej Kashi
MMath CS, University of Waterloo
Waterloo, ON, CA



pgsql-hackers by date:

Previous
From: "Gregory Stark (as CFM)"
Date:
Subject: Re: Commitfest 2023-03 starting tomorrow!
Next
From: Mikhail Gribkov
Date:
Subject: Re: On login trigger: take three