public inbox for [email protected]
help / color / mirror / Atom feedFrom: SATYANARAYANA NARLAPURAM <[email protected]>
To: PostgreSQL Hackers <[email protected]>
To: Amit Kapila <[email protected]>
Subject: [Patch]: Fix excessive ProcArrayLock acquisitions with subscription max_retention_duration=0
Date: Mon, 27 Apr 2026 01:41:18 -0700
Message-ID: <CAHg+QDdKVnCLHot=AcoPpEiSyDzGz7wGYjAFHVOw57oDtmUDWQ@mail.gmail.com> (raw)
Hi Hackers,
When a subscription has retain_dead_tuples enabled with maxretention set
to zero (unlimited retention), adjust_xid_advance_interval() caps
xid_advance_interval to Min(interval, maxretention). Since maxretention
is zero, this always collapses the interval to zero milliseconds.
A zero makes TimestampDifferenceExceeds(last_time, now, 0) always
true in get_candidate_xid(). This causes the apply worker to call
GetOldestActiveTransactionId() on every single WAL message. This results in
a huge number of ProcArrayLock acquisitions under moderate write load.
Fix by adding a maxretention > 0 guard to the cap. When maxretention is
zero ,
the exponential back-off in adjust_xid_advance_interval()
now works correctly, growing the interval from 100 ms toward the 180 s
ceiling.
Measured with perf uprobe counting GetOldestActiveTransactionId calls
at ~39K TPS (pgbench, 5 clients):
Before fix: 25,104 calls / 5 s (~5,021/s)
After fix: 31 calls / 5 s (~6/s)
Thank
Satya
Attachments:
[application/octet-stream] 0001-Fix-apply-worker-busy-loop-when-subscription-max_ret.patch (1.9K, 3-0001-Fix-apply-worker-busy-loop-when-subscription-max_ret.patch)
download | inline diff:
From dfa89aba06742428fe56a263a9236b862b14e34b Mon Sep 17 00:00:00 2001
From: Satya Narlapuram <[email protected]>
Date: Mon, 27 Apr 2026 08:17:42 +0000
Subject: [PATCH] Fix apply worker busy loop when subscription
max_retention_duration is zero
When a subscription has retain_dead_tuples enabled with maxretention set
to zero (unlimited retention), adjust_xid_advance_interval() caps
xid_advance_interval to Min(interval, maxretention). Since maxretention
is zero, this always collapses the interval to zero milliseconds.
A zero internal makes TimestampDifferenceExceeds(last_time, now, 0)
always true in get_candidate_xid(). This causes the apply worker to call
GetOldestActiveTransactionId() on every single WAL message. This results
in a huge number of ProcArrayLock acquisitions under moderate write load.
Fix by adding a maxretention > 0 guard to the cap. When maxretention is zero,
the exponential back-off in adjust_xid_advance_interval() now works
correctly, growing the interval from 100 ms toward the 180 s ceiling.
---
src/backend/replication/logical/worker.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/src/backend/replication/logical/worker.c b/src/backend/replication/logical/worker.c
index 9f2a16b1..dd6fc38a 100644
--- a/src/backend/replication/logical/worker.c
+++ b/src/backend/replication/logical/worker.c
@@ -4997,9 +4997,10 @@ adjust_xid_advance_interval(RetainDeadTuplesData *rdt_data, bool new_xid_found)
/*
* Ensure the wait time remains within the maximum retention time limit
- * when retention is active.
+ * when retention is active. Skip this cap when maxretention is zero.
*/
- if (MySubscription->retentionactive)
+ if (MySubscription->retentionactive && MySubscription->maxretention > 0)
rdt_data->xid_advance_interval = Min(rdt_data->xid_advance_interval,
MySubscription->maxretention);
}
--
2.43.0
view thread (7+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected], [email protected]
Subject: Re: [Patch]: Fix excessive ProcArrayLock acquisitions with subscription max_retention_duration=0
In-Reply-To: <CAHg+QDdKVnCLHot=AcoPpEiSyDzGz7wGYjAFHVOw57oDtmUDWQ@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox