Hacker News
Postgres 19 Repack: Faster, Built-In Table Bloat Cleanup
jzelinskie
|next
[-]
We (the SpiceDB developers) took a similar approach to solve a different problem a few years ago: implementing strict serializability in Postgres[0]. By hooking into the transactions layer themselves (pg_xact), we could layer on our own MVCC reusing the real Postgres transactions to compute visibility and total ordering. When you can just tail the Postgres internals, you don't even need to implement a Postgres extension, which can keep it portable across locked-down, managed Postgres offerings.
Do folks know of other clever implementations of behavior by "spying" on the Postgres internals?
aurareturn
|next
|previous
[-]
I thought it would be a simple process but it ended up taking many hours and a few retries. Holy hell it was a miserable experience and it ruined my New Years Eve.
I’m so happy this is now built in.
craigkerstiens
|root
|parent
|next
[-]
pg_repack, pg_squeeze, pg_reorg, all felt like it was "use as directed" and if you misuse them we're sorry if we corrupt data - that's a little extreme but they were still very advanced tools.
Having this in core and learning from all the previous Postgres paths is the way of Postgres. I'm with you couldn't be more excited to have this in core, to me it was always the flagship feature and I'm just glad it stayed in 19 vs. a revert compared to so many other flagship features.
lefra
|root
|parent
|next
|previous
[-]
The man page is quite long, use "screen -R <appropriate name" to create the session or reconnect to it, and (IIRC) CTRL-A D to exit screen without closing the session.
inkysigma
|next
|previous
[-]
nopurpose
|next
|previous
[-]
foxhill
|root
|parent
|next
[-]
what i wish postgres would do is to replan when it wildly mis-estimates row counts in deeply nested queries. just because you decided on a linear scan join when you thought that sub-query had 4 rows, doesn’t mean you need to commit to it when that sub-query turns out to actually have 4 million rows.
if you need query plan hints, it’s most likely because some aspect of postgres’ statistics about your tables is very out of line. and, given the very nature of stats collection, i.e., it being a lossy process, there are many distributions of data that it simply cannot detect & accurately account for.
hans_castorp
|root
|parent
|next
|previous
[-]
You can send the SET and the actual SQL command as a single String (delimited by ; obviously), so there is no additional round trip required.
Additionally: there is the possibility to save such a plan advice to be applied without issuing a "SET pg_plan_advice.advice" before running the statement. So this can also be applied to queries that can't be changed in the source code. This is provided by the extension pg_stash_advice
nopurpose
|root
|parent
[-]
This works for simple protocol only, with drawbacks like no parameter binding or re-planning of every query even if repeated.
hans_castorp
|root
|parent
|next
[-]
But I think the approach to decouple the actual "hint" from the query still makes more sense, than requiring a change to the original query to include it into the comments. I don't know if something like pg_stash_advice would be possible without that approach.
nopurpose
|root
|parent
[-]
They solve different problems:
- SET syntax, or query comment like in third-party pg_hint_plan extension, are for app developers to embed desired hint into the code
- pg_stash_advice, or 'hint_plan.hints' table from pg_hint_plan, is a tool to get out of a pickle when query suddenly starts to misbehave and rebuilding and redeploying app with a new hint is not an option or will take too much time.
ndriscoll
|root
|parent
|previous
[-]
hylaride
|next
|previous
[-]
Index bloat has been another story, though. Pruning b-trees is expensive and I've mostly just been scheduling reindexes (which have been able to be done concurrently for awhile) instead.
USING INDEX is interesting, though...
dangoodmanUT
|next
|previous
[-]
this feels like a foot gun. While other storage formats (eg LSMs) have lots of write amplification, it's done iteratively so you don't have massive storage and IO spikes when performing maintenance.
While this is _definitely_ better, I think the long-term solution is to replace the storage engine with something more modern.
dap
|next
|previous
[-]
QuentinM
|next
|previous
[-]
Sadly it doesn’t support partitions yet, which is typical when reaching sufficient scale that bloat management really matters. People often mention disk space when talking about dead tuples, but the real killer is what’s hidden under - bloat in the ctid & btree leaf linked lists make every lookup feel like table scans…!
Thankfully HOT (Heap-only Tuples) has saved us since. Virtually no dead tulles generated, and they get otherwise collected during regular ops like SELECT, amortizing cost over time, and preventing dangerous build up.