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 1jnkyY-0004Tp-C0 for pgsql-general@arkaria.postgresql.org; Tue, 23 Jun 2020 15:36:42 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jnkyX-0007f8-97 for pgsql-general@arkaria.postgresql.org; Tue, 23 Jun 2020 15:36: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 1jnkyW-0007f1-MM for pgsql-general@lists.postgresql.org; Tue, 23 Jun 2020 15:36:41 +0000 Received: from mail-oi1-x232.google.com ([2607:f8b0:4864:20::232]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jnkyQ-0004u0-1n for pgsql-general@lists.postgresql.org; Tue, 23 Jun 2020 15:36:39 +0000 Received: by mail-oi1-x232.google.com with SMTP id r8so573009oij.5 for ; Tue, 23 Jun 2020 08:36:33 -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=MLJDuHI24nf2Gy+M043aw+mQM3OG2UKs6LawAj2NupY=; b=JuI6IO6v4YZIed2dXrsk9FjXhnddiES22CgSk7UsSBhKkULIy2IXLmQ4HsgbG45KEv hLEi/XXa/40SJCckRjTs05ZRyqUSpNWNKDKX11F59i1QjhPVTi/9PsUikNIfm33bWihx 2ymtkdupD+3DN32rMysNhzKMiImqNmdayTrQRKDRSzzizyBjOydibs36CDG8rYS0rZxO gMQfABzGqQnFWLEqYJPvmlUWELNAM7833Ox4kFE9AbE1ppVjkWKZj3m4TQ8UUA9DZ3hi 8il2+sK/VA97AjGfREms+KvE2vi2zaFBKhjGCAtY2SE82F28H4kzfzRn7z112tF5HQVj ZvDg== 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=MLJDuHI24nf2Gy+M043aw+mQM3OG2UKs6LawAj2NupY=; b=ZhGrMJw3nsSZtKWFb+V8ibgZAVYpg9YRoSFoeX951ttV1KN24FAIERJ3drcXLCsgx0 6jBV7o/2x16tckhpBp2RxXwzIxWrKV4A1oQvendGe02MujWpdlLvyBXPQqf5rmQOQVBB ZUdKWYSScfqV9Pt48s4PKLN4nMWX0o8N0LV/8ooUHwbine30WLs34MbXsRzt0grqNJwG +OUMlpOxxCTdzVNgVEXzzVs1tuEXOCje1/i3yukq1vo3wln5TakkeY2+4HdOdhCC/rdV 5wPSyiwT9bNj/lzqTy7EyR8+uskED3nrcoTHiwjRjP9MGwm+myr0XCI7T2Ldtkd73RAN dPnA== X-Gm-Message-State: AOAM532Kxh3i84TRlzSQWbG8M1UMg850beGy+RR7EgA3WOv5bXmxkDGT 2vmCULs9Rj31lI8bhZZ9ntYy5P1mZ1G1VQ== X-Google-Smtp-Source: ABdhPJxYjtnHgNoejAC2WAsjEIRD8xBVjrPem67bfN1QPMZuHaB1t20XGIX+SDHzy587TJpmNEANnQ== X-Received: by 2002:aca:e044:: with SMTP id x65mr17577397oig.56.1592926592954; Tue, 23 Jun 2020 08:36:32 -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 t18sm4120949otk.42.2020.06.23.08.36.31 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 23 Jun 2020 08:36:32 -0700 (PDT) Subject: Re: UPDATE on 20 Million Records Transaction or not? To: "pgsql-general@lists.postgresql.org" References: From: Ron Message-ID: <023c409e-5313-735d-6c26-4c3a300310fd@gmail.com> Date: Tue, 23 Jun 2020 10:36:31 -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="------------14BF7B6573B976CCFE63E98E" 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. --------------14BF7B6573B976CCFE63E98E Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit I'd make a copy of the table, and test how long the various methods take. On 6/23/20 10:17 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? > > No I am using an update like so: UPDATE members SET regdate='2038-01-18' > WHERE regdate='2020-07-07' > > DB=# select count(*) from members where regdate = '2020-07-07'; > >   count > > ---------- > > 17333090 > > (1 row) > > >Are you updating indexed fields?  (If not, then leave the indexes and > FKs, since they won't be touched.) > > Just checked regdate is not indexed so I will leave them in place. > > > Would it make sense to make a back up of the table then execute update > without a transaction? > > > >Always make a backup. > > Agreed > > > 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. > > Please see above, thanks > > *Jason Ralph* > > *From:* Ron > *Sent:* Tuesday, June 23, 2020 10:57 AM > *To:* pgsql-general@lists.postgresql.org > *Subject:* Re: UPDATE on 20 Million Records Transaction or not? > > 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. > > This message contains confidential information and is intended only for > the individual named. If you are not the named addressee you should not > disseminate, distribute or copy this e-mail. Please notify the sender > immediately by e-mail if you have received this e-mail by mistake and > delete this e-mail from your system. E-mail transmission cannot be > guaranteed to be secure or error-free as information could be intercepted, > corrupted, lost, destroyed, arrive late or incomplete, or contain viruses. > The sender therefore does not accept liability for any errors or omissions > in the contents of this message, which arise as a result of e-mail > transmission. If verification is required please request a hard-copy version. -- Angular momentum makes the world go 'round. --------------14BF7B6573B976CCFE63E98E Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit
I'd make a copy of the table, and test how long the various methods take.

On 6/23/20 10:17 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?

No I am using an update like so: UPDATE members SET regdate='2038-01-18' WHERE regdate='2020-07-07'

DB=# select count(*) from members where regdate = '2020-07-07';

  count  

----------

17333090

(1 row)

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

Just checked regdate is not indexed so I will leave them in place.


 

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


>Always make a backup.

Agreed


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.

Please see above, thanks

 

Jason Ralph

 

From: Ron <ronljohnsonjr@gmail.com>
Sent: Tuesday, June 23, 2020 10:57 AM
To: pgsql-general@lists.postgresql.org
Subject: Re: UPDATE on 20 Million Records Transaction or not?

 

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.

This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. E-mail transmission cannot be guaranteed to be secure or error-free as information could be intercepted, corrupted, lost, destroyed, arrive late or incomplete, or contain viruses. The sender therefore does not accept liability for any errors or omissions in the contents of this message, which arise as a result of e-mail transmission. If verification is required please request a hard-copy version.

--
Angular momentum makes the world go 'round.
--------------14BF7B6573B976CCFE63E98E--