pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ron <ronljohnsonjr@gmail.com>
To: pgsql-general@lists.postgresql.org
Subject: Re: Force re-compression with lz4
Date: Sun, 17 Oct 2021 11:36:40 -0500
Message-ID: <08365af1-e076-fe67-6de8-333e1118281e@gmail.com> (raw)
In-Reply-To: <EDA6D3AC-7B66-46CB-821E-7F2E8FBBFAC0@gmail.com>
References: <EDA6D3AC-7B66-46CB-821E-7F2E8FBBFAC0@gmail.com>

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.

view thread (18+ messages)  latest in thread

Message-ID: <08365af1-e076-fe67-6de8-333e1118281e@gmail.com>
Permalink:  ../08365af1-e076-fe67-6de8-333e1118281e@gmail.com/
Also on:    postgresql.org/message-id/08365af1-e076-fe67-6de8-333e1118281e@gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: ronljohnsonjr@gmail.com
  Subject: Re: Force re-compression with lz4
  In-Reply-To: <08365af1-e076-fe67-6de8-333e1118281e@gmail.com>
  References: <EDA6D3AC-7B66-46CB-821E-7F2E8FBBFAC0@gmail.com> <08365af1-e076-fe67-6de8-333e1118281e@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox