4 ms·
The "little trick" in the Citus approach is very inventive. SHARE ROW EXCLUSIVE mode protects a table against concurrent data changes, and is self-exclusive so
by eugene-khyst 3y ago
The "little trick" in the Citus approach is very inventive.
SHARE ROW EXCLUSIVE mode protects a table against concurrent data changes, and is self-exclusive so that only one session can hold it at a time.
Thus, when such lock is obtained, we can be sure that there are no more pending transactions with uncommited changes. It's a protection from loosing data of the pending transactions.
Throwing the exception immediately releases the lock. Thus, the exclusive table lock is held for milliseconds.
I like the general idea, but I don't want to add plpgsql functions/procedures.
I'll see if this can be elegantly implemented in Java+SQL (without plpgsql) and perhaps add it as alternative approach to my project. Such approach may be even more effective because it focuses on a single table and not on all transactions like the one described in my project, thus, locks on irrelevant tables have no effect on event handlers.
Thanks for sharing.
- nextaccountic 3y agoWhy no plpgsql? Is it because the language is bad? If so, what about something like pl/rust https://plrust.io/ https://plrust.io/ ? (Or other language)
- eugene-khyst 3y agoplpgsql is good language. But in my experience Java and .NET developers tend to choose solutions that do not use plpgsql, PL/SQL, T-SQL. And these developers is the main audience for the project.