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 1jnkM8-0002zx-Rn for pgsql-general@arkaria.postgresql.org; Tue, 23 Jun 2020 14:57:01 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jnkM7-0006MZ-Er for pgsql-general@arkaria.postgresql.org; Tue, 23 Jun 2020 14:56:59 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jnkM7-0006MS-57 for pgsql-general@lists.postgresql.org; Tue, 23 Jun 2020 14:56:59 +0000 Received: from mail-ot1-x341.google.com ([2607:f8b0:4864:20::341]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jnkM0-0002ix-KL for pgsql-general@lists.postgresql.org; Tue, 23 Jun 2020 14:56:58 +0000 Received: by mail-ot1-x341.google.com with SMTP id 18so2211977otv.6 for ; Tue, 23 Jun 2020 07:56:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language; bh=2nb8Sp+ucFdqusssQRmUs48BsOpNcsdeAulSlbe+6pM=; b=IsvMLoocIhA+OmW+wT6eRBnBAmkEN+D/Fl1Pgw1EYCgKiBaNQHHH3TARALITdB8E3r i/z+6d0dhANQeyb7IXFcQjKHkYyys8D7H1GMPLa3l5n5iKVBTk+OxZxxpMMl2xflJ/pj ZWFPJkl2DVNWUcbpch8e8r0R43ulIXxhxvzYHxrg8dCihbp6d0AnKuKmTAjaa4AjVrqt kgeGdWLeRJOyeaxnM8aMdPtNt/UGONVPQbPoH728Nakrg5AyV0oM6M7JPZI78xBfbeh5 9SkdhBagdIgrZKrWOVviRyDL7q+vzZX1qdaV3DvtcGfqW70szjmMX2VyXgUTUnRGe4Uc 0pmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=2nb8Sp+ucFdqusssQRmUs48BsOpNcsdeAulSlbe+6pM=; b=spAboh1I6QVM5uQ2Yxdj/o4rIlD0jOjhMcwCFQX47WQEq7iyipEEL1QX6ojgqdYI0a HJJPFAxP+jvCGQfzerZW5gU711rFXFSnLx7hNESSVIUGWPE/trbdMiOdrniz9wmv5Bpm 6aF94iMb1WAGBO2GJdxrLQtQyWou18FIVuQyskUIZ/zK9VFTT9UuoXH3zXGl4FXu1mJU KbPLfZJO6g6ZS5kk9sN9MqkimL/RF7/JOnT5Ipwex2eB7+yvZ774w6XT52Y+5LoEiZDH IW5eBduLL2UrioIOjXb3uHNAoCZETuHlqGj86qk1wsh0blo/lWpkvTn/MKK5Dh6IJ8nz CcBw== X-Gm-Message-State: AOAM531IFPPpXJSnpuHr/2pJ1omPmm/qNMZuqw7gHT0d5kaUX8vk1JOA ri6MQxQvZcajXtAiMxRl/l8ATax4GUORiw== X-Google-Smtp-Source: ABdhPJx8CWPHnJeUddsHTfNizxmD2aVe6rGu8KMzy1CMDmx3OzHImI14ezIClwOoJdZHU6UOwtsIjA== X-Received: by 2002:a05:6830:1df6:: with SMTP id b22mr18654592otj.98.1592924210563; Tue, 23 Jun 2020 07:56:50 -0700 (PDT) Received: from [192.168.1.10] (ip70-186-126-197.no.no.cox.net. [70.186.126.197]) by smtp.googlemail.com with ESMTPSA id b3sm1073475ooa.27.2020.06.23.07.56.49 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 23 Jun 2020 07:56:49 -0700 (PDT) Subject: Re: UPDATE on 20 Million Records Transaction or not? To: pgsql-general@lists.postgresql.org References: From: Ron Message-ID: Date: Tue, 23 Jun 2020 09:56:48 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/alternative; boundary="------------E82F1A3A1DC93C80499B1AD1" Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------E82F1A3A1DC93C80499B1AD1 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit On 6/23/20 8:32 AM, Jason Ralph wrote: > > Hello List, > > PostgreSQL 11.8 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.4.7 > 20120313 (R > > ed Hat 4.4.7-23), 64-bit > > I am planning an update on a table with 20Million records, I have been > researching the best practices.  I will remove all indexes and foreign > keys prior to the update, however I am not sure if I should use a > transaction or not. > > My thought process is that a transaction would be easier to recover if > something fails, however it would take more time to write to the WAL log > in a transaction. > Are you updating *every* row in the table? Are you updating indexed fields?  (If not, then leave the indexes and FKs, since they won't be touched.) > Would it make sense to make a back up of the table then execute update > without a transaction? > Always make a backup. > How would you guys do it? > It depends on what percentage of the rows are being updated, which columns are being updated and how big the records are. -- Angular momentum makes the world go 'round. --------------E82F1A3A1DC93C80499B1AD1 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit On 6/23/20 8:32 AM, Jason Ralph wrote:

Hello List,

PostgreSQL 11.8 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.4.7 20120313 (R

ed Hat 4.4.7-23), 64-bit

 

I am planning an update on a table with 20Million records, I have been researching the best practices.  I will remove all indexes and foreign keys prior to the update, however I am not sure if I should use a transaction or not.

My thought process is that a transaction would be easier to recover if something fails, however it would take more time to write to the WAL log in a transaction. 


Are you updating every row in the table?

Are you updating indexed fields?  (If not, then leave the indexes and FKs, since they won't be touched.)

 

Would it make sense to make a back up of the table then execute update without a transaction?


Always make a backup.

How would you guys do it?


It depends on what percentage of the rows are being updated, which columns are being updated and how big the records are.


--
Angular momentum makes the world go 'round.
--------------E82F1A3A1DC93C80499B1AD1--