pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ron <ronljohnsonjr@gmail.com>
To: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re: UPDATE on 20 Million Records Transaction or not?
Date: Tue, 23 Jun 2020 10:36:31 -0500
Message-ID: <023c409e-5313-735d-6c26-4c3a300310fd@gmail.com> (raw)
In-Reply-To: <BN7PR04MB3826F4CB9DCD8810AF2C9AFDD0940@BN7PR04MB3826.namprd04.prod.outlook.com>
References: <BN7PR04MB382623164C18461A1DDB6242D0940@BN7PR04MB3826.namprd04.prod.outlook.com>
	<d9d78de2-21c7-3999-beed-62458347d83b@gmail.com>
	<BN7PR04MB3826F4CB9DCD8810AF2C9AFDD0940@BN7PR04MB3826.namprd04.prod.outlook.com>


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.

view thread (12+ messages)  latest in thread

Message-ID: <023c409e-5313-735d-6c26-4c3a300310fd@gmail.com>
Permalink:  ../023c409e-5313-735d-6c26-4c3a300310fd@gmail.com/
Also on:    postgresql.org/message-id/023c409e-5313-735d-6c26-4c3a300310fd@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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: ronljohnsonjr@gmail.com
  Subject: Re: UPDATE on 20 Million Records Transaction or not?
  In-Reply-To: <023c409e-5313-735d-6c26-4c3a300310fd@gmail.com>
  References: <BN7PR04MB382623164C18461A1DDB6242D0940@BN7PR04MB3826.namprd04.prod.outlook.com> <d9d78de2-21c7-3999-beed-62458347d83b@gmail.com> <BN7PR04MB3826F4CB9DCD8810AF2C9AFDD0940@BN7PR04MB3826.namprd04.prod.outlook.com> <023c409e-5313-735d-6c26-4c3a300310fd@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