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 1oJVGh-0001dk-5Y for pgsql-admin@arkaria.postgresql.org; Thu, 04 Aug 2022 07:27:43 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oJVGf-0000ub-Uh for pgsql-admin@arkaria.postgresql.org; Thu, 04 Aug 2022 07:27:41 +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 1oJVGf-0000qN-Hk for pgsql-admin@lists.postgresql.org; Thu, 04 Aug 2022 07:27:41 +0000 Received: from mail-ed1-x52c.google.com ([2a00:1450:4864:20::52c]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1oJVGd-0001Hw-2e for pgsql-admin@lists.postgresql.org; Thu, 04 Aug 2022 07:27:40 +0000 Received: by mail-ed1-x52c.google.com with SMTP id m8so24153354edd.9 for ; Thu, 04 Aug 2022 00:27:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc; bh=SDs6W1sYo9+IO7aQ3WW2dhH+fUq+5gwYN5yecAFrMSI=; b=RZ6tdWr7CUt0zJYEi5GXkiHnWSo1NLlg9ILI/b3th7a84ypX2LTWIhZTzcmk/gpueD 9qQGvHpk37TbOrLHtdHmtCk/ZKnM+4GlJfZevPGmcRkbkCrNtYBDtFtJbH/MOLBonkOp XacKoYdZ08QwxnCGiOEtGayjlSbYyxFGxmtLHOtxVaSNelbEpkSB/Hf5fHvYAmJ5Dg9J N7Hnrtjm6fNBN19+3s/UdDvMszynFvaV9k1KXkm52UGRiPFPKqE9HX/T07OBWw8rWOOx PEQp7tm7m1t3dKc5g0ErXeFc7+YT7VdXtYaxLXebR7Qy/6DOfCAKFCLPo6rS16O0ZT46 25Fw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc; bh=SDs6W1sYo9+IO7aQ3WW2dhH+fUq+5gwYN5yecAFrMSI=; b=ucT9KpTpTaH1rOE3JstmcFQ3VVOagllpImES2SUvsndiVQmON3iwIhK10OGSxRZtYP CzOJ2uJdA+j2oYqxQRT7gqDVi3VxRrOaaewC9AL5Fs+aDyy4hC4jDUWAG/mwagdMvEPo qPPcxB2Aq5Egi0on2FS8zb19e5esRmgFqwFpYcKH2ULNr6d8NNqAAF6aCU6zO0X2EMsP 0ZEVvjUDDfLvf3dLCSGq8v5+RO6BJ0HV03w1CTL6XjLZ3qdBffK9lsK5pzC8rT60l+H3 GAPnSPpCWBFHDQmgHSqJFocuFv7B6Dcs1A3wFLvmFoFdiYZQdtu2Pb8860x8C/Ka9UKM Fv5w== X-Gm-Message-State: ACgBeo1lCKSY6t38RUt3toSIYp8HELUkWz3L8hrtzN5Cjn2qnro/iZ9H QAewE4tlrZ6TtpGrFOjg6PHN95BGsqY= X-Google-Smtp-Source: AA6agR7TWMk4BPVpaxsgi9Jr00JdsongtokOraqkj11n5YZ03aAPuccg15RVbp+Ic6RDZgEnfKbnLA== X-Received: by 2002:a05:6402:444c:b0:43b:d375:e932 with SMTP id o12-20020a056402444c00b0043bd375e932mr657987edb.399.1659598056967; Thu, 04 Aug 2022 00:27:36 -0700 (PDT) Received: from [192.168.1.85] ([212.97.251.163]) by smtp.gmail.com with ESMTPSA id t10-20020a056402020a00b0043ce97fe4f7sm244166edv.44.2022.08.04.00.27.35 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 04 Aug 2022 00:27:36 -0700 (PDT) Message-ID: Date: Thu, 4 Aug 2022 09:27:33 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: doubts Content-Language: en-GB To: pgsql-admin@lists.postgresql.org References: <9493A23B-213C-4479-82FD-1AAE18127655@elevated-dev.com> From: Bo Victor Thomsen In-Reply-To: <9493A23B-213C-4479-82FD-1AAE18127655@elevated-dev.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 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 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 ;-) > > > >