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 1mcBS1-000481-Jf for pgsql-general@arkaria.postgresql.org; Sun, 17 Oct 2021 19:04:05 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mcBS0-0005iF-5A for pgsql-general@arkaria.postgresql.org; Sun, 17 Oct 2021 19:04:04 +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 1mcBRz-0005i6-OI for pgsql-general@lists.postgresql.org; Sun, 17 Oct 2021 19:04:03 +0000 Received: from mail-wr1-x42d.google.com ([2a00:1450:4864:20::42d]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1mcBRv-0006RA-Mi for pgsql-general@lists.postgresql.org; Sun, 17 Oct 2021 19:04:01 +0000 Received: by mail-wr1-x42d.google.com with SMTP id r7so37153543wrc.10 for ; Sun, 17 Oct 2021 12:03:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:message-id:mime-version:subject:date:in-reply-to:cc:to :references; bh=g4vTZaKRanvUM5Rb3GF6TMBsd2wXMQCvbiN0ZtljheA=; b=nWFmo8lAdePvQw6fDdpKyx/QTylqWOJgJaBB/Lngfk91L4cwQeKml7kypL0QBfM6Iv +JoLcS3up+pg4y4L9klbpSFGFzXy7evcadovoMKkWV9tWTCJMDBM+cQyKna3BivzZnNJ dYd3LQQfigSjLbrfMQ5bUIlVZ8bOvCX0uARmy3cEVe6eBuWP7BePH5H3bCI579a6PUVh jHy8MkRWBBeSk0EyYjIpMFSDRIhfxX0NK1oqJo2XxIA4MJt6be/z8DzTa3ZmmQTin8Rr l2lFeWKQwCsiqybd3zBOLIbpIEgM8AL6Rci/3+inUG8RWY4gJwQjstMt/btrYV6yz82l aRJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:message-id:mime-version:subject:date :in-reply-to:cc:to:references; bh=g4vTZaKRanvUM5Rb3GF6TMBsd2wXMQCvbiN0ZtljheA=; b=TXl4HS8WcfekexNc16IOQ76bk5o34J9DxRJk5jX8/M7V1CALt+T4l36MilQaEl6XVo P2ALfAWsw3xRpvGAGvTqawO7fduvXhu1BbE8PBEPB8bdlBWADMvhbLW8rkFse2JvRwQA 6QsWthPlGvJqOS610x9qw4w4/yXi4hxcPRtphqADSnKnyYTomGrz6OUpwI8dPGn79Eju /Bnit7s8jYme63TZgEEZq5R2gvtCiNvAZx0eogEqjVGGo1R0tG2NlAkFK2dIVtkW+em8 GmsRPu9NecQh7Hw7Iltin/kqgJPObfzmmo95GaIEekUZkGWeaEX/8XVF5AWIUotMHHte 7Umw== X-Gm-Message-State: AOAM533i90xVyHrNlUtLntAnxLwkg205vvxo6vZXYgYTHccqz2QroUwq rhMrVCreAltbldWArY7D5svmI39atE/EW+RD X-Google-Smtp-Source: ABdhPJxKF1cFjExI0/F2qNv/ucJdcx+QAocBlv2Slpy3eesNl3UeU+bl/8lOJXcNrGvgCSpmhRJfNg== X-Received: by 2002:adf:a78a:: with SMTP id j10mr30832268wrc.105.1634497437382; Sun, 17 Oct 2021 12:03:57 -0700 (PDT) Received: from smtpclient.apple (ppp-94-66-221-255.home.otenet.gr. [94.66.221.255]) by smtp.gmail.com with ESMTPSA id y191sm18787608wmc.36.2021.10.17.12.03.56 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 17 Oct 2021 12:03:56 -0700 (PDT) From: Florents Tselai Message-Id: Content-Type: multipart/alternative; boundary="Apple-Mail=_A2F4A356-5F30-4F2F-9298-F858979AE195" Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.120.0.1.13\)) Subject: Re: Force re-compression with lz4 Date: Sun, 17 Oct 2021 22:03:55 +0300 In-Reply-To: <08365af1-e076-fe67-6de8-333e1118281e@gmail.com> Cc: pgsql-general@lists.postgresql.org To: Ron References: <08365af1-e076-fe67-6de8-333e1118281e@gmail.com> X-Mailer: Apple Mail (2.3654.120.0.1.13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --Apple-Mail=_A2F4A356-5F30-4F2F-9298-F858979AE195 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 Yes, That COPY-delete-COPY sequence is what I ended up doing. Unfortunately can=E2=80=99t use ranges as the PK its a text string. > On 17 Oct 2021, at 7:36 PM, Ron wrote: >=20 > On 10/17/21 10:12 AM, Florents Tselai wrote: >> Hello, >>=20 >> I have a table storing mostly text data (40M+ rows) that has = pg_total_relation_size ~670GB. >> I=E2=80=99ve just upgraded to postgres 14 and I=E2=80=99m now eager = to try the new LZ4 compression. >>=20 >> I=E2=80=99ve altered the column to use the new lz4 compression, but = that only applies to new rows. >>=20 >> What=E2=80=99s the recommended way of triggering the re-evaluation = for pre-existing rows?=20 >>=20 >> I tried wrapping a function like the following, but apparently each = old record retains the compression applied. >> text_corpus=3D(SELECT t.text from ...); >>=20 >> delete from t where id=3D; >>=20 >> insert into t(id, text) values (id, text_corpus); >=20 > Because it's all in one transaction? >=20 >> Fttb, I resorted to preparing an external shell script to execute = against the db but that=E2=80=99s too slow as it moves data in&out the = db. >>=20 >> Is there a smarter way to do this ? >=20 > Even with in-place compression, you've got to read the uncompressed = data. >=20 > 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'; >=20 > --=20 > Angular momentum makes the world go 'round. --Apple-Mail=_A2F4A356-5F30-4F2F-9298-F858979AE195 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8 Yes, = That COPY-delete-COPY sequence is what I ended up doing.
Unfortunately can=E2=80=99t use ranges as the PK its a text = string.

On 17 Oct 2021, at 7:36 PM, Ron <ronljohnsonjr@gmail.com> wrote:

=20 =20
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=E2=80=99ve just upgraded to postgres 14 and = I=E2=80=99m now eager to try the new LZ4 compression.

I=E2=80=99ve altered the column to use the new lz4 compression, but that only applies to new rows.

What=E2=80=99s 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=3D(SELECT t.text from =
...);

delete from =
t where id=3D;

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=E2=80=99s 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.

= --Apple-Mail=_A2F4A356-5F30-4F2F-9298-F858979AE195--