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 1oGiJ6-0000x7-HD for pgsql-performance@arkaria.postgresql.org; Wed, 27 Jul 2022 14:46:40 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oGiJ4-0006Uy-6j for pgsql-performance@arkaria.postgresql.org; Wed, 27 Jul 2022 14:46:38 +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 1oGiJ3-0006SG-S4 for pgsql-performance@lists.postgresql.org; Wed, 27 Jul 2022 14:46:37 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oGiIu-0001Te-Ct for pgsql-performance@lists.postgresql.org; Wed, 27 Jul 2022 14:46:34 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 26REkNBj2883169; Wed, 27 Jul 2022 10:46:23 -0400 From: Tom Lane To: Joe Conway cc: "James Pang (chaolpan)" , Jim Mlodgenski , "pgsql-performance@lists.postgresql.org" Subject: Re: alter table xxx set unlogged take long time In-reply-to: References: <2240967.1658839372@sss.pgh.pa.us> Comments: In-reply-to Joe Conway message dated "Wed, 27 Jul 2022 10:35:02 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2883167.1658933183.1@sss.pgh.pa.us> Date: Wed, 27 Jul 2022 10:46:23 -0400 Message-ID: <2883168.1658933183@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Joe Conway writes: > Then (completely untested) I *think* you could create the "partition" > initially as a free standing unlogged table, load it, index it, switch > to logged, and then attach it to the partitioned table. I'm still of the opinion that this plan to load the data unlogged and switch to logged later is a loser. Sooner or later you have got to write the data to WAL, and this approach doesn't eliminate that cost. What it does do is create one whole extra cycle of writing the data to disk and reading it back. I don't think it's an oversight that no such thing is suggested in our standard tips for bulk-loading data: https://www.postgresql.org/docs/current/populate.html What perhaps *is* an oversight is that we don't suggest use of COPY FREEZE there. AFAIK that doesn't reduce the initial data loading cost directly, but it would save overhead later. regards, tom lane