Tables that receive many updates and deletes can build up unused space, known as "bloat," which can also significantly impact query performance. The VACUUM FULL and CLUSTER commands were previously used to handle this, but had tradeoffs, including preventing access to the table until the cleanup finished. PostgreSQL 19 introduces the REPACK command, which reclaims this space and can reorder a table's data to match an index, and with REPACK (CONCURRENTLY), can do so without blocking reads or writes. REPACK replaces the VACUUM FULL and CLUSTER commands, both of which remain available for compatibility.
Probably the best thing about using SQL these days is that you can just kind of expect that the only things added version-over-version are quality of life things.
There are some exceptions, of course, like yesterday I had to contrive a solution in SQL Server 2019 that didn't depend on regex when it would have been immensely helpful. Had to re-educate my brain on using CHARINDEX and SUBSTRING to get the same result. But for the most part, I just know that the syntax will work, and I can do what I want with little concern.
Yeah, regex was just introduced in SQL Server 2025. Still vastly prefer it over Postgres because of clustered indexes, it's just a shame that running it on Linux has so many limitations.
It's not just a matter of randomly placed seeks, for small tuples a clustered index also means you're more likely to have multiple matching tuples per page
Being able to design a clustered index is a means of ordering the data as it is stored within a logical volume. An index seek is akin to accessing an array by its index. An index scan is akin to iterating over the entire array until you find the relevant items. The clustered index is what determines the order. Additionally, SQL Server will take sargable predicates and attempt a binary search to get in the rough area of the table where the relevant rows are.
So, yes, the clustered index is very beneficial. Most other SQL implementations get by using nonclustered indexes for this purpose, and it works well enough.
Unfortunately the new concurrent repack comes with a heck of a caveat:
Warning REPACK with the CONCURRENTLY option is not MVCC-safe. After the repacking transaction commits, the table will appear empty to concurrent transactions, if they are using a snapshot taken before repacking started. See Section 13.6 for more details.
If i understand correctly the sequencing needs to be: TransactionStart -> RepackStart -> RepackEnd (-> TransactionRead) -> TransactionEnd
Sounds like it only becomes an issue when the transaction runs longer than the repack in which case either the transaction takes too long or your REPACK is very fast (which i assume implies small tables or little need for work to be done).
From the top of my head the only scenario where this becomes a concern is if you have something long running like a nightly report and someone decides to schedule a REPACK during the night.
Otherwise i'd say optimize your transactions and make sure you only run REPACK when necessary.
That's my reading too - it's up to you to make sure no long-running transactions might use a stale snapshot. Most transactions are probably both short, and use the default read committed isolation level which takes a fresh snapshot for each statement, so the set of scenarios where it's likely to be a problem seems fairly limited.
If you want to be completely certain, enforce a bit of downtime prior to running the REPACK - once the server is quiesced, you can kick it off, and then allow traffic again. Still a win over needing downtime for the entire duration of the operation.
View all comments
485
u/senatorium 8d ago
Neat.