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 1mc99c-0004V8-CL for pgsql-general@arkaria.postgresql.org; Sun, 17 Oct 2021 16:36:56 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mc99Z-00087L-8D for pgsql-general@arkaria.postgresql.org; Sun, 17 Oct 2021 16:36:53 +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 1mc99Y-00087B-Nu for pgsql-general@lists.postgresql.org; Sun, 17 Oct 2021 16:36:52 +0000 Received: from mail-ot1-x32e.google.com ([2607:f8b0:4864:20::32e]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1mc99P-0003ui-SX for pgsql-general@lists.postgresql.org; Sun, 17 Oct 2021 16:36:51 +0000 Received: by mail-ot1-x32e.google.com with SMTP id p6-20020a9d7446000000b0054e6bb223f3so243465otk.3 for ; Sun, 17 Oct 2021 09:36:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language; bh=zrTBTmGqQBTmJ1Z8fUk9H9V5nO7hSLT01w2GcNorDyo=; b=VhmJ6SuPHCFoauTsHxNu/VANhPnvnq3hr3ovFNophNpHC22BsDa6058jxAqf3NPe4k 1m739vi3sfMNMxde813xkKM/XhisYiDKhYsI5paO8IlbZwd27WzJ5n7uoK9lLH+NosLj gjlLm68u5X5fWq+LkRLKU9X9vnJ0q1cnlYvpHkpc1RKIL/8FuoNTEeyzKtizgQuziDVz p3yoGNkda3tHWwMOd0kavwWxzaM5FMyTz6iU3OGS614R9DEfOBFUsu9jCpr+pYNOelZE 818wqewicLXpMHsjtpeGEtiGzsoq4Bw3YqLDj5chH06eYODkgEmdn/3NytwqGJAsKAIP aYGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=zrTBTmGqQBTmJ1Z8fUk9H9V5nO7hSLT01w2GcNorDyo=; b=5fd3NMVNtSP6SAiLJTQ3td+U78Mg/oZkKazB6r+xXFlpejaJf1y2+Sf0U8qJzqzt8I 04Ma+yYQGJk5J0qMBc8fa90LaJeiVzuUcD3ENyDI10H+5NBSX0fsuL8vbjfefdAmkvLt TXdKaLUDlLsnFyLgrbS8Mzw1p0sOYaM4Ka0zJylVfHmInYvqOvI4YWRMqZy1O9WyuwQT SHnevMsHqofOXxdJZmAfhwPnOHY4STY/FYHU8pp+0FoNiGWBB5ImOCaHC1GHrabeHQsY KkBqcUKV6wVmPKnMErhvmrCpjnLHhiyM78TrrfrxLC2e+8P7RFrmLaeVaG3Dpzic5dbh RNSg== X-Gm-Message-State: AOAM533G6mho+iZYrrfP8SYU/innbPws9vT7W2G75AHucYgFrSPXRs8/ H/yk4pN2E/Ho3NdO4GRDhHzpFxxUGUQ= X-Google-Smtp-Source: ABdhPJzq8MhW6Zfe0+ltgD7yiOLOIxSmuCd4NTDxx/ApPO+kmKkWyutD4PtH4tYLP8BaNSSloB5+Vw== X-Received: by 2002:a9d:842:: with SMTP id 60mr17942194oty.302.1634488602578; Sun, 17 Oct 2021 09:36:42 -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 h17sm368014otm.69.2021.10.17.09.36.41 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 17 Oct 2021 09:36:41 -0700 (PDT) Subject: Re: Force re-compression with lz4 To: pgsql-general@lists.postgresql.org References: From: Ron Message-ID: <08365af1-e076-fe67-6de8-333e1118281e@gmail.com> Date: Sun, 17 Oct 2021 11:36:40 -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: Content-Type: multipart/alternative; boundary="------------15DD86B202C21F90F45E7FDD" 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. --------------15DD86B202C21F90F45E7FDD Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit 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; COPY t FROM '/some/file.csv'; -- Angular momentum makes the world go 'round. --------------15DD86B202C21F90F45E7FDD Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit 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;
COPY t FROM '/some/file.csv';

--
Angular momentum makes the world go 'round.
--------------15DD86B202C21F90F45E7FDD--