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 1makNl-0005CO-Mu for pgsql-hackers@arkaria.postgresql.org; Wed, 13 Oct 2021 19:57:45 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1makNk-0002kA-MF for pgsql-hackers@arkaria.postgresql.org; Wed, 13 Oct 2021 19:57:44 +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 1makNj-0002k0-Nq for pgsql-hackers@lists.postgresql.org; Wed, 13 Oct 2021 19:57:44 +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 1makNg-00030V-30 for pgsql-hackers@lists.postgresql.org; Wed, 13 Oct 2021 19:57:43 +0000 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id CDFBB5C01CA; Wed, 13 Oct 2021 15:57:36 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Wed, 13 Oct 2021 15:57:36 -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=ypInScXRllbOUbCX6mClFPVFshZ7Ds9jJAHb1KrV5VU=; b=jBJU1ODb QLa4YB4/EZ3bxHsOegPwjkSo0oReD+a1h0DmL6YmCz/80BDShz1XLjKLQF+0i7ww imuGR5DscHHb1qtTcdEIv4kO2N0O3HdVGiZBfk/+mwlBdqgiAH5/8jlBjUfPUNgt mk33sX86bycPviU2GZbn66BOgaXOvpKPb8x8sO/EPS7u/A6WrzDsoQJdMjZO2x2o oSVJFr9LhXrNvPFMwgmu84bzKgT1jPTMNAI4xJKRRetxZLpPMM+XbZksPcnRg2Rt 9yqN3gu8fTOxbpSDyPExLCy5LVCIl9l13y5BDpzCwlGRYLwC505DEDso7ZAhm6o2 2QwPnj64lIEyuA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddrvddutddgudegudcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvuffkgggtugfgjgesthekredttddtjeenucfhrhhomheptehlvhgr rhhoucfjvghrrhgvrhgruceorghlvhhhvghrrhgvsegrlhhvhhdrnhhoqdhiphdrohhrgh eqnecuggftrfgrthhtvghrnhepfeduleekteeigfegledtvddvvddtledugfefhfdtieev teeftdeuueehudeuvdelnecuffhomhgrihhnpegvnhhtvghrphhrihhsvggusgdrtghomh dpphhoshhtghhrvghsqhhlrdhorhhgnecuvehluhhsthgvrhfuihiivgeptdenucfrrghr rghmpehmrghilhhfrhhomheprghlvhhhvghrrhgvsegrlhhvhhdrnhhoqdhiphdrohhrgh X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 13 Oct 2021 15:57:35 -0400 (EDT) Received: by perhan.alvh.no-ip.org (Postfix, from userid 1000) id 708222A06EC; Wed, 13 Oct 2021 16:57:33 -0300 (-03) Date: Wed, 13 Oct 2021 16:57:33 -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: <202110131957.cjm4ftp4dtdm@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20211013191345.gqgsih7gq6jn5cxo@alap3.anarazel.de> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2021-Oct-13, Andres Freund wrote: > > > Another thing: filling a segment by inserting lots of very tiny rows is pretty > > > expensive. Can't we use something a bit wider? Perhaps even emit_message? > > FWIW, the count of inserted rows is something like 171985 ;) This does ~1600 iterations to fill one segment, 10 rows per iteration, row size is variable; exits when two BLCKSZ remain to complete the WAL segment: create table filler (a int, b text); 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; raise notice '(%) remain: %', iters, remain; if remain < 2 * setting::int from pg_settings where name = 'block_size' then exit; end if; iters := iters + 1; end loop; end $$ ; (Of course, I'm not proposing that the 'raise notice' be there in the committed form.) If I enlarge the 'repeat' count, it gets worse (more iterations required) because a lot of the rows become toasted and thus subject to compression. If I do 20 rows per iteration rather than 10, the risk is that we'll do too many near the end of the segment and we'll have to continue running until completing the next one. So, this seems good enough. -- Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/ "Once again, thank you and all of the developers for your hard work on PostgreSQL. This is by far the most pleasant management experience of any database I've worked on." (Dan Harris) http://archives.postgresql.org/pgsql-performance/2006-04/msg00247.php