Session in aborted transaction misses effective_wal_level change
Session in aborted transaction misses effective_wal_level change
For an aborted transaction, there is today a gap between the AtEOXact_LogicalCtl call and the XID being cleared. If an effective_wal_level change occurs during that gap, the change will be missed. That means the next transaction on that session will not be logically decoded. Attaching a reproducer bash script that demonstrates the missing decoded change. Attaching a fix that moves the AtEOXact_LogicalCtl call later, closing the gap. The issue was observed on master (b69356cd789) and REL_19_STABLE (67c01b84788). It seems it was introduced in 67c20979ce7. repro.sh output without patch: > rows committed: > 1 > 2 > 3 > > changes decoded from slot s: > table public.t: INSERT: a[integer]:1 > table public.t: INSERT: a[integer]:3 repro.sh output with patch: > rows committed: > 1 > 2 > 3 > > changes decoded from slot s: > table public.t: INSERT: a[integer]:1 > table public.t: INSERT: a[integer]:2 > table public.t: INSERT: a[integer]:3 Best regards, Sergei
Re: Session in aborted transaction misses effective_wal_level change
Hi, On Wed, Sep 30, 2026 at 10:19 AM Sergei Patiakin wrote: > > For an aborted transaction, there is today a gap between the > AtEOXact_LogicalCtl call and the XID being cleared. If an > effective_wal_level change occurs during that gap, the change will be > missed. That means the next transaction on that session will not be > logically decoded. > > Attaching a reproducer bash script that demonstrates the missing decoded change. > Attaching a fix that moves the AtEOXact_LogicalCtl call later, closing the gap. Thank you for the report. I agree it's an issue that we should fix for v19. The fix looks good to me. We need to check and update XLogLogicalInfo in every place where we reset the top-level transaction id. I've updated the patch with the regression tests. Please review it. Regards, -- Masahiko Sawada Amazon Web Services: https://aws.amazon.com
RE: Session in aborted transaction misses effective_wal_level change
От:
"Hayato Kuroda (Fujitsu)" <kuroda.hayato@fujitsu.com>
Дата:
Dear Sawada-san, Serigei, Good catch, I have also been seeing and considering the test, but Sawada-san is faster. > The fix looks good to me. We need to check and update XLogLogicalInfo > in every place where we reset the top-level transaction id. > > I've updated the patch with the regression tests. Please review it. Confirmed the test fails on HEAD and pass after the patch. There might be idea to put the function after the "nParallelCurrentXids = 0;" even in the CommitTransaction() and PrepareTransaction(), which is same as CleanupTransaction(). But any places are OK for me. LGTM. Best regards, Hayato Kuroda FUJITSU LIMITED
Re: Session in aborted transaction misses effective_wal_level change
От:
Sergei Patiakin <sergei.patiakin@enterprisedb.com>
Дата:
> I've updated the patch with the regression tests. Please review it. The updated patch looks good, thanks. Best regards, Sergei
Re: Session in aborted transaction misses effective_wal_level change
От:
Shlok Kyal <shlok.kyal.oss@gmail.com>
Дата:
On Thu, 1 Oct 2026 at 08:56, Masahiko Sawada wrote: > > Hi, > > On Wed, Sep 30, 2026 at 10:19 AM Sergei Patiakin > wrote: > > > > For an aborted transaction, there is today a gap between the > > AtEOXact_LogicalCtl call and the XID being cleared. If an > > effective_wal_level change occurs during that gap, the change will be > > missed. That means the next transaction on that session will not be > > logically decoded. > > > > Attaching a reproducer bash script that demonstrates the missing decoded change. > > Attaching a fix that moves the AtEOXact_LogicalCtl call later, closing the gap. > > Thank you for the report. I agree it's an issue that we should fix for v19. > > The fix looks good to me. We need to check and update XLogLogicalInfo > in every place where we reset the top-level transaction id. > > I've updated the patch with the regression tests. Please review it. Hi Sawada-san, Sergei, I am able to reproduce the issue on HEAD and PG19. The patch applies on both the branches and it addresses the issue. Just a minor comment, the patch requires a pgperltidy run. Otherwise patch LGTM. Thanks, Shlok Kyal
Re: Session in aborted transaction misses effective_wal_level change
On Wed, Sep 30, 2026 at 11:28 PM Hayato Kuroda (Fujitsu) wrote: > > Dear Sawada-san, Serigei, > > Good catch, I have also been seeing and considering the test, but Sawada-san is faster. > > > The fix looks good to me. We need to check and update XLogLogicalInfo > > in every place where we reset the top-level transaction id. > > > > I've updated the patch with the regression tests. Please review it. > > Confirmed the test fails on HEAD and pass after the patch. > There might be idea to put the function after the "nParallelCurrentXids = 0;" > even in the CommitTransaction() and PrepareTransaction(), which is same as > CleanupTransaction(). But any places are OK for me. > > LGTM. Thank you for reviewing the patch. I'd rather move AtEOXact_LogicalCtl() to before resetting CurrentResourceOwner. I think it should work fine too and caon deal with your concern. I've attached the updated patch. I'm going to push it on Monday, barring objections. Regards, -- Masahiko Sawada Amazon Web Services: https://aws.amazon.com
Re: Session in aborted transaction misses effective_wal_level change
От:
Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Дата:
Hi Sawada-san, On Fri, Oct 02, 2026 at 01:54:04PM -0700, Masahiko Sawada wrote: > On Wed, Sep 30, 2026 at 11:28 PM Hayato Kuroda (Fujitsu) > wrote: > > > > Dear Sawada-san, Serigei, > > > > Good catch, I have also been seeing and considering the test, but Sawada-san is faster. > > > > > The fix looks good to me. We need to check and update XLogLogicalInfo > > > in every place where we reset the top-level transaction id. > > > > > > I've updated the patch with the regression tests. Please review it. > > > > Confirmed the test fails on HEAD and pass after the patch. > > There might be idea to put the function after the "nParallelCurrentXids = 0;" > > even in the CommitTransaction() and PrepareTransaction(), which is same as > > CleanupTransaction(). But any places are OK for me. > > > > LGTM. > > Thank you for reviewing the patch. > > I'd rather move AtEOXact_LogicalCtl() to before resetting > CurrentResourceOwner. I think it should work fine too and caon deal > with your concern. I wonder if it wouldn't make more sense to keep this after XactTopFullTransactionId is reset, as in v1? Indeed, couldn't a barrier be processed during AtCleanup_Memory(), while the XID is still valid, and set XLogLogicalInfoUpdatePending again after this call? Unless I'm missing something, I don't see AtEOXact_LogicalCtl() itself relying on CurrentResourceOwner. Is there some other reason why it needs to be called before CurrentResourceOwner is reset? Regards, -- Bertrand Drouvot PostgreSQL Contributors Team RDS Open Source Databases Amazon Web Services: https://aws.amazon.com
RE: Session in aborted transaction misses effective_wal_level change
От:
"Hayato Kuroda (Fujitsu)" <kuroda.hayato@fujitsu.com>
Дата:
Dear Bertrand, Sawada-san, > I wonder if it wouldn't make more sense to keep this after > XactTopFullTransactionId > is reset, as in v1? > > Indeed, couldn't a barrier be processed during AtCleanup_Memory(), while the > XID is still valid, and set XLogLogicalInfoUpdatePending again after this call? Per my research the function calls MemoryContextCallResetCallbacks(), which can calls the arbitrary functions from core and extensions. So It's possible that a random callback calls CHECK_FOR_INTERRUPTS() and consumes a barrier. I still prefer to put after resetting the XactTopFullTransactionId. Best regards, Hayato Kuroda FUJITSU LIMITED
Re: Session in aborted transaction misses effective_wal_level change
On Sun, Oct 4, 2026 at 8:35 PM Hayato Kuroda (Fujitsu) wrote: > > Dear Bertrand, Sawada-san, > > > I wonder if it wouldn't make more sense to keep this after > > XactTopFullTransactionId > > is reset, as in v1? > > > > Indeed, couldn't a barrier be processed during AtCleanup_Memory(), while the > > XID is still valid, and set XLogLogicalInfoUpdatePending again after this call? > > Per my research the function calls MemoryContextCallResetCallbacks(), which can > calls the arbitrary functions from core and extensions. So It's possible that a > random callback calls CHECK_FOR_INTERRUPTS() and consumes a barrier. > > I still prefer to put after resetting the XactTopFullTransactionId. > Thank you for the comments. I'm now convinced that we can call it after resetting the top-level XID. I was concerned about the inconsistency between the AtEOXact_LogicalCtl() calls in CommitTransaction() and CleanupTransaction(), but it's fine for them to differ, since we're holding interrupts in the former but not in the latter. Calling AtEOXact_LogicalCtl() after resetting the top-level XID would be more bullet-proof, so let's go with this approach. I've attached the updated patch. Please review it. Regards, -- Masahiko Sawada Amazon Web Services: https://aws.amazon.com
Re: Session in aborted transaction misses effective_wal_level change
От:
Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Дата:
Hi Sawada-san, On Mon, Oct 05, 2026 at 11:01:50AM -0700, Masahiko Sawada wrote: > On Sun, Oct 4, 2026 at 8:35 PM Hayato Kuroda (Fujitsu) > wrote: > > > > Dear Bertrand, Sawada-san, > > > > > I wonder if it wouldn't make more sense to keep this after > > > XactTopFullTransactionId > > > is reset, as in v1? > > > > > > Indeed, couldn't a barrier be processed during AtCleanup_Memory(), while the > > > XID is still valid, and set XLogLogicalInfoUpdatePending again after this call? > > > > Per my research the function calls MemoryContextCallResetCallbacks(), which can > > calls the arbitrary functions from core and extensions. So It's possible that a > > random callback calls CHECK_FOR_INTERRUPTS() and consumes a barrier. > > > > I still prefer to put after resetting the XactTopFullTransactionId. > > > > Thank you for the comments. I'm now convinced that we can call it > after resetting the top-level XID. I was concerned about the > inconsistency between the AtEOXact_LogicalCtl() calls in > CommitTransaction() and CleanupTransaction(), but it's fine for them > to differ, since we're holding interrupts in the former but not in the > latter. Calling AtEOXact_LogicalCtl() after resetting the top-level > XID would be more bullet-proof, so let's go with this approach. Yeah, thanks! > I've attached the updated patch. Please review it. LGTM. Regards, -- Bertrand Drouvot PostgreSQL Contributors Team RDS Open Source Databases Amazon Web Services: https://aws.amazon.com
RE: Session in aborted transaction misses effective_wal_level change
От:
"Hayato Kuroda (Fujitsu)" <kuroda.hayato@fujitsu.com>
Дата:
Dear Sawada-san, > Thank you for the comments. I'm now convinced that we can call it > after resetting the top-level XID. I was concerned about the > inconsistency between the AtEOXact_LogicalCtl() calls in > CommitTransaction() and CleanupTransaction(), but it's fine for them > to differ, since we're holding interrupts in the former but not in the > latter. Calling AtEOXact_LogicalCtl() after resetting the top-level > XID would be more bullet-proof, so let's go with this approach. > > I've attached the updated patch. Please review it. Understood, LGTM. Best regards, Hayato Kuroda FUJITSU LIMITED
Re: Session in aborted transaction misses effective_wal_level change
От:
Sergei Patiakin <sergei.patiakin@enterprisedb.com>
Дата:
Hi Masahiko, > I've attached the updated patch. Please review it. Looks good. I confirmed the v3 test changes fail on `master` and pass with the v3 code changes. Best regards, Sergei
Re: Session in aborted transaction misses effective_wal_level change
От:
Masahiko Sawada <sawada.mshk@gmail.com>
Дата:
On Tue, Oct 6, 2026 at 2:19 AM Sergei Patiakin wrote: > > Hi Masahiko, > > > I've attached the updated patch. Please review it. > > Looks good. I confirmed the v3 test changes fail on `master` and pass > with the v3 code changes. > Thank you for reviewing the patch! Pushed. Regards, -- Masahiko Sawada Amazon Web Services: https://aws.amazon.com