Hello, Andrey Borodin wrote: > Could we reuse the debug nesting check to collect inner/outer call > sites over a check-world run
I changed the check to record the pairs instead of aborting, and ran meson test with TAP and injection points enabled. On master (b0496e30830) no wait event was started while another one was set. With the logging events added, a log write happened inside a wait in six processes: once in quickdie() during ClientRead, and five times in injection_wait() when the process was canceled or terminated. In all six the outer wait ends there, by ERROR or process exit. Andres Freund wrote: > If there are places where wait events clear an exising wait event, > that code needs to be fixed. Understood. v11 drops the swap and the Windows part. It is a single patch with plain pgstat_report_wait_start()/end() around the log writes. This means an extension that logs inside its own wait and keeps waiting loses that wait event, which is what Nikolay's harness showed with v8. -- Best regards, Seongjun
From 415cdd93c31c8eaecc8b80a0866582e2ff425691 Mon Sep 17 00:00:00 2001 From: Seongjun Shin <[email protected]> Date: Sat, 14 Nov 2026 18:45:09 +0900 Subject: [PATCH v11] Add wait events for server logging destination writes Writing server log output can block: write(2) to the syslogger pipe once the pipe is full, write(2) to stderr when the output device is slow, and syslog(3) or openlog(3) when the system logger is slow. In all these cases pg_stat_activity showed wait_event as NULL. This adds three wait events for these calls: IO / SysloggerWrite - write(2) to the syslogger pipe. IO / StderrWrite - write(2) to stderr. IO / SyslogWrite - syslog(3) and openlog(3). Author: Seongjun Shin <[email protected]> Reviewed-by: Kirk Wolak <[email protected]> Reviewed-by: Kyotaro Horiguchi <[email protected]> Reviewed-by: Michael Paquier <[email protected]> Reviewed-by: Andrey Borodin <[email protected]> Reviewed-by: Henson Choi <[email protected]> Reviewed-by: Nikolay Samokhvalov <[email protected]> Reviewed-by: Jihyun Bahn <[email protected]> Reviewed-by: Jakub Wartak <[email protected]> Tested-by: Nikolay Samokhvalov <[email protected]> Tested-by: Jihyun Bahn <[email protected]> Tested-by: Jakub Wartak <[email protected]> Discussion: https://postgr.es/m/cacdn0m78u+gvpqa7oey-ga7ffsym636adp6h9fvvcztv9zx...@mail.gmail.com --- src/backend/utils/activity/wait_event_names.txt | 3 +++ src/backend/utils/error/elog.c | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/backend/utils/activity/wait_event_names.txt b/src/backend/utils/activity/wait_event_names.txt index 112873dc46b..f6ade4300c7 100644 --- a/src/backend/utils/activity/wait_event_names.txt +++ b/src/backend/utils/activity/wait_event_names.txt @@ -260,6 +260,9 @@ SLRU_WRITE "Waiting for a write of an SLRU page." SNAPBUILD_READ "Waiting for a read of a serialized historical catalog snapshot." SNAPBUILD_SYNC "Waiting for a serialized historical catalog snapshot to reach durable storage." SNAPBUILD_WRITE "Waiting for a write of a serialized historical catalog snapshot." +STDERR_WRITE "Waiting for a write to the server's standard error stream." +SYSLOGGER_WRITE "Waiting for a write to the syslogger pipe." +SYSLOG_WRITE "Waiting for a write to the system logger (syslog), including connection setup." TIMELINE_HISTORY_FILE_SYNC "Waiting for a timeline history file received via streaming replication to reach durable storage." TIMELINE_HISTORY_FILE_WRITE "Waiting for a write of a timeline history file received via streaming replication." TIMELINE_HISTORY_READ "Waiting for a read of a timeline history file." diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c index e215ed053ff..d8e440a83f8 100644 --- a/src/backend/utils/error/elog.c +++ b/src/backend/utils/error/elog.c @@ -89,6 +89,7 @@ #include "utils/pg_locale.h" #include "utils/ps_status.h" #include "utils/varlena.h" +#include "utils/wait_event.h" /* In this module, access gettext() via err_gettext() */ @@ -2837,9 +2838,11 @@ write_syslog(int level, const char *line) /* Open syslog connection if not done yet */ if (!openlog_done) { + pgstat_report_wait_start(WAIT_EVENT_SYSLOG_WRITE); openlog(syslog_ident ? syslog_ident : "postgres", LOG_PID | LOG_NDELAY | LOG_NOWAIT, syslog_facility); + pgstat_report_wait_end(); openlog_done = true; } @@ -2912,10 +2915,12 @@ write_syslog(int level, const char *line) chunk_nr++; + pgstat_report_wait_start(WAIT_EVENT_SYSLOG_WRITE); if (syslog_sequence_numbers) syslog(level, "[%lu-%d] %s", seq, chunk_nr, buf); else syslog(level, "[%d] %s", chunk_nr, buf); + pgstat_report_wait_end(); line += buflen; len -= buflen; @@ -2924,10 +2929,12 @@ write_syslog(int level, const char *line) else { /* message short enough */ + pgstat_report_wait_start(WAIT_EVENT_SYSLOG_WRITE); if (syslog_sequence_numbers) syslog(level, "[%lu] %s", seq, line); else syslog(level, "%s", line); + pgstat_report_wait_end(); } } #endif /* HAVE_SYSLOG */ @@ -3112,7 +3119,9 @@ write_console(const char *line, int len) * We ignore any error from write() here. We have no useful way to report * it ... certainly whining on stderr isn't likely to be productive. */ + pgstat_report_wait_start(WAIT_EVENT_STDERR_WRITE); rc = write(fileno(stderr), line, len); + pgstat_report_wait_end(); (void) rc; } @@ -3959,7 +3968,9 @@ write_pipe_chunks(char *data, int len, int dest) /* no need to set PIPE_PROTO_IS_LAST yet */ p.proto.len = PIPE_MAX_PAYLOAD; memcpy(p.proto.data, data, PIPE_MAX_PAYLOAD); + pgstat_report_wait_start(WAIT_EVENT_SYSLOGGER_WRITE); rc = write(fd, &p, PIPE_HEADER_SIZE + PIPE_MAX_PAYLOAD); + pgstat_report_wait_end(); (void) rc; data += PIPE_MAX_PAYLOAD; len -= PIPE_MAX_PAYLOAD; @@ -3969,7 +3980,9 @@ write_pipe_chunks(char *data, int len, int dest) p.proto.flags |= PIPE_PROTO_IS_LAST; p.proto.len = len; memcpy(p.proto.data, data, len); + pgstat_report_wait_start(WAIT_EVENT_SYSLOGGER_WRITE); rc = write(fd, &p, PIPE_HEADER_SIZE + len); + pgstat_report_wait_end(); (void) rc; } -- 2.50.1 (Apple Git-155)
