pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Laurenz Albe <laurenz.albe@cybertec.at>
To: Dominique Devienne <ddevienne@gmail.com>
To: Michael Paquier <michael@paquier.xyz>
Cc: rob stone <floriparob@tpg.com.au>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: How to force "re-TOAST" after changing STORAGE or COMPRESSION?
Date: Tue, 03 Oct 2023 09:17:49 +0200
Message-ID: <2eb92d315e13af55c96c12f7b0ea1e9b6d5826a3.camel@cybertec.at> (raw)
In-Reply-To: <CAFCRh-9Fy=R9gE6oJkfnAvPqzZ1BtKZv7Qp-cAP8Ebde6KBhig@mail.gmail.com>
References: <CAFCRh-8_EFUgKSNpsyideokDo+j80iPg4GVwNoukniOjpZVnng@mail.gmail.com>
	<ZRtY5lEDPlSQuore@paquier.xyz>
	<069c100e455299d6e1aa80bda283a397fadf1926.camel@tpg.com.au>
	<f8ddee9d35553f802b5c1b1968f6c4c72a1640f1.camel@cybertec.at>
	<ZRucYsOTalCdlSzU@paquier.xyz>
	<CAFCRh-9Fy=R9gE6oJkfnAvPqzZ1BtKZv7Qp-cAP8Ebde6KBhig@mail.gmail.com>

On Tue, 2023-10-03 at 09:08 +0200, Dominique Devienne wrote:
>  In my case, it's OK not to be transactional, for these experiments. Is there a way
> to lock the table and do the rewriting w/o generating any WAL? I don't have any experience
> with unlogged tables, but should I take an exclusive lock on the table, switch it to unlogged,
> rewrite, and switch it back to logged?

The only way to avoid WAL is to use unlogged tables, but they lose their data after
a crash.  If you change an unlogged table to a logged table, the whol table ends up
in WAL, so you won't save anything that way.

The best thing that you can do to reduce the amount of WAL is to TRUNCATE and
populate the table in the same transaction.  Then, if you have "wal_level = minimal",
PostgreSQL can forego writing WAL information.  But you cannot have archive recovery
and replication with "wal_level = minimal".

> What about my last question about whether storage=extended always being compressed?
> Given that I don't see much compression, at least when looking indirectly via total-rel-sizes?
> Is there a way to evaluate the compression ratios achieved on TOASTED values?

If you don't see much compression in your toasted data, it is possible that you are
storing data that are already compressed.  In that case, PostgreSQL will attempt
compression with its algorithms that are geared at speed rather than good compression.
If it finds that the data grew after compression, it will discard the compressed value
and continue with the original value.  To avoid that useless compression attempt,
you should use STORAGE EXTERNAL in such cases.

Yours,
Laurenz Albe





view thread (9+ messages)  latest in thread

Message-ID: <2eb92d315e13af55c96c12f7b0ea1e9b6d5826a3.camel@cybertec.at>
Permalink:  ../2eb92d315e13af55c96c12f7b0ea1e9b6d5826a3.camel@cybertec.at/
Also on:    postgresql.org/message-id/2eb92d315e13af55c96c12f7b0ea1e9b6d5826a3.camel@cybertec.at

 · 

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: laurenz.albe@cybertec.at, ddevienne@gmail.com, michael@paquier.xyz, floriparob@tpg.com.au
  Subject: Re: How to force "re-TOAST" after changing STORAGE or COMPRESSION?
  In-Reply-To: <2eb92d315e13af55c96c12f7b0ea1e9b6d5826a3.camel@cybertec.at>
  References: <CAFCRh-8_EFUgKSNpsyideokDo+j80iPg4GVwNoukniOjpZVnng@mail.gmail.com> <ZRtY5lEDPlSQuore@paquier.xyz> <069c100e455299d6e1aa80bda283a397fadf1926.camel@tpg.com.au> <f8ddee9d35553f802b5c1b1968f6c4c72a1640f1.camel@cybertec.at> <ZRucYsOTalCdlSzU@paquier.xyz> <CAFCRh-9Fy=R9gE6oJkfnAvPqzZ1BtKZv7Qp-cAP8Ebde6KBhig@mail.gmail.com> <2eb92d315e13af55c96c12f7b0ea1e9b6d5826a3.camel@cybertec.at>

* 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