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 1mal5L-0006j5-C5 for pgsql-hackers@arkaria.postgresql.org; Wed, 13 Oct 2021 20:42:47 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mal5K-0006uT-8y for pgsql-hackers@arkaria.postgresql.org; Wed, 13 Oct 2021 20:42:46 +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 1mal5K-0006uK-07 for pgsql-hackers@lists.postgresql.org; Wed, 13 Oct 2021 20:42:46 +0000 Received: from out3-smtp.messagingengine.com ([66.111.4.27]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mal5H-0003Lp-3a for pgsql-hackers@lists.postgresql.org; Wed, 13 Oct 2021 20:42:45 +0000 Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id BD7A25C014E; Wed, 13 Oct 2021 16:42:41 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Wed, 13 Oct 2021 16:42:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; bh=qYfUd88X8/IPUEI6YqqX+yZ7bogm3iYXmbU/7YhzAQ8=; b=JM3U5SJ5 PMQ8bpZvp4GOfRPVffKJi8k/1dgnGjP+0fd7h56NmPK1+shxmLk+Qm9GdqhVgn26 lWboDFwbH+r6Yc+qDLgBZL74/mA0AEzcf325vE+ARnDdIH5Uo6CqBN+E6JuLHY4d Z6fKwcyRGl+WPDJxzkR27mu4hh9lUcQluhfZuPsxmri4qIgK1He4GPNJLDEkQWum wHbu7JKvIcTpwL+AjJT3cd62mClN+ze9xVLXWu1M7zQL8zFZ6vXFw0J1VjHtfSCX LNC5HfAE+SPeh9NYBo0tHGjX0BF/AbS0SBVvIO8SSlIFrEKwxec3dkVFgplesbL9 21Cf/eX6VWGD+w== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddrvddutddgudeglecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvuffkgggtugfgjgesmhekreertddtjeenucfhrhhomheptehlvhgr rhhoucfjvghrrhgvrhgruceorghlvhhhvghrrhgvsegrlhhvhhdrnhhoqdhiphdrohhrgh eqnecuggftrfgrthhtvghrnheptedvhfetueeukeefhfefudegfffhhefhvdelffelteek geegfefhgfegkeejtddunecuffhomhgrihhnpegvnhhtvghrphhrihhsvggusgdrtghomh enucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrlhhv hhgvrhhrvgesrghlvhhhrdhnohdqihhprdhorhhg X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 13 Oct 2021 16:42:40 -0400 (EDT) Received: by perhan.alvh.no-ip.org (Postfix, from userid 1000) id 98E132A06EC; Wed, 13 Oct 2021 17:42:37 -0300 (-03) Date: Wed, 13 Oct 2021 17:42:37 -0300 From: Alvaro Herrera To: Andres Freund Cc: Tom Lane , Andrew Dunstan , "Bossart, Nathan" , Kyotaro Horiguchi , "masao.fujii@oss.nttdata.com" , "pgsql-hackers@lists.postgresql.org" , "mengjuan.cmj@alibaba-inc.com" , "Jakub.Wartak@tomtom.com" , Ryo Matsumura Subject: Re: prevent immature WAL streaming Message-ID: <202110132042.pe4herrhq4a7@alvherre.pgsql> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="43xlhermssq2bdon" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <202110131957.cjm4ftp4dtdm@alvherre.pgsql> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --43xlhermssq2bdon Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit This works nicely with the TAP test: -- Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/ "Postgres is bloatware by design: it was built to house PhD theses." (Joey Hellerstein, SIGMOD annual conference 2002) --43xlhermssq2bdon Content-Type: text/x-diff; charset=utf-8 Content-Disposition: attachment; filename="0001-do-away-with-small-tuple-writing.patch" From e9bcdb3b44f36ffa1a2377f252d73ff3d7210fd9 Mon Sep 17 00:00:00 2001 From: Alvaro Herrera Date: Wed, 13 Oct 2021 17:41:31 -0300 Subject: [PATCH] do away with small tuple writing --- .../recovery/t/026_overwrite_contrecord.pl | 39 +++++++++++-------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/src/test/recovery/t/026_overwrite_contrecord.pl b/src/test/recovery/t/026_overwrite_contrecord.pl index 1725a97531..b7d3b6e03d 100644 --- a/src/test/recovery/t/026_overwrite_contrecord.pl +++ b/src/test/recovery/t/026_overwrite_contrecord.pl @@ -22,27 +22,32 @@ $node->init(allows_streaming => 1); $node->append_conf('postgresql.conf', 'wal_keep_size=1GB'); $node->start; -$node->safe_psql('postgres', 'create table filler (a int)'); -# First, measure how many bytes does the insertion of 1000 rows produce -my $start_lsn = - $node->safe_psql('postgres', q{select pg_current_wal_insert_lsn() - '0/0'}); -$node->safe_psql('postgres', - 'insert into filler select * from generate_series(1, 1000)'); -my $end_lsn = - $node->safe_psql('postgres', q{select pg_current_wal_insert_lsn() - '0/0'}); -my $rows_walsize = $end_lsn - $start_lsn; +$node->safe_psql('postgres', 'create table filler (a int, b text)'); # Now consume all remaining room in the current WAL segment, leaving # space enough only for the start of a largish record. $node->safe_psql( - 'postgres', qq{ -WITH setting AS ( - SELECT setting::int AS wal_segsize - FROM pg_settings WHERE name = 'wal_segment_size' -) -INSERT INTO filler -SELECT g FROM setting, - generate_series(1, 1000 * (wal_segsize - ((pg_current_wal_insert_lsn() - '0/0') % wal_segsize)) / $rows_walsize) g + 'postgres', q{ +DO $$ +DECLARE + wal_segsize int := setting::int FROM pg_settings WHERE name = 'wal_segment_size'; + remain int; + iters int := 0; +BEGIN + LOOP + INSERT into filler + select g, repeat(md5(g::text), (random() * 60 + 1)::int) + from generate_series(1, 10) g; + + remain := wal_segsize - (pg_current_wal_insert_lsn() - '0/0') % wal_segsize; + IF remain < 2 * setting::int from pg_settings where name = 'block_size' THEN + RAISE log 'exiting after % iterations, % bytes to end of WAL segment', iters, remain; + EXIT; + END IF; + iters := iters + 1; + END LOOP; +END +$$; }); my $initfile = $node->safe_psql('postgres', -- 2.30.2 --43xlhermssq2bdon--