Incredibly well written. You clearly put a lot of thought and effort into this. Thank you.
Also FOR UPDATE SKIP LOCKED is interesting.
Also FOR UPDATE SKIP LOCKED is interesting.
One thing worth looking into if you do this in production is adding a way to add partitions such that each partition is single threaded. It’s the only way to guarantee ordering if your jobs are doing anything non-deterministic.
We increased partition counts on sale days and it works well for us.
Couple of gotchas we had were.
1) Using hashtext from postgres is sketchy.
2) Increasing partiton count is an orchestra which requires stopping the partition.
Claude says you can use a CTE to select and the run your update with the locked rows, but I have only ever used transactions.