Skip to content

feat(node,store): shrink the blocks table after compressing - #6861

Draft
MoonBoi9001 wants to merge 11 commits into
mb9/pause-compressing-blocks-when-unsafefrom
mb9/give-compressed-block-space-back-to-disk
Draft

MoonBoi9001 wants to merge 11 commits into
mb9/pause-compressing-blocks-when-unsafefrom
mb9/give-compressed-block-space-back-to-disk

Conversation

@MoonBoi9001

Copy link
Copy Markdown
Member

Adds graphman chain compress-blocks <chain> shrink, which gives the space freed by compressing blocks back to the disk. It moves the last blocks in the TOAST table into free space nearer the start, so VACUUM can truncate the end. It needs Postgres 17 or later, plus grant usage on schema pg_toast for a user that is not a superuser.

Rewriting blocks frees space inside the table, but its files stay as big. Add a shrink command
for Postgres 17 and later that moves the blocks at the end of the table into that free space
and lets VACUUM cut off the empty end, a slice at a time, with the same pacing and pauses.
Explain how compress-blocks shrink gives the space that rewriting blocks freed back to the disk,
what it needs, the map it keeps while it works, and what its truncation costs replicas.
Shrinking the blocks table compressed every uncompressed block it moved unless told otherwise,
which changed how blocks are stored without being asked. Move blocks as they are by default,
and change how they are stored only when --compression is given.
Shrinking kept its map from TOAST values to blocks in an unlogged table in the chain's schema,
which an interrupted run left behind. Keep it in a temporary table of the connection that
shrinks, and close that connection afterwards, so the map goes away however shrinking ends.
Check that an owner who is no superuser can shrink the blocks table once it may read TOAST
tables, and that blocks a node changes or adds while shrinking runs keep what the node wrote.
Shrinking added the missing data_zstd column before it checked that the user owns the blocks
table, so a user who does not own it tried to add the column for about a minute. Check first.
The test that shrinks the blocks table as an owner who is no superuser ran VACUUM as the
superuser and never checked the result. Run that VACUUM as the owner and check the table shrank.
@MoonBoi9001
MoonBoi9001 added this pull request to stack #6852 December 4, 2026 01:03
Shrinking moves as many blocks at once as compressing does, which is now up to 10,000, so a
batch of big blocks could take GBs of memory. Its batches now also end at 32 MiB of blocks.
…-compressed-block-space-back-to-disk

# Conflicts:
#	store/postgres/src/compress_blocks.rs

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant