Is there a way to tell whether the database is in the middle of a transaction?

My only comment is that this:

Is not 100% true all the time*, and two transactions can exist simultaneously even in the same table at the same time, as long as any changes that are made are completely time independently serializable.

(It snapshots the rows read/written to, and if it can, will make any and all updates that can happen if ALL of those changes do not conflict with each other by changing anything that they depended on to use in the transaction)

What you are describing is more like a table level lock, and PostGreSQL does not do this, but you can create any sort of blocking you want I guess. It’s just going to let less things proceed than the standard ‘serializable’ isolation level would. (The highest available in PGSQL) You might also have to deal with memory level race conditions with a global lock variable and the GIL.

*When we are using anvil the way we do it is quite often true that transactions fail, due to lack of a pure access to something like an UPDATE statement.

2 Likes