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 1wZWN5-0016hC-2c for pgsql-hackers@arkaria.postgresql.org; Tue, 16 Jun 2026 16:10:39 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wZWN3-001ORm-1L for pgsql-hackers@arkaria.postgresql.org; Tue, 16 Jun 2026 16:10:37 +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 1wZWN3-001ORe-02 for pgsql-hackers@lists.postgresql.org; Tue, 16 Jun 2026 16:10:37 +0000 Received: from mail-ed1-x533.google.com ([2a00:1450:4864:20::533]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wZWN0-00000000lA8-2qHX for pgsql-hackers@lists.postgresql.org; Tue, 16 Jun 2026 16:10:36 +0000 Received: by mail-ed1-x533.google.com with SMTP id 4fb4d7f45d1cf-6924a68e3f3so7640297a12.1 for ; Tue, 16 Jun 2026 09:10:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1781626232; cv=none; d=google.com; s=arc-20240605; b=ImSt1D5PgpbcPLclxXjU5MfAPZkn0wxzV3Nv/rGCGVfbyWA31OXyajGPcWIxVCDYBw 9JJeOSkZ2i/DZVYXh/Fq3mWfnxocwW2yoHUN0SEyrKCSXpC0O0fpljlmqifEA8AA7q2J iRDqktUnnTFyYooP9hDdzgbzKd3UgErc9UHtiAWpV4m8s6evaRyVBZ8B0OW8/2lNWzia lc9FjhQW5uZ7nQ9RJfBD7PjowBEtubpTRUWgXWrcyQcVu3CluqGY6i0NLJQxeGlw1Zt3 mepVaUxriijFvAvTK6R5fp1obXY3L6WbWCHxmRb8KTqOTvi/MOqMGrpEoWsInQhdDuJu PtQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=KkzJI87bdtGn5unEZzsPOVe4X14zbjdgHtjn5GEm774=; fh=JyIz7FTxV0T44NOEmLCMskGOowtVvjhj3I8WqveT4No=; b=akEKq584Uv2NtkUIa73dGvTLcBt1+S9KDEgarZ7yMprdrrX67CgwWQejgyDmWYspOQ gh6vgUJMMFAJtThCgJf93nqZy88qwSn4zAHJoKCbjF4f8x74jMiwOj5XiGvjN6idpwZz FyEijxN+9FOzRqTK2LLpTjUy574z6iQGK9tcreU837q26yxqzKpVWJrRx6InBpFmGgiy YOADjDQX1MKzav93MPSA3bCDi4YBI/G4CFzZThbwSYifWkycbm+nFeEHSKMCyhgVpes7 Q1d/zLdf/PPTrNX0Qr31mzvM1JVNKkBdDXPaS4udiW1xTeazjFKWPmywg0wZGVybgO87 EzEw==; 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=1781626232; x=1782231032; darn=lists.postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=KkzJI87bdtGn5unEZzsPOVe4X14zbjdgHtjn5GEm774=; b=lvrE79nMYovO0uqUzfr7ny8Eg/tJxd8+/5jQoImnice/d5D7/YsTHIGeQraU4N6hUn SZUmAkJGh7VlKjek6IizLK+FedubgsEkMhVaF1dBzmQ6iAp5UtnASgIYl/DRHCyhTl4O VFA3w7/ZSEOlm+J/rGH/l2rdSEtFkpN0hWrMcqgrQ8uf7QVwapv6JV04qmx0ANhvXLg6 Pjc5d+baOqzuWmqxyJLWsnhyGhFs8taEAHf5TtvEY78vB8qW0vxY7KIERSZ9qlInch/C yM4nWLPLRPmFTz41qlImwdmiOnIKIPeVp6r9j5OZljv0acR5gjtWoTL9d4Usv/W0foDt iY+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781626232; x=1782231032; h=content-transfer-encoding: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=KkzJI87bdtGn5unEZzsPOVe4X14zbjdgHtjn5GEm774=; b=hMRot9ukVRRHXyVU3TefZPIsdHP+ZVGmnqB7xdx0kvZiTCit0c3Pqj6VI8XXuyPL+K mj9ieB4N9pWDQBhVa/khBe3RIu480Sa3d4n1pDmcMtQbVL941VWWjvtPJzSS7o4HiBx0 YGVc8Uvpt1PeOiLW62nUcJd2GlfUuiqs5FYjPFeDpPYX6lmjV2oP/6xVke4MQDJgExod N9rFlBoFPsCUS4A1tppzGGJAsEk5KoIW+k7h7X8eXgYsGNMhDwQL1fhfT5MsgUL9iiFg QjCaTdxvgEAMaSPomgpqI2NDgx/qC+LhbWNSMVVqUKPCOi4bRP5D3+JttZFYvzqCbC0H n4fQ== X-Gm-Message-State: AOJu0YwIrlqXq7TGm1j4thTMSgTzsMwlu9WSDrvrLGaLJC/Wg7hwsfW5 Sh/iv80STQ2aejIC/qTHWX+YzYel0SLcpxIl8uEaC27hVd8bG2L3NtyEJkO+ZTYe6PywxlacIIr ORV6PA4vQgj62iAVdzWODhEvcvjG70Cs= X-Gm-Gg: Acq92OGjFjUVumsRbf8++KQNTuDNINiM6Ug35HULFmzgimtUvkXktAbEI386aA1dxo7 MMBBhyzmh5P0lVKMPAkVCl+ulSwzOfgoi/yfJ9E1pKtGNG585DR2IiZg+dhENXpM75oN0twd0Tc OG6MlyCy+GPr4MRCmUUgTCgWWizyaCLLFS/DO2fLaTSTMnL55Sdsl7yypoXOctTHCYG96qv2Xk/ mSgFoiKf+tPHX1DtKPFxOBS+zRqbOmS9jUfH3zx9jPs+FRgvKCcZB7rz5w1W1YwrDaRpdIhqBRY C65SNtypQ73nEA7DjFajK+AVG3l6RYzNBKsgciBA X-Received: by 2002:a05:6402:3547:b0:68f:c62d:d23e with SMTP id 4fb4d7f45d1cf-6950878a74cmr2436168a12.27.1781626231518; Tue, 16 Jun 2026 09:10:31 -0700 (PDT) MIME-Version: 1.0 References: <20260601.144922.658666928129832364.horikyota.ntt@gmail.com> <378001C2-12FE-47F5-8188-05900EF53F62@yandex-team.ru> In-Reply-To: <378001C2-12FE-47F5-8188-05900EF53F62@yandex-team.ru> From: =?UTF-8?B?7Iug7ISx7KSA?= Date: Wed, 17 Jun 2026 01:10:18 +0900 X-Gm-Features: AVVi8Ce-uPELrxtS-ZF2CxrtrKwsTRIQ4fmly-eD22_Vuwn22kOMWMS4gQjtt10 Message-ID: Subject: Re: Add wait events for server logging destination writes To: Andrey Borodin Cc: pgsql-hackers mailing list , Kirk Wolak , Kyotaro Horiguchi , Andreas Karlsson , nik@postgres.ai Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi Andrey, > +1: a blocking logging write shows as wait_event IS NULL today, which mos= t > tools read as on-CPU. This is very real for us. In our managed Postgres t= he > root filesystem that holds the logs sits on slow network-backed HDD, so w= hen > the syslogger pipe backs up the backends stall on the log write and the w= hole > node looks like a CPU overload. This patch would have made that directly > visible. Thanks for the review, and for the production example. That node-looks-like= -a- CPU-overload case is exactly what this is meant to make visible. > Worth a line in the commit message: the call that actually blocks on a sl= ow > log device is write_syslogger_file() in the syslogger, which has no share= d > memory and isn't in pg_stat_activity. It surfaces on backends as the pipe > fills and they block on the pipe write (SysloggerWrite), so the backend s= ide > is the right, visible layer. Agreed. In v5 I'll add that to the commit message, and a short code comment= to the same effect: the syslogger does the file write in write_syslogger_file(= ) and isn't in pg_stat_activity, so the backend-side SysloggerWrite is where = the stall becomes visible. > Naming is a hard thing. Anyone who can tell syslog from syslogger without > checking man is probably a computer themselves. Fair. I kept each name aligned with the routine it wraps, and the descripti= ons spell out the difference, so I'd lean toward leaving them unless others obj= ect. > One thing worth checking: wait events are single-slot by design (no nesti= ng - > discussed back in 2016 [0]), and pgstat_report_wait_end() just writes 0. = So > if any ereport() path runs while a wait event is already set, instrumenti= ng > the logging write here clobbers that outer event. Probably rare, but I'm = not > sure it never happens. Right about the mechanism. pgstat_report_wait_end() unconditionally writes = 0, so a log message emitted while an outer wait event is set would briefly mas= k that event until the outer code reports its own end. Two things, though. First, this is a pre-existing property of the subsystem= , not something the patch introduces: every pgstat_report_wait_start()/end() = pair behaves this way, and as the 2016 thread you linked concluded, the single unsynchronized write is what keeps the mechanism cheap enough to stay on by default, so nesting was deliberately left out. The patch follows that convention rather than diverging from it. Second, the wrapped regions are t= ight and log output is normally emitted outside them, so the overlap window shou= ld be rare in practice, though I agree it isn't provably never. So I'd prefer not to add save/restore here, since that would diverge from w= hat the rest of the tree relies on. I'll add a brief comment at these sites not= ing the single-slot behavior. If reviewers would rather have a guard, a minimal option that stays within the single-write model is to report the logging ev= ent only when the slot is currently 0, which preserves the outer event at the c= ost of not showing the logging write while nested. Happy to go that way if that= 's the consensus. > EventlogWrite necessarily shows up in the event list on all platforms (th= e > generator has no per-platform gating), but the description already says > "Windows event log", so that seems fine... Agreed, I'll leave it as-is. I'll hold v5 until Nikolay's Linux and Windows testing comments land too, s= o I can fold everything into one revision. Thanks again, Seongjun 2026=EB=85=84 6=EC=9B=94 15=EC=9D=BC (=EC=9B=94) =EC=98=A4=EC=A0=84 3:49, A= ndrey Borodin =EB=8B=98=EC=9D=B4 =EC=9E=91=EC=84=B1: > > > > > On 6 Jun 2026, at 21:52, =EC=8B=A0=EC=84=B1=EC=A4=80 wrote: > > > > Hi Seongjun, > > Naming is a hard thing. Anyone who can tell syslog from syslogger > without checking man is probably a computer themselves. > > +1: a blocking logging write shows as wait_event IS NULL today, which > most tools read as on-CPU. This is very real for us. In our managed > Postgres the root filesystem that holds the logs sits on slow > network-backed HDD, so when the syslogger pipe backs up the backends > stall on the log write and the whole node looks like a CPU overload. > This patch would have made that directly visible. > > Worth a line in the commit message: the call that actually blocks on a > slow log device is write_syslogger_file() in the syslogger, which has no > shared memory and isn't in pg_stat_activity. It surfaces on backends as > the pipe fills and they block on the pipe write (SysloggerWrite), so > the backend side is the right, visible layer. > > One thing worth checking: wait events are single-slot by design (no > nesting - discussed back in 2016 [0]), and pgstat_report_wait_end() > just writes 0. So if any ereport() path runs while a wait event is > already set, instrumenting the logging write here clobbers that outer > event. Probably rare, but I'm not sure it never happens. > > EventlogWrite necessarily shows up in the event list on all platforms > (the generator has no per-platform gating), but the description already > says "Windows event log", so that seems fine... > > Thanks for working on this! > > > Best regards, Andrey Borodin. > > [0] https://www.postgresql.org/message-id/CANP8%2BjKsS6SDo011AUWrLdBcBMv0= KJha69t7eFGqEtqx9FVfag%40mail.gmail.com > >