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 1ltdml-00077F-Ho for pgsql-hackers@arkaria.postgresql.org; Wed, 16 Jun 2021 22:13:23 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1ltdmj-00071R-1P for pgsql-hackers@arkaria.postgresql.org; Wed, 16 Jun 2021 22:13:21 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ltdmi-00071J-Pw for pgsql-hackers@lists.postgresql.org; Wed, 16 Jun 2021 22:13:20 +0000 Received: from out2-smtp.messagingengine.com ([66.111.4.26]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ltdmg-0004Eg-L1 for pgsql-hackers@lists.postgresql.org; Wed, 16 Jun 2021 22:13:19 +0000 Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.nyi.internal (Postfix) with ESMTP id 87BC65C00D8; Wed, 16 Jun 2021 18:13:17 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Wed, 16 Jun 2021 18:13:17 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anarazel.de; h= date:from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=fm1; bh=GVOJMEqG3vCyu0NnVIdRCfp0zWs XbZHsz6n9SuhouNc=; b=L4iMaO7+UBy+ij5EQMJBuVsPiNb+fSsCXDjwf2PdRR6 +hCUY3fLzUJmH/pBuU4CNLZmqwtG/df1s1HMarAUexASYUq6aXFJd6JNC+C45vC2 Mqme2NmKDyKu8fIAPsFllDMGLuUP7HtZhMe9pFsFr2/Hup2l8bIXd6XxEY/lzXKK 0MIxftydkhnSb2akOKw8LYjNMc8t7+o+WMh5suhPoVGfLS6k/2FeFlDcZF3pR0uD D9AMRd7+89KfsqQuWdn8hBAotI801Gyceu64huODlvQNo+CAxEXNg/PHAlqd/99n a9kzymx0lGvSmI8OT7uqrCibFXeDiy6c/5sUAZT8efQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=GVOJME qG3vCyu0NnVIdRCfp0zWsXbZHsz6n9SuhouNc=; b=KRp2O5MRitIygH6u0d96Fv 0nVmOpskZLYpLy3EfMyVXxIjj/7jqrkvPtbwHGy3ijQVTkpmxjVj9I/6AO05E7aK JlIGGTCBot75SB6PExd7VSO5V16yS50cbM3qBjsztSf5z9DpEjgBOzjdGz9RN2g3 ffUIbJiq9luOQXTwJSFfmDo8kGKjDEtXqMClBz0tgD8GtP2ZyL6l+EPDtdUd69h8 NakcJDW7J3RLxZjVYLFWYHRdGRZxE3Gv5IwQqlCf4bM7Y/U0VNwwTlFUgGe02Qtf LIdPP0ZYB6MGx6hqFsIN9BiYLW55aG5noVjZ1927LrALP6QlPWE0cIoQuiHxpR6w == X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrfeeftddgtdefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvffukfhfgggtuggjsehttdertddttddvnecuhfhrohhmpeetnhgurhgv shcuhfhrvghunhguuceorghnughrvghssegrnhgrrhgriigvlhdruggvqeenucggtffrrg htthgvrhhnpedukefhkeelueegveetheelffffjeegleeuudelfeefuedtleffueejfffh ueffudenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpe grnhgurhgvshesrghnrghrrgiivghlrdguvg X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 16 Jun 2021 18:13:17 -0400 (EDT) Date: Wed, 16 Jun 2021 15:13:16 -0700 From: Andres Freund To: Dilip Kumar Cc: Heikki Linnakangas , PostgreSQL Hackers Subject: Re: [Proposal] Fully WAL logged CREATE DATABASE - No Checkpoints Message-ID: <20210616221316.jrveut7d5kimpl6j@alap3.anarazel.de> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On 2021-06-15 18:11:23 +0530, Dilip Kumar wrote: > On Tue, Jun 15, 2021 at 5:34 PM Heikki Linnakangas wrote: > > > > On 15/06/2021 14:20, Dilip Kumar wrote: > > > Design Idea: > . Then > > > we can get the relfilenode of every file we need to copy, and prepare > > > a list of all such relfilenode. > > > > I guess that would work, but you could also walk the database directory > > like copydir() does. How you find the relations to copy is orthogonal to > > whether you WAL-log them or use checkpoints. And whether you use the > > buffer cache is also orthogonal to the rest of the proposal; you could > > issue FlushDatabaseBuffers() instead of a checkpoint. > > Yeah, that would also work, but I thought since we are already > avoiding the checkpoint so let's avoid FlushDatabaseBuffers() also and > directly use the lower level buffer manager API which doesn't need > recache. And I am using pg_class to identify the useful relfilenode > so that we can avoid processing some unwanted relfilenode but yeah I > agree that this is orthogonal to whether we use checkpoint or not. It's not entirely obvious to me that it's important to avoid FlushDatabaseBuffers() on its own. Forcing a checkpoint is problematic because it unnecessarily writes out dirty buffers in other databases, triggers FPWs etc. Normally a database used as a template won't have a meaningful amount of dirty buffers itself, so the FlushDatabaseBuffers() shouldn't trigger a lot of writes. Of course, there is the matter of FlushDatabaseBuffers() not being cheap with a large shared_buffers - but I suspect that's not a huge factor compared to the rest of the database creation cost. I think the better argument for going through shared buffers is that it might be worth doing so for the *target* database. A common use of frequently creating databases, in particular with a non-default template database, is to run regression tests with pre-created schema / data - writing out all that data just to have it then dropped a few seconds later after the regression test completed is wasteful. > > In principle, we could have both mechanisms, and use the new WAL-logged > > system if the database is small, and the old system with checkpoints if > > it's large. But I don't like idea of having to maintain both. > > Yeah, I agree in some cases, where we don't have many dirty buffers, > checkpointing can be faster. I don't think the main issue is the speed of checkpointing itself? The reaoson to maintain the old paths is that the "new approach" is bloating WAL volume, no? Right now cloning a 1TB database costs a few hundred bytes of WAL and about 1TB of write IO. With the proposed approach, the write volume approximately doubles, because there'll also be about 1TB in WAL. Greetings, Andres Freund