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 1jVj5g-0007N5-9q for pgsql-general@arkaria.postgresql.org; Mon, 04 May 2020 21:57:32 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jVj5e-0002uR-QM for pgsql-general@arkaria.postgresql.org; Mon, 04 May 2020 21:57:30 +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 1jVj5e-0002uJ-FY for pgsql-general@lists.postgresql.org; Mon, 04 May 2020 21:57:30 +0000 Received: from mail-il1-x144.google.com ([2607:f8b0:4864:20::144]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jVj5b-0004g1-Ud for pgsql-general@lists.postgresql.org; Mon, 04 May 2020 21:57:29 +0000 Received: by mail-il1-x144.google.com with SMTP id f82so357873ilh.8 for ; Mon, 04 May 2020 14:57:27 -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=ber28Arf/VA7ZK2PdDIMn+8e7I4/N0bvatLsDtK711A=; b=M1Iu42tYwdvei6rCo996oABTIsGoIx8rzXq0XCtMhsQQUv/7GfvQOb4xUBk74QQc4g yvawGVr7wGQRF0fqQfTYkKs3wz6W8OGq8BBm2aKoqYd3bmgZIjY+JxvS9O04XJ6+Ag6q J76XXQprjN5OvhGYjzv1DpwN00IvRXOtGpO8Dnwp/jVeOvc6F4rDaF2Fgw7sue5+FA0w hxFt8g1ot0VD6uoZjeJfd1cXEKnU4nw2nUFbg9xzaRt7+BvEcORUaT61LwnUmOdBCaqG JS0uvcQkQL3p8s/SjbRkIa7XPwefc6dU1MGFCHy396S3kF69apxoUr6CgaLkI0dEUkVZ BCvg== 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=ber28Arf/VA7ZK2PdDIMn+8e7I4/N0bvatLsDtK711A=; b=ONMSWZ6X9TFbF3HzMLd5+lmiTHJ5yf5/Nv22G24RBHthPmy6q0Ni5Vohw0tIQhYYxi fCyD0fSRmJCt4Ds0afj3NN/tmsc3vVPxB34Jr4/fAC2veIcCEXysaptUwpBDvgMO+GN9 Kuzdr66QyW5hsfEKOrzGr+xO9x0U7M/Mz9gzxfbPVoEOQTSXvnKnQ4hrC3k3CewKE89R sPqQyAgc6MomzD0vGUFXKI+suhSU+InHW3UmZiRmhz2HqU7KsdYzzlnjhpswFi/Dq/z0 yccwQw5MT03uuK6UiKfGFzex+H4hNGZIc09SOdl7OXLSHxIqSfitVBIg0T+INt7BgqM8 RcBw== X-Gm-Message-State: AGi0PuY1dah/SjdCAPXWYP07maZbbn0Q3Ft5V8g+gKEV4SwvdwsP6wMs cwa/Pqlx6izIKeNZJ5Mnn7u6G7CAcSQ= X-Google-Smtp-Source: APiQypJmXCuUv5doA79JsALFz6rf8t58PDyUIyubTCqHbRjSrZh6EdIJ1vGihFkXKV0NiMutwEnZDw== X-Received: by 2002:a92:ba46:: with SMTP id o67mr545596ili.66.1588629445516; Mon, 04 May 2020 14:57:25 -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 m22sm230934iow.35.2020.05.04.14.57.21 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 04 May 2020 14:57:25 -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: <94454b33-1913-ac3c-3437-73e3a5c29c9a@gmail.com> Date: Mon, 4 May 2020 15:57:20 -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="------------962C97EA79F3A6E080B7FB87" 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. --------------962C97EA79F3A6E080B7FB87 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 > Is the new value computable from the original value with a single function? Could you cover your tables with viewa transforming the column with said function? No?  You'll need to divorce each table from that lookup table and any foreign key relationships to avoid all those lookups with ever update. --------------962C97EA79F3A6E080B7FB87 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
Is the new value computable from the original value with a single function? Could you cover your tables with viewa transforming the column with said function?

No?  You'll need to divorce each table from that lookup table and any foreign key relationships to avoid all those lookups with ever update.
--------------962C97EA79F3A6E080B7FB87--