pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Bo Victor Thomsen <bo.victor.thomsen@gmail.com>
To: pgsql-admin@lists.postgresql.org
Subject: Re: doubts
Date: Thu, 4 Aug 2022 09:27:33 +0200
Message-ID: <ccf901c2-c0ce-496c-0fc7-4b0d663c7f8f@gmail.com> (raw)
In-Reply-To: <9493A23B-213C-4479-82FD-1AAE18127655@elevated-dev.com>
References: <CAHtRPB6atN3u+dccSOjiJdYpNGEiTJqMrHCpZ4NZc+1F4jEaaw@mail.gmail.com>
	<9493A23B-213C-4479-82FD-1AAE18127655@elevated-dev.com>

Sorry for being "Captain Obvious" -

If you use this method, just remember to have the necessary storage 
capacity available for two versions of the table in question.

Med venlig hilsen / Kind regards

Bo Victor Thomsen

Den 04-08-2022 kl. 01:18 skrev Scott Ribe:
> On Aug 3, 2022, at 5:06 PM, Thomaz Luiz Santos <thomaz.santos@gmail.com> wrote:
>> 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 ?
> 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 ;-)
>
>
>
>





view thread (4+ messages)

Message-ID: <ccf901c2-c0ce-496c-0fc7-4b0d663c7f8f@gmail.com>
Permalink:  ../ccf901c2-c0ce-496c-0fc7-4b0d663c7f8f@gmail.com/
Also on:    postgresql.org/message-id/ccf901c2-c0ce-496c-0fc7-4b0d663c7f8f@gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-admin@postgresql.org
  Cc: bo.victor.thomsen@gmail.com, pgsql-admin@lists.postgresql.org
  Subject: Re: doubts
  In-Reply-To: <ccf901c2-c0ce-496c-0fc7-4b0d663c7f8f@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox