If you conclude your transactions inside a transaction, all of them will be executed atomically. You may need to increase the level of transaction isolation based on your needs.
For example, if you do not want anyone to read or write any particular table while executing a bunch of statements, this statement at the top will do this:
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
I do not recommend escalating to this level if it is absolutely necessary because it basically violates the benefits of concurrency.
Instead, consider using something lower or remaking your logic to remove the need for a critical section.
source
share