pgsql: While vacuuming a large table, update upper-level FSM data every

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: While vacuuming a large table, update upper-level FSM data every
Date: 2018-03-29 15:30:03
Message-ID: E1f1ZV5-0001Rz-7p@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

While vacuuming a large table, update upper-level FSM data every so often.

VACUUM updates leaf-level FSM entries immediately after cleaning the
corresponding heap blocks. fsmpage.c updates the intra-page search trees
on the leaf-level FSM pages when this happens, but it does not touch the
upper-level FSM pages, so that the released space might not actually be
findable by searchers. Previously, updating the upper-level pages happened
only at the conclusion of the VACUUM run, in a single FreeSpaceMapVacuum()
call. This is bad because the VACUUM might get canceled before ever
reaching that point, so that from the point of view of searchers no space
has been freed at all, leading to table bloat.

We can improve matters by updating the upper pages immediately after each
cycle of index-cleaning and heap-cleaning, processing just the FSM pages
corresponding to the range of heap blocks we have now fully cleaned.
This adds a small amount of extra work, since the FSM pages leading down
to each range boundary will be touched twice, but it's pretty negligible
compared to everything else going on in a large VACUUM.

If there are no indexes, VACUUM doesn't work in cycles but just cleans
each heap page on first visit. In that case we just arbitrarily update
upper FSM pages after each 8GB of heap. That maintains the goal of not
letting all this work slide until the very end, and it doesn't seem worth
expending extra complexity on a case that so seldom occurs in practice.

In either case, the FSM is fully up to date before any attempt is made
to truncate the relation, so that the most likely scenario for VACUUM
cancellation no longer results in out-of-date upper FSM pages. When
we do successfully truncate, adjusting the FSM to reflect that is now
fully handled within FreeSpaceMapTruncateRel.

Claudio Freire, reviewed by Masahiko Sawada and Jing Wang, some additional
tweaks by me

Discussion: https://postgr.es/m/CAGTBQpYR0uJCNTt3M5GOzBRHo+-GccNO1nCaQ8yEJmZKSW5q1A@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/851a26e26637aac60d6e974acbadb31748b12f86

Modified Files
--------------
src/backend/commands/vacuumlazy.c | 43 ++++++++++--
src/backend/storage/freespace/README | 12 ++--
src/backend/storage/freespace/freespace.c | 107 ++++++++++++++++++++++++++----
src/include/storage/freespace.h | 2 +
4 files changed, 141 insertions(+), 23 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Teodor Sigaev 2018-03-29 16:15:21 Re: pgsql: Add casts from jsonb
Previous Message David Steele 2018-03-29 15:02:32 Re: pgsql: Add documentation for the JIT feature.