Re: Understanding WAL - large amount of activity from removing data - Mailing list pgsql-hackers

From David G. Johnston
Subject Re: Understanding WAL - large amount of activity from removing data
Date
Msg-id CAKFQuwY6nKw38LT7bsyiZ-db7+ALbSO1gKc-vFWC7BL_zYqxwQ@mail.gmail.com
Whole thread Raw
In response to Understanding WAL - large amount of activity from removing data  (Isaac Morland <isaac.morland@gmail.com>)
Responses Re: Understanding WAL - large amount of activity from removing data
List pgsql-hackers
On Sun, Nov 20, 2022 at 6:24 PM Isaac Morland <isaac.morland@gmail.com> wrote:
What I'm finding is that the UPDATE is taking over an hour for 5000 records, and tons of WAL is being generated, several files per minute. Selecting the non-PDF columns from the entire table takes a few milliseconds, and the only thing I'm doing with the records is updating them to much smaller values. Why so much activity just to remove data? The new rows are tiny.

Simplistic answer (partly because the second part of this isn't spelled out explicitly in the docs that I could find) when you UPDATE two things happen, the old record is modified to indicate it has been deleted and a new record is inserted.  Both of these are written to the WAL, and a record is always written to the WAL as a self-contained unit, so the old record is full sized in the newly written WAL.  TOAST apparently has an optimization if you don't change the TOASTed value, but here you are so that optimization doesn't apply.

David J.

pgsql-hackers by date:

Previous
From: Isaac Morland
Date:
Subject: Understanding WAL - large amount of activity from removing data
Next
From: Kyotaro Horiguchi
Date:
Subject: Re: when the startup process doesn't (logging startup delays)