News for hackers. Stuff that matters.
Re:Show HN: Postgres Query Lock Explainer by fovc on Wednesday May 17, 2023 @07:54PM (#35982701)
It would be nice if you added a how it works section to the readme. Knowing that it does `begin; ${query}; rollback;` under the hood is important. The example with truncate in fact made me think the opposite was true, since truncate violates MVCC and cannot be rolled back.

I’m often worrying about locks in migrations that could be long running, so executing the query to figure out the locks defeats the purpose. Or at least I need to know to use a test DB.

Re:Show HN: Postgres Query Lock Explainer by admtal on Wednesday May 17, 2023 @10:55PM (#35983678)
Re:Show HN: Postgres Query Lock Explainer by LunaSea on Thursday May 18, 2023 @01:15AM (#35984344)
As far as I know, truncate can be rolled back but it is also visible, even before the transaction is commited, to other transactions that started before:

https://www.postgresql.org/docs/current/sql-truncate.html

Re:Show HN: Postgres Query Lock Explainer by fovc on Friday May 19, 2023 @12:51PM (#36004088)
Ah thank you! Quoting the link for others;

> TRUNCATE is not MVCC-safe. After truncation, the table will appear empty to concurrent transactions, if they are using a snapshot taken before the truncation occurred. See Section 13.6 for more details.

> TRUNCATE is transaction-safe with respect to the data in the tables: the truncation will be safely rolled back if the surrounding transaction does not commit.

Re:Show HN: Postgres Query Lock Explainer by mad0 on Thursday May 18, 2023 @04:37AM (#35985390)
Maybe emitting a warning would be good. I'm no DBA so remembering all operations that cannot be rolledback might be tough. (Though maybe I should know all of them if they aren't rollbackable :P )