Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wTjPy-000ieJ-1Z for pgsql-hackers@arkaria.postgresql.org; Sun, 31 May 2026 16:53:42 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wTjPx-007p8L-07 for pgsql-hackers@arkaria.postgresql.org; Sun, 31 May 2026 16:53:41 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wTjPw-007p8D-2H for pgsql-hackers@lists.postgresql.org; Sun, 31 May 2026 16:53:41 +0000 Received: from mail-wm1-x329.google.com ([2a00:1450:4864:20::329]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wTjPu-00000000VKx-2fid for pgsql-hackers@lists.postgresql.org; Sun, 31 May 2026 16:53:40 +0000 Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-4906869f0cbso82740815e9.1 for ; Sun, 31 May 2026 09:53:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1780246417; cv=none; d=google.com; s=arc-20240605; b=Iu1s1Q90hkjJ1pkyp9WNbaoxUCoaAvHGwlRxauFSIOts2LmcVtkLwIO+rg0vHbXi6U nZftQeROGsWlTTQKKQ+Zx3cE/bemWdqGpOWc+Q73wh8iOeSh54/QOcbnuSa4p/ipM9Er KGMqS2N4tYXYxmcsGo1Lkd1iaK7SgUAckDLwTdtSZPlf7tvhakXPtqfqkroyYs6J/Q/a HiEyBlm26BdfgPvx/7sH8GRsu6LWCpS/UwIVydAL4eT6NsYpXBZCLq5UCrEf79sa6LMB 472P3lCY+Y8c6czFxwftNOu9M6RaxKaVpx8Y5O825Xqx3DF9Op5Xx4qE+RQhovktb8jh rR0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=TuYxqltBlSf30FR81jyU060259wXAm+Z3bxZjQzv7mU=; fh=NIH6W/IvF4zKNDazWZcO7WvyQxkekVHXat99D/wSJ/I=; b=bUl7+dJJOClK6l/YAS/wxajOl37hs4ZPgOiy2p7sQQ6xNGxpYe2LtxFh7hvz315Fo/ 5ZVYhYjk7IgpIjS18CVB0vpNirHSIDvXJRJopgNk7MXi/a7yBj0Bw5IckJ2s7/nEouDf IkjNoGQ0GA/748SPDdsSllNTl9wfjvqgjsSt/ct14L1lr1FfCupKAWosCEKSlAy/3p53 EgcPdfEx+Us0PEOd0jCX3VNRO2mY306eWjrFQc0ynW9u3Qw4TRecBiYTnODCZdUZjWOL K1mPL85DhpXzjU1qajdG0/ESYcQft1OXm9ApTvfR+3+tya2vHNpKaDJDMbsfJcjImpVJ OEzg==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1780246417; x=1780851217; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=TuYxqltBlSf30FR81jyU060259wXAm+Z3bxZjQzv7mU=; b=S10JodU/kBI9NhJsgvMJxuGQQ7rp/tiq2W/7d1yabx7gHSeFCgY0vbeArqhXlkc5zI LkLFvsfDKHr90ki0I/uBAc+w62GC+/enC6Qkt+dmTdr+8Z5c7JfeuTDgF0b7U9Tcg9AL EZ50i9Q5xC9HrC/KJbTwlhoCTDf8oPcjP5kIqExcL8hVXXsBHNPjw+PlhBf+Ku1o9Wco JTbnFPZdf/dY5S2YZnlPRN6h/uznR4ADiVvrqRG01yOUkRauNwmsHEc2dGyslJzWjqRk dDmS7HaTcr7oaL45WmUMWHXxxNMIYFmvI8esOw6DSVUjlAAXLBJRl+rGHtd537jv1Zgk GaCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780246417; x=1780851217; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=TuYxqltBlSf30FR81jyU060259wXAm+Z3bxZjQzv7mU=; b=j4+etFi02HGo+/VCDmftAL4XNVIDD/xcmQfiX/kzVms+7D5+01Kz++cpm8wnu6a6HG QalctEyaJGLY3VxuqyPmKcjjAULOo74PcRPYAdfJ/OJUwQIHW5yfFSU6L9tXFoGPWLtr a8Voi4YHDn3MPlEWxOpECaolo0YmzhnQkmnfjHzwuBkbVadXQk+w63rijJfXTOvAs+R1 c0DxoFoZqfA7/QHjuCPHu2+l3PAjhp2wVJR45fBWGkZwwLrmzcLp/Exes2IZWRnzp6ki WDCFwP4n4/UNv154ML3W/jKVjfhVfDSPLLyM1U6X+ruBIvDSqdw+3y3IdMSytQfCFLj+ rS3w== X-Gm-Message-State: AOJu0Yzc6sDzPHWL9XYFIzcq2Ewu+aHrRi78cDT+W9t3aWE8/ADy/pct FgdCQBqtY+zzE8C5W0KqGTunhOtXA1u2QWu7Msghr2if3/hT5j/UIeoAk7CEJqYYQ2nhNIREFzK QPQMtMhs5baCwdOHG2kjB9sPqkRAhrtuvNA== X-Gm-Gg: Acq92OEiAio7a27AHRDLz1mH+sbSHlgzs3Y3H6SCh9lTV0lZi18PFfHT7b1tcxrvOhi n8D0s8bmtnooRs3JxPcVISF3Cvh8e8lC7xg9Y6b1+gJvnqHjiGXRMp8JHFcyK7QvHdHJ6XJrfDN VNTzJrR57hyJJx7qOolTO9i130Przyac9eUaQmMHuC+j//rYi6dNocuq7E7p65SBQRm+Qhao0Cc tmOUuF+/JZALLEWODTbwlUxd5EpTHJBbYdPoYm22/QcC7O0wMUmlM6bv+UW7CHfSawZqyCCdlg6 dGiZmMmHtiE7xesuYJ7HLNyEFbC51bpTZI7JJawZ9F56z9AYjEoPAQPHQy0e1KtBNKwfeNESEz2 4Nzw= X-Received: by 2002:a05:600c:8b77:b0:48a:9428:5522 with SMTP id 5b1f17b1804b1-490a293a0b1mr152058195e9.16.1780246416759; Sun, 31 May 2026 09:53:36 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Kirk Wolak Date: Sun, 31 May 2026 12:53:09 -0400 X-Gm-Features: AVHnY4J10zk1Uiu9GyBEqXYw7QnbwW8IPazzFNI1xcuQEX_dAHsyj3tXy6Isflw Message-ID: Subject: Re: Add wait events for server logging destination writes To: =?UTF-8?B?7Iug7ISx7KSA?= Cc: pgsql-hackers@lists.postgresql.org, Andrey Borodin , Andreas Karlsson , Nikolay Samokhvalov Content-Type: multipart/alternative; boundary="000000000000489e4706531feb97" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000489e4706531feb97 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Sun, May 31, 2026 at 4:50=E2=80=AFAM =EC=8B=A0=EC=84=B1=EC=A4=80 wrote: > Hi hackers, > > The write(2) calls that flush server log output aren't covered by wait > events. When a backend logs something, the writes go out in: > > - write_pipe_chunks(): write(2) to the syslogger pipe > - write_console(): write(2) to stderr (WriteConsoleW() on Windows) > > If one of those blocks -- syslogger pipe full, slow console, slow log > device -- pg_stat_activity just shows wait_event =3D NULL until it > returns. Since NULL usually reads as "on CPU", a backend stuck writing > logs looks like it's doing work, so logging-related stalls are easy to > miss. > > Attached is a short series that adds two WaitEventIO events and reports > them around those writes: > > IO / SysloggerWrite - write(2) to the syslogger pipe > IO / StderrWrite - write(2) to stderr, and WriteConsoleW() > > 0001 adds the events and covers the write(2) paths. 0002 does the > Windows WriteConsoleW() path, split out since it's platform-specific. > > It only wraps the leaf write call and uses the existing > pgstat_report_wait_start()/end() helpers, so it stays allocation-free > and safe to call from inside the error-reporting path. > > I did a quick before/after to make sure the events show up: 8 backends > each emitting large RAISE LOG lines, sampling wait_event from > pg_stat_activity every 50 ms for 20 s. > > - logging_collector =3D on (syslogger pipe): > master: NULL 100.0% (2184/2184) > patched: IO/SysloggerWrite 99.1% (2204/2224), NULL 0.9% > > - logging_collector =3D off (stderr): > master: NULL 100.0% (2144/2144) > patched: IO/StderrWrite 90.7% (1952/2152), NULL 9.3% > > On master that wait time is just invisible; with the patch it lands on > the new events. I can send the scripts and raw samples if anyone wants > to reproduce it. > +1 Nice. We have too many waits that are registered as CPU. > > --000000000000489e4706531feb97 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


On Sun, May 31, 2026 at 4:50= =E2=80=AFAM =EC=8B=A0=EC=84=B1=EC=A4=80 <shinsj4653@gmail.com> wrote:
Hi hackers,

The write(2) calls that flush server log output aren't covered by wait<= br> events. When a backend logs something, the writes go out in:

=C2=A0 - write_pipe_chunks(): write(2) to the syslogger pipe
=C2=A0 - write_console(): write(2) to stderr (WriteConsoleW() on Windows)
If one of those blocks -- syslogger pipe full, slow console, slow log
device -- pg_stat_activity just shows wait_event =3D NULL until it
returns. Since NULL usually reads as "on CPU", a backend stuck wr= iting
logs looks like it's doing work, so logging-related stalls are easy to<= br> miss.

Attached is a short series that adds two WaitEventIO events and reports
them around those writes:

=C2=A0 IO / SysloggerWrite - write(2) to the syslogger pipe
=C2=A0 IO / StderrWrite - write(2) to stderr, and WriteConsoleW()

0001 adds the events and covers the write(2) paths. 0002 does the
Windows WriteConsoleW() path, split out since it's platform-specific.
It only wraps the leaf write call and uses the existing
pgstat_report_wait_start()/end() helpers, so it stays allocation-free
and safe to call from inside the error-reporting path.

I did a quick before/after to make sure the events show up: 8 backends
each emitting large RAISE LOG lines, sampling wait_event from
pg_stat_activity every 50 ms for 20 s.

=C2=A0 - logging_collector =3D on (syslogger pipe):
=C2=A0 =C2=A0 master:=C2=A0 NULL=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 100.0%=C2=A0 (2184/2184)
=C2=A0 =C2=A0 patched: IO/SysloggerWrite=C2=A0 =C2=A0 =C2=A099.1%=C2=A0 (22= 04/2224), NULL 0.9%

=C2=A0 - logging_collector =3D off (stderr):
=C2=A0 =C2=A0 master:=C2=A0 NULL=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 100.0%=C2=A0 (2144/2144)
=C2=A0 =C2=A0 patched: IO/StderrWrite=C2=A0 =C2=A0 =C2=A0 =C2=A0 90.7%=C2= =A0 (1952/2152), NULL 9.3%

On master that wait time is just invisible; with the patch it lands on
the new events. I can send the scripts and raw samples if anyone wants
to reproduce it.
+1
=C2=A0 Nice.=C2=A0 We have too many waits that are regist= ered as CPU.

--000000000000489e4706531feb97--