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 1oJNdd-0005Bx-SO for pgsql-admin@arkaria.postgresql.org; Wed, 03 Aug 2022 23:18:53 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oJNdc-0007Dc-JS for pgsql-admin@arkaria.postgresql.org; Wed, 03 Aug 2022 23:18:52 +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 1oJNdc-0007Ad-8b for pgsql-admin@lists.postgresql.org; Wed, 03 Aug 2022 23:18:52 +0000 Received: from mailout.easymail.ca ([64.68.200.34]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oJNdV-0005hJ-Dc for pgsql-admin@postgresql.org; Wed, 03 Aug 2022 23:18:51 +0000 Received: from localhost (localhost [127.0.0.1]) by mailout.easymail.ca (Postfix) with ESMTP id 4041262F9F; Wed, 3 Aug 2022 23:18:43 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at emo09-pco.easydns.vpn Received: from mailout.easymail.ca ([127.0.0.1]) by localhost (emo09-pco.easydns.vpn [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 5LYfA0wFnBGj; Wed, 3 Aug 2022 23:18:43 +0000 (UTC) Received: from smtpclient.apple (unknown [4.28.96.150]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mailout.easymail.ca (Postfix) with ESMTPSA id D37FA62F1A; Wed, 3 Aug 2022 23:18:42 +0000 (UTC) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.100.31\)) Subject: Re: doubts From: Scott Ribe In-Reply-To: Date: Wed, 3 Aug 2022 17:18:41 -0600 Cc: pgsql-admin@postgresql.org Content-Transfer-Encoding: quoted-printable Message-Id: <9493A23B-213C-4479-82FD-1AAE18127655@elevated-dev.com> References: To: Thomaz Luiz Santos X-Mailer: Apple Mail (2.3696.100.31) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Aug 3, 2022, at 5:06 PM, Thomaz Luiz Santos = wrote: >=20 > I have one question: is it possible to minimize the downtime for this = process ( because this table is large. ), using another strategy, like = one view and updating the view ?=20 Yes, using a view and redefining it after the new data is loaded would = work. You could also: - load new data into a new table - begin transaction - drop old table - rename new table - commit The drop/rename dance executes very quickly because it's just = manipulating catalog entries--with the caveat that dropping the table = requires an exclusive lock for the obvious reason, so if you have a = long-running transaction using that table, you can wind up waiting for = it. Look at the docs for CREATE TABLE and the "LIKE" option, which gives you = a shortcut to creating a table with the structure of an existing one. One peculiarity you might or might not care about: when you create your = indexes on the new table, they will be named based on that table's name, = and when you rename it the indexes don't get renamed. Personally, I am = OK with "my_table_temp_some_idx" on "my_table", but if this offends your = sensibilities, you can always rename the indexes ;-) and constraints ;-)