Add wait event for CommitDelay
Hello there,
So, my colleague Ants Aasma found that a wait_event is missing for
CommitDelay. This just looks like it was missed, please enlighten if it is
left out intentionally.
For now, I worked on this patch to add it.
--
Regards,
Rafia Sabih
CYBERTEC PostgreSQL International GmbH
Attachments:
0001-Add-WAIT_EVENT-for-CommitDelay.patchapplication/octet-stream; name=0001-Add-WAIT_EVENT-for-CommitDelay.patchDownload
From 00713939d3fe41c405ba989a9a3f5bbb13fb015c Mon Sep 17 00:00:00 2001
From: Rafia Sabih <rafia.sabih@cybertec.at>
Date: Thu, 4 Dec 2025 19:05:05 +0100
Subject: [PATCH] Add WAIT_EVENT for CommitDelay
---
src/backend/access/transam/xlog.c | 2 ++
src/backend/utils/activity/wait_event_names.txt | 1 +
2 files changed, 3 insertions(+)
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index 22d0a2e8c3a..76a3a875679 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -2884,7 +2884,9 @@ XLogFlush(XLogRecPtr record)
if (CommitDelay > 0 && enableFsync &&
MinimumActiveBackends(CommitSiblings))
{
+ pgstat_report_wait_start(WAIT_EVENT_COMMIT_DELAY);
pg_usleep(CommitDelay);
+ pgstat_report_wait_end();
/*
* Re-check how far we can now flush the WAL. It's generally not
diff --git a/src/backend/utils/activity/wait_event_names.txt b/src/backend/utils/activity/wait_event_names.txt
index 1e5e368a5dc..a0130105fe1 100644
--- a/src/backend/utils/activity/wait_event_names.txt
+++ b/src/backend/utils/activity/wait_event_names.txt
@@ -180,6 +180,7 @@ RECOVERY_APPLY_DELAY "Waiting to apply WAL during recovery because of a delay se
RECOVERY_RETRIEVE_RETRY_INTERVAL "Waiting during recovery when WAL data is not available from any source (<filename>pg_wal</filename>, archive or stream)."
REGISTER_SYNC_REQUEST "Waiting while sending synchronization requests to the checkpointer, because the request queue is full."
SPIN_DELAY "Waiting while acquiring a contended spinlock."
+COMMIT_DELAY "Waiting while pre commit."
VACUUM_DELAY "Waiting in a cost-based vacuum delay point."
VACUUM_TRUNCATE "Waiting to acquire an exclusive lock to truncate off any empty pages at the end of a table vacuumed."
WAL_SUMMARIZER_ERROR "Waiting after a WAL summarizer error."
--
2.39.5 (Apple Git-154)
Hi,
So, my colleague Ants Aasma found that a wait_event is missing for CommitDelay.
This just looks like it was missed, please enlighten if it is left out intentionally.
I do not know if it was left out intentionally, there are no comments on that
matter.
I am not sure how widely used this GUC is, but from the quick test that I
did using pgench TPC-B workload with 50 clients, it seems useful
since a DBA can set commit_delay too high and you will easily observe
a single backend constantly in this delay which will impact tps.
It's good to show this clearly as a wait event.
As far as the patch goes, It makes sense to put this under "WaitEventTimeout",
but it should be placed after CHECKPOINT_WRITE_DELAY in
alphabetical order, and the description could be improved a bit.
How about? "Waiting for the commit delay before WAL flush."
--
Sami Imseih
Amazon Web Services (AWS)
On Fri, Dec 05, 2025 at 10:15:19AM -0600, Sami Imseih wrote:
I am not sure how widely used this GUC is, but from the quick test that I
did using pgench TPC-B workload with 50 clients, it seems useful
since a DBA can set commit_delay too high and you will easily observe
a single backend constantly in this delay which will impact tps.
It's good to show this clearly as a wait event.
I have never used it myself, but I can see why it could be useful for
monitoring here. No objections to this addition here.
As far as the patch goes, It makes sense to put this under "WaitEventTimeout",
but it should be placed after CHECKPOINT_WRITE_DELAY in
alphabetical order, and the description could be improved a bit.
How about? "Waiting for the commit delay before WAL flush."
Yes, your description is more useful than what the patch is proposing.
--
Michael
On Fri, 5 Dec 2025 at 17:15, Sami Imseih <samimseih@gmail.com> wrote:
Hi,
So, my colleague Ants Aasma found that a wait_event is missing for
CommitDelay.
This just looks like it was missed, please enlighten if it is left out
intentionally.
I do not know if it was left out intentionally, there are no comments on
that
matter.I am not sure how widely used this GUC is, but from the quick test that I
did using pgench TPC-B workload with 50 clients, it seems useful
since a DBA can set commit_delay too high and you will easily observe
a single backend constantly in this delay which will impact tps.
It's good to show this clearly as a wait event.As far as the patch goes, It makes sense to put this under
"WaitEventTimeout",
but it should be placed after CHECKPOINT_WRITE_DELAY in
alphabetical order, and the description could be improved a bit.
How about? "Waiting for the commit delay before WAL flush."Thanks for the review of the patch. Please find the attachment for the
updated version.
--
Regards,
Rafia Sabih
CYBERTEC PostgreSQL International GmbH
Attachments:
0002-Add-WAIT_EVENT-for-CommitDelay.patchapplication/octet-stream; name=0002-Add-WAIT_EVENT-for-CommitDelay.patchDownload
From e6bac7a4a7de597dada842834e510464631654a2 Mon Sep 17 00:00:00 2001
From: Rafia Sabih <rafia.sabih@cybertec.at>
Date: Mon, 8 Dec 2025 16:15:57 +0100
Subject: [PATCH] Add wait event for CommitDelay
---
src/backend/access/transam/xlog.c | 2 ++
src/backend/utils/activity/wait_event_names.txt | 1 +
2 files changed, 3 insertions(+)
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index 22d0a2e8c3a..76a3a875679 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -2884,7 +2884,9 @@ XLogFlush(XLogRecPtr record)
if (CommitDelay > 0 && enableFsync &&
MinimumActiveBackends(CommitSiblings))
{
+ pgstat_report_wait_start(WAIT_EVENT_COMMIT_DELAY);
pg_usleep(CommitDelay);
+ pgstat_report_wait_end();
/*
* Re-check how far we can now flush the WAL. It's generally not
diff --git a/src/backend/utils/activity/wait_event_names.txt b/src/backend/utils/activity/wait_event_names.txt
index 1e5e368a5dc..469fa365636 100644
--- a/src/backend/utils/activity/wait_event_names.txt
+++ b/src/backend/utils/activity/wait_event_names.txt
@@ -175,6 +175,7 @@ Section: ClassName - WaitEventTimeout
BASE_BACKUP_THROTTLE "Waiting during base backup when throttling activity."
CHECKPOINT_WRITE_DELAY "Waiting between writes while performing a checkpoint."
+COMMIT_DELAY "Waiting for the commit delay before WAL flush."
PG_SLEEP "Waiting due to a call to <function>pg_sleep</function> or a sibling function."
RECOVERY_APPLY_DELAY "Waiting to apply WAL during recovery because of a delay setting."
RECOVERY_RETRIEVE_RETRY_INTERVAL "Waiting during recovery when WAL data is not available from any source (<filename>pg_wal</filename>, archive or stream)."
--
2.39.5 (Apple Git-154)
Thanks for the review of the patch. Please find the attachment for the updated version.
Thanks! v2 LGTM
--
Sami Imseih
Amazon Web Services (AWS)