0002-async-avoid-pallocs-in-critical-section-v3.patch
application/octet-stream
Filename: 0002-async-avoid-pallocs-in-critical-section-v3.patch
Type: application/octet-stream
Part: 1
From 7fa517cd8767cd69aa820bb74173880e282e5a38 Mon Sep 17 00:00:00 2001
From: Joel Jacobson <joel@compiler.org>
Date: Tue, 25 Nov 2025 10:10:51 +0100
Subject: [PATCH 2/3] Move asyncQueueAdvanceTail from AtCommit to PreCommit
---
src/backend/commands/async.c | 33 +++++++++++++++------------------
1 file changed, 15 insertions(+), 18 deletions(-)
diff --git a/src/backend/commands/async.c b/src/backend/commands/async.c
index 37526c7b726..ea6ea9e09a8 100644
--- a/src/backend/commands/async.c
+++ b/src/backend/commands/async.c
@@ -981,6 +981,21 @@ PreCommit_Notify(void)
LWLockRelease(NotifyQueueLock);
}
+ /*
+ * If it's time to try to advance the global tail pointer, do that.
+ *
+ * (It might seem odd to do this in the sender, when more than likely the
+ * listeners won't yet have read the messages we just sent. However,
+ * there's less contention if only the sender does it, and there is little
+ * need for urgency in advancing the global tail. So this typically will
+ * be clearing out messages that were sent some time ago.)
+ */
+ if (tryAdvanceTail)
+ {
+ tryAdvanceTail = false;
+ asyncQueueAdvanceTail();
+ }
+
/* Note that we don't clear pendingNotifies; AtCommit_Notify will. */
}
}
@@ -1046,21 +1061,6 @@ AtCommit_Notify(void)
if (pendingNotifies != NULL)
SignalBackends();
- /*
- * If it's time to try to advance the global tail pointer, do that.
- *
- * (It might seem odd to do this in the sender, when more than likely the
- * listeners won't yet have read the messages we just sent. However,
- * there's less contention if only the sender does it, and there is little
- * need for urgency in advancing the global tail. So this typically will
- * be clearing out messages that were sent some time ago.)
- */
- if (tryAdvanceTail)
- {
- tryAdvanceTail = false;
- asyncQueueAdvanceTail();
- }
-
/* And clean up */
ClearPendingActionsAndNotifies();
}
@@ -2131,9 +2131,6 @@ asyncQueueProcessPageEntries(QueuePosition *current,
/*
* Advance the shared queue tail variable to the minimum of all the
* per-backend tail pointers. Truncate pg_notify space if possible.
- *
- * This is (usually) called during CommitTransaction(), so it's important for
- * it to have very low probability of failure.
*/
static void
asyncQueueAdvanceTail(void)
--
2.50.1