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.94.2) (envelope-from ) id 1u4cPQ-004n9W-Qx for pgsql-performance@arkaria.postgresql.org; Tue, 15 Apr 2025 09:16:49 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1u4cPO-006qph-JU for pgsql-performance@arkaria.postgresql.org; Tue, 15 Apr 2025 09:16:47 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1u4cPO-006qpX-5E for pgsql-performance@lists.postgresql.org; Tue, 15 Apr 2025 09:16:46 +0000 Received: from mail.postgrespro.ru ([93.174.132.70]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1u4cPL-000APg-2R for pgsql-performance@lists.postgresql.org; Tue, 15 Apr 2025 09:16:45 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mx2023; t=1744708601; bh=01vpOyMCaQUf6QD7in10zdQ9KgoQsEWy4ci8ZYNRMnI=; h=Message-ID:Date:User-Agent:Subject:To:References:From:In-Reply-To: From; b=2Z9gy6p0tNwrd5FD+8ng0RpAX6p0PFjXBlqyGUVACRp+M2JZSpDO1O6AHDSxNiySy /E/LI488LZCuE2xFCXFq1R00sJF6zyEmqcQakR7KWZPvhGQy2dUf0QAz5TqQekDvdV YGGa22AvcGl3XT57PUuDJ8fZ7IA46On3ncCCFImvLBdR/ri4uQyZj0Ah3WB4c7Fhg/ UIKWrbq1ASTpVXfgYyZv4Z9PJF/wK4JIqfmFRYpAqlsAc39dH8p7G6qmEL8kOJm0hb 1vnhkQdRbJXs45f+enXUQOvIGtrS3hkJMsN6nSBESU9rQ6FfFp7wmBixmGpGJH3Tfn qRHoWBo/2JD2g== Received: from [172.30.50.150] (unknown [93.174.131.138]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (Client did not present a certificate) (Authenticated sender: y.sokolov@postgrespro.ru) by mail.postgrespro.ru (Postfix/465) with ESMTPSA id 529345FF87; Tue, 15 Apr 2025 12:16:41 +0300 (MSK) Message-ID: <20ee7c44-bb93-4590-a984-b7fe4e4a9b14@postgrespro.ru> Date: Tue, 15 Apr 2025 12:16:40 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: many sessions wait on LWlock WALWrite suddenly To: James Pang , pgsql-performance@lists.postgresql.org, Andres Freund References: Content-Language: en-US From: Yura Sokolov In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-KSMG-AntiPhishing: NotDetected X-KSMG-AntiSpam-Interceptor-Info: not scanned X-KSMG-AntiSpam-Status: not scanned, disabled by settings X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 2.1.0.7854, bases: 2025/04/15 04:45:00 #27887313 X-KSMG-AntiVirus-Status: NotDetected, skipped X-KSMG-LinksScanning: not scanned, disabled by settings X-KSMG-Message-Action: skipped X-KSMG-Rule-ID: 1 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 11.04.2025 17:36, James Pang пишет: >    pgv14.8 , during peak time, we suddenly see hundreds of active sessions > waiting on LWlock  WALWrite at the same time, but we did not find any issue > on storage . > any suggestions ? No real suggestions... There is single WALWrite lock. So only single process may actually write WAL to disk. There're no any parallelism. And the process also does fsync. One file after other. There're no any parallelism. And all other backend that needs to be sure their transactions settled on the disk waits for this process. And this process is gready: it collects farest position in WAL buffers ready to be written, and write and fsync whole those buffers. And only after than it releases WALWrite lock and other backends awoken. So when many backends wrote to WAL buffers and now need to wait buffers are settled on disc, they wait for this single process, which will write buffers for all that backends. So: - many backends wrote WAL buffers, - one backend calculated how many buffers were written, - and then the backend write and fsync those buffers serially, - all other backends waits for this backend, In the results, backends waits each other, or, in other words, they waits latest of them!!! All backends waits until WAL record written by latest of them will be written and fsynced to disk. (Andres, iiuc it looks to be main bottleneck on the way of increasing NUM_XLOGINSERT_LOCKS. Right?) -- regards Yura Sokolov aka funny-falcon