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 1jVknD-0007Zr-E9 for pgsql-general@arkaria.postgresql.org; Mon, 04 May 2020 23:46:35 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jVknC-0003Dj-9J for pgsql-general@arkaria.postgresql.org; Mon, 04 May 2020 23:46:34 +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 1jVknB-0003Dc-Tw for pgsql-general@lists.postgresql.org; Mon, 04 May 2020 23:46:34 +0000 Received: from mail-il1-x132.google.com ([2607:f8b0:4864:20::132]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jVkn9-0005db-Ov for pgsql-general@lists.postgresql.org; Mon, 04 May 2020 23:46:33 +0000 Received: by mail-il1-x132.google.com with SMTP id e8so580103ilm.7 for ; Mon, 04 May 2020 16:46:31 -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=LoobTmk3lrR0SitKdO6fyNHcO7lMFV51Yi7qOQC3EDI=; b=r8lLJ7pHPF+L6bLOkCvtzYyvDb8WKivOz9QboILoC/Ex9E60EMaAvAR7MmETeuhseM w0xJdCM1v6qvOC82Fg6L+C6DG2JZ0sL2Zbww8AAqZPnn+DCPAInHxqxzdm6Yp15Rwci1 ShUKvDacqPNGL0GqgTXt8xP+3eTS9eq90UAUQtE7RuTFpAS53hIRFXWqCdZZaEVI6HtK 4D7kDAUZ4N13GAuiOA4DpbazFRegochi78cxmL4yHqE7DT8Vq7ZZa9cNaSGL6DL8xUtF sFQFX/bR6SMunDj+UccE8OZ/wXkY/R8Yyk8+d+XvlHGNhbLn8dk2T9X0keAoYZ1uTobX NFnA== 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=LoobTmk3lrR0SitKdO6fyNHcO7lMFV51Yi7qOQC3EDI=; b=iR2l+NTB4UuaWwhltIT/6FH7FQs4QMwVTxCfyw40bmw9eDrLfkeT8rzKmuP8L1ttD6 MKkfuTxv044PHd/chxTqzr3w40AZEEDTC91VWVPkn4sbpyyRdaTGDABGgqE8qZxU1FH2 /mdZXWU2hGWDT3LwR3xD4ntD3344V5n1165UxbSdy929+y9IAp5/H4tEBWA1KyWLbvBz CxWYtf9Fqk17EM9bPTUPa06mxSisEhqn2YXSmIgSoPSY/laqxVoKWE46hjlhZdpGwe3O P/1i2sJAgnA+twkui47wt1hxL4Wxft+JHKFCayee3x+bWmH2hQEJ+Y2pgnLCU7aoRyhP GVTg== X-Gm-Message-State: AGi0PubfhKDokeVstKkc/qGmnWG3gwF/grtyKBqIYlB/hKEVUXpH15U3 PvAoT0d1GyZ/nddF8r80YOuBfTymU5Q= X-Google-Smtp-Source: APiQypJ5m2R8C9nYsoAOjT10FG9aS9EeC5sMZHRqk3Ep4+vdmNygIAc3yLdDyDRVO7CV+rW0f6lKeA== X-Received: by 2002:a92:7303:: with SMTP id o3mr919781ilc.275.1588635989496; Mon, 04 May 2020 16:46:29 -0700 (PDT) Received: from ?IPv6:2601:681:5500:dde0:386a:4779:2217:54f4? ([2601:681:5500:dde0:386a:4779:2217:54f4]) by smtp.gmail.com with ESMTPSA id n25sm392367ion.34.2020.05.04.16.46.28 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 04 May 2020 16:46:29 -0700 (PDT) Subject: Re: Thoughts on how to avoid a massive integer update. To: pgsql-general@lists.postgresql.org References: From: Rob Sargent Message-ID: <1ad51d80-94d5-cd49-cda0-d55daf9bfbb8@gmail.com> Date: Mon, 4 May 2020 17:46:27 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/alternative; boundary="------------B3D5DA65434C766869275753" 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. --------------B3D5DA65434C766869275753 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit On 5/4/20 3:32 PM, Fehrle, Brian wrote: > > Hi all, > > This is a shot in the dark in hopes to find a magic bullet to fix an > issue I have, I can’t personally think of any solution myself. > > I have a database with hundreds of terabytes of data, where every > table has an integer column referencing a small table. For reasons out > of my control and cannot change, I NEED to update every single row in > all these tables, changing the integer value to a different integer. > > Since I have to deal with dead space, I can only do a couple tables at > a time, then do a vacuum full after each one. > Another option is to build a new table with the new values, then drop > the old one and swap in the new, either way is very time consuming. > > Initial tests suggest this effort will take several months to > complete, not to mention cause blocking issues on tables being worked on. > > Does anyone have any hackery ideas on how to achieve this in less > time? I was looking at possibly converting the integer column type to > another that would present the integer differently, like a hex value, > but everything still ends up requiring all data to be re-written to > disk. In a well designed database (I didn’t design it :) ), I would > simply change the data in the referenced table (200 total rows), > however the key being referenced isn’t just an arbitrary ID, it’s > actual ‘data’, and must be changed. > > Thanks for any thoughts or ideas, > > * Brian F > Here's my wife solution:  add a column to small table, fill with duplicate of the original column.  Change the foreign keys of the huge tables to reference the new column in the small table.  Update the original values to what you now need them to be.  (Not sure how much re-index cost you'll see here, but non-zero I'm guessing) Your reports now must of course return the new value via joins to the dictionary(?) table.  Views my be your best bet here. --------------B3D5DA65434C766869275753 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit

On 5/4/20 3:32 PM, Fehrle, Brian wrote:

Hi all,

 

This is a shot in the dark in hopes to find a magic bullet to fix an issue I have, I can’t personally think of any solution myself.

 

I have a database with hundreds of terabytes of data, where every table has an integer column referencing a small table. For reasons out of my control and cannot change, I NEED to update every single row in all these tables, changing the integer value to a different integer.

 

Since I have to deal with dead space, I can only do a couple tables at a time, then do a vacuum full after each one.
Another option is to build a new table with the new values, then drop the old one and swap in the new, either way is very time consuming.

 

Initial tests suggest this effort will take several months to complete, not to mention cause blocking issues on tables being worked on.

 

Does anyone have any hackery ideas on how to achieve this in less time? I was looking at possibly converting the integer column type to another that would present the integer differently, like a hex value, but everything still ends up requiring all data to be re-written to disk. In a well designed database (I didn’t design it :) ), I would simply change the data in the referenced table (200 total rows), however the key being referenced isn’t just an arbitrary ID, it’s actual ‘data’, and must be changed.

 

Thanks for any thoughts or ideas,

  • Brian F

Here's my wife solution:  add a column to small table, fill with duplicate of the original column.  Change the foreign keys of the huge tables to reference the new column in the small table.  Update the original values to what you now need them to be.  (Not sure how much re-index cost you'll see here, but non-zero I'm guessing)

Your reports now must of course return the new value via joins to the dictionary(?) table.  Views my be your best bet here.
--------------B3D5DA65434C766869275753--