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 1mc9Bq-0004cQ-Ny for pgsql-general@arkaria.postgresql.org; Sun, 17 Oct 2021 16:39:14 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mc9Bp-0003Zz-MC for pgsql-general@arkaria.postgresql.org; Sun, 17 Oct 2021 16:39:13 +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 1mc9Bp-0003Zq-BD for pgsql-general@lists.postgresql.org; Sun, 17 Oct 2021 16:39:13 +0000 Received: from mail-oi1-x22d.google.com ([2607:f8b0:4864:20::22d]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1mc9Bn-0005LK-UU for pgsql-general@lists.postgresql.org; Sun, 17 Oct 2021 16:39:13 +0000 Received: by mail-oi1-x22d.google.com with SMTP id g125so21062459oif.9 for ; Sun, 17 Oct 2021 09:39:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=subject:from:to:references:message-id:date:user-agent:mime-version :in-reply-to:content-language; bh=nFiXrUXjd4ESfVaYp+vfebKSHORX+i6II8vEkCHniC4=; b=O8C3t0o9cl8XEIavRglg7fTWBrFw/CMb1HewHFvtVWgNS/47AvqGsgWPtsJsvr5qhi xR4dAQS16Y0vAXE4rNGh1Yx7+aH9Cr5bTtBsapwZY1+FGfGfcQLQn759Vvs3bUQm17w4 I3p5/EFM1LJl6u80N41XXPq2OooSGwy+GokTlkc4KarOdz085517j4xXD+ZuL9pLDoXv GsT3zY8sAwq8oNbNW0rqqOGOXsZqO8fnkk7A8GDPBzm3LaHSTHNXWNK4IRz3f7ySLUGF KK9BRGhYDivp2D6lfHY5KoRQsZu/ZTxcynfeDfq2B8bUrF5tkYzCULRoB8zsWd1KvMcS BA/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:from:to:references:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=nFiXrUXjd4ESfVaYp+vfebKSHORX+i6II8vEkCHniC4=; b=R+3ayyt+Mb57uAYXXoHCnwuHaj10XFfTeFc8Ge4yqpP+zHh3ro9/K5BcjehAxaaSQd SGvWLAZFeJmRS8BD8ltvxAeaS31PueqsBQgM7aSVhLOEIF8XpXtzdbT5NOMvvhxvz4lH 9Xk67LMnvJt3fijcPBvasjC0wu9ygo+mlhMd83g1lcIXHvr4pd3hJT5246Rslz5sku1K 3SlR99kFSgHUbV5PK6izOltvtnxM0mepzJ2iNEDJjHKVnyE2yvJPIkzFMH3DIJ43ciCy OcQ2XB2yoRsqCl7llta8MhZRhBOxKf2Of8sSR83vpVUwbcf7pMw3Bg4h/IzV5+uSEWkq /YhQ== X-Gm-Message-State: AOAM532AWud+kjEuTovTve1ioRr+yHEl2Cv1LEJ+phe3LCQq+ee4zk5d f2Jqw8wi1gFVYgdIdbzpkymUI9h9Na0= X-Google-Smtp-Source: ABdhPJwcbp8W6RAkCTwRJhp+iQ6uK1D8mQBB63lz4cV5CI3QZzaQbdq1qEnTS++f7AJb8qHqaKLx8w== X-Received: by 2002:aca:c156:: with SMTP id r83mr26321464oif.78.1634488749460; Sun, 17 Oct 2021 09:39:09 -0700 (PDT) Received: from [192.168.88.10] (ip68-11-68-85.no.no.cox.net. [68.11.68.85]) by smtp.googlemail.com with ESMTPSA id a15sm2680973oiw.53.2021.10.17.09.39.08 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 17 Oct 2021 09:39:08 -0700 (PDT) Subject: Re: Force re-compression with lz4 From: Ron To: pgsql-general@lists.postgresql.org References: <08365af1-e076-fe67-6de8-333e1118281e@gmail.com> Message-ID: <1b985e59-74b2-7a0d-9594-9df2c76efb4c@gmail.com> Date: Sun, 17 Oct 2021 11:39:07 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: <08365af1-e076-fe67-6de8-333e1118281e@gmail.com> Content-Type: multipart/alternative; boundary="------------CF1AFFD537592B4302D25D07" Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------CF1AFFD537592B4302D25D07 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit On 10/17/21 11:36 AM, Ron wrote: > On 10/17/21 10:12 AM, Florents Tselai wrote: >> Hello, >> >> I have a table storing mostly text data (40M+ rows) that has >> pg_total_relation_size ~670GB. >> I’ve just upgraded to postgres 14 and I’m now eager to try the new LZ4 >> compression. >> >> I’ve altered the column to use the new lz4 compression, but that only >> applies to new rows. >> >> What’s the recommended way of triggering the re-evaluation for >> pre-existing rows? >> >> I tried wrapping a function like the following, but apparently each old >> record retains the compression applied. >> text_corpus=(SELECT t.text from...); delete from t where id=; insert into >> t(id, text) values (id, text_corpus); > > Because it's all in one transaction? > >> Fttb, I resorted to preparing an external shell script to execute against >> the db but that’s too slow as it moves data in&out the db. >> >> Is there a smarter way to do this ? > > Even with in-place compression, you've got to read the uncompressed data. > > Does your shell script process one record at a time?  Maybe do ranges: > COPY (SELECT * FROM t WHERE id BETWEEN x AND y) TO '/some/file.csv'; > DELETE FROM t WHERE id BETWEEN x AND y; I forgot to mention: VACUUM t; > COPY t FROM '/some/file.csv'; -- Angular momentum makes the world go 'round. --------------CF1AFFD537592B4302D25D07 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit On 10/17/21 11:36 AM, Ron wrote:
On 10/17/21 10:12 AM, Florents Tselai wrote:
Hello,

I have a table storing mostly text data (40M+ rows) that has pg_total_relation_size ~670GB.
I’ve just upgraded to postgres 14 and I’m now eager to try the new LZ4 compression.

I’ve altered the column to use the new lz4 compression, but that only applies to new rows.

What’s the recommended way of triggering the re-evaluation for pre-existing rows? 

I tried wrapping a function like the following, but apparently each old record retains the compression applied.
text_corpus=(SELECT t.text from ...);

delete from t where id=;

insert into t(id, text) values (id, text_corpus);

Because it's all in one transaction?

Fttb, I resorted to preparing an external shell script to execute against the db but that’s too slow as it moves data in&out the db.

Is there a smarter way to do this ?

Even with in-place compression, you've got to read the uncompressed data.

Does your shell script process one record at a time?  Maybe do ranges:
COPY (SELECT * FROM t WHERE id BETWEEN x AND y) TO '/some/file.csv';
DELETE FROM t WHERE id BETWEEN x AND y;
I forgot to mention:
VACUUM t;
COPY t FROM '/some/file.csv';

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