Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kdW4D-0005PW-Kt for pgsql-performance@arkaria.postgresql.org; Fri, 13 Nov 2020 10:12:30 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kdW4B-0007TY-OW for pgsql-performance@arkaria.postgresql.org; Fri, 13 Nov 2020 10:12:27 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kdW4A-0007Sa-0y for pgsql-performance@lists.postgresql.org; Fri, 13 Nov 2020 10:12:27 +0000 Received: from wout4-smtp.messagingengine.com ([64.147.123.20]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kdW46-0002pN-5o for pgsql-performance@postgresql.org; Fri, 13 Nov 2020 10:12:25 +0000 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.west.internal (Postfix) with ESMTP id 33F79B25 for ; Fri, 13 Nov 2020 05:12:19 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Fri, 13 Nov 2020 05:12:19 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=imap.cc; h=to :from:subject:message-id:date:mime-version:content-type :content-transfer-encoding; s=fm1; bh=pUrQWDlMg+7WLUyHpCBxFMQjGD ISOEWjKaE9920Mwno=; b=xMlVgtDaWqMKX2hgAhLf56irPMzUHQqntnjYwMnqX1 9inVPIDthe+N6QRy/WxkvQMMGtMzV3AFxl0tPtp5Y92FiIb0RhtuNj92bde+CBKy DhTwZJ+9yJ/+3N2UbvUxxippDcCvoV37ODfqoB6ydnit7dNP7ExuBWLZfU6LvCA7 4qMKD+eY5xsOuk1aaC1Kp6yv4wmtYuuOm7KroAvUgWM7yhOLT3cMFuBtQqfwq/7e Vzk5Mt0MtcR5ZL5hJ0FNvTQwXGgnrd/27DDiZxO1nwKtYjj6i8nRqqdj+7EjQsPf RZX5PsOo7S2hDDAKHmtLLRHYgcVEW8lJXZkKYQLS2qZw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:message-id:mime-version:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=pUrQWD lMg+7WLUyHpCBxFMQjGDISOEWjKaE9920Mwno=; b=JJ4sAK9V1nEQRXURUjDvcf h/A1d0IwCn+6qE5cBL+x6gDHGNNgaKD8hk0dnRgykF76hxq9jggx0JT/u4+wczHs IY/D75w0BPLWCNJ20ZlBfhI6vlOhpz1pfwR1kZ00F1N7Xv84+sidjtKNELY01If1 3+eZhf3AAB8kDGeBD7FVXX6sdx+dyv2BI+sKrK+PePd7Z12F1b2NPTyGRG60hkbI SIZAltmAGwGoNW2Wdof6u5NrC29ozhkWUSwLNCEYznM7u8VHcTEWAmrk8S2QZSCJ 6dWhg0rSlRhNFZDGyGoFo6O/7p5vIMdS134WGD/66yk5lLzvopuDwpIwKlFwOluA == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedruddvhedgudefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucgfrhhlucfvnfffucdlfedtmdenucfjughrpefvhf fukffffgggtgfgsehtjeertddtfeejnecuhfhrohhmpeetlhgvgigvhicuuegrshhhthgr nhhovhcuoegsrghshhhtrghnohhvsehimhgrphdrtggtqeenucggtffrrghtthgvrhhnpe ekkeeihfejtdehffffgfeuveelteevhfejvdetffehkeelgeefueefteevkeevueenucfk phepledvrddugedrheejrddufeeknecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrg hmpehmrghilhhfrhhomhepsggrshhhthgrnhhovhesihhmrghprdgttg X-ME-Proxy: Received: from ev9d9.btn1.brandwatch.net (host-92-14-57-138.as43234.net [92.14.57.138]) by mail.messagingengine.com (Postfix) with ESMTPA id 46CAB3280065 for ; Fri, 13 Nov 2020 05:12:18 -0500 (EST) To: pgsql-performance@postgresql.org From: Alexey Bashtanov Subject: How to prioritise walsender reading from pg_wal over WAL writes? Message-ID: Date: Fri, 13 Nov 2020 10:12:17 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hello, I've got a postgres master node that receives a lot of writes, WAL written at 100MB/sec or more at times. And when these load spikes happen streaming replication starts lagging. It looks like the lag happens on sending stage, and is limited by the master pg_wal partition throughput. It's an SSD RAID-1 but it was the same when it was an HDD RAID-1. I tried to prioritize reads using deadline scheduler, but even extreme values don't change the situation: iostat shows more bytes written than read, while the device is busy, often 90-100%. Writers connect via a transaction-pooling-mode pgbouncer, so I can tune the number of parallel connections. Replication works fine when I limit it to 3, which is quite low. It works for me so far, but looks really inflexible to me, as e.g. I'll have to allocate a separate pgbouncer server pool for less eager apps and for humans. I increased wal_buffers to 256MB hoping that it'll reduce the disk load, but it probably works only for initial lag accumulation, once the lag is there it's not going to help. ionice'ing walsender to best-effort -2 didn't help either Any ideas how to prioritize walsender reads over writes from wal writer and backends even if there are multiple quite active ones? The problem happens only occasionally, so if you ask for more details it may take some time to reply. Sorry about this. Best, Alex