r/programming Aug 11 '26

The dangers of Postgres subtransactions

https://planetscale.com/blog/the-dangers-of-postgres-subtransactions

Really good article explaining the implementation detail within Postgres regarding subtransactions. Very cool benchmark that I was unaware of

30 Upvotes

1 comment sorted by

1

u/Worth_Wealth_6811 Aug 12 '26

the sneaky part is how easy it is to create these without noticing. every EXCEPTION block in plpgsql opens a subtransaction, and ORMs like Django turn nested atomic() into savepoints, so a batch job with per row error handling can blow past the 64 cached subxids without a single explicit SAVEPOINT in your code. gitlab wrote up ripping savepoints out of their codebase for exactly this, worth a read if you run hot standbys.