Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are the changes of a write transaction in ClientA immediately visible to a ClientB read, started after COMMIT?

Tags:

postgresql

We are observing some behaviours/errors in some of our workflows, related to the consistency and visiblity of a Postgres write transaction, followed by a read. One of our developers offered an explanation, but I could not find any search results documenting the proposed reasoning.

Given a single Postgres 10.3 host, the following operations take place:

  1. ClientA performs a successful write transaction
  2. After the COMMIT, an external notification is emitted
  3. ClientB reacts to external notification and performs a read, only to find that the UPDATE transaction changes are not visible

The explanation that was proposed is that two postgres client connections on different threads don't have a guaranteed view snapshot and may not immediately observe the write transaction update after the commit. But from what I have read, I would expect that after the COMMIT has succeeded, a read operation then starting in response should see the effects of that write.

My specific question is: Given two database client connections on different threads, is it possible for a race condition with one client viewing the effects of a write transaction AFTER the other client has committed? (no overlapping transactions).

Every bit of documentation I have found thus far only refers to concerns about overlapping/concurrent transaction and the MVCC/transaction isolation topics. Nothing about a synchronised serial operation between two different client connections.

Edit: Some extra details about the configuration. ClientA and ClientB would be different threads accessing postgres through a connection pool. Clients may both be in the same connection pool on the same application server, or it may be ClientA/ApplicationA and ClientB/ApplicationB. When ClientB reacts, it will access the existing Application server connection pool to make a new read.

like image 681
jdi Avatar asked Oct 16 '25 03:10

jdi


1 Answers

No, that cannot happen, unless the reading transaction started earlier and is running at the REPEATABLE READ or SERIALIZABLE isolation level.

There is also the possibility that the reading transaction does not connect to the same server as the writing transaction, but to a streaming replication standby server with hot_standby enabled. Then this can easily happen, even with synchronous replication (unless you set synchronous_commit = remote_apply).

like image 56
Laurenz Albe Avatar answered Oct 18 '25 01:10

Laurenz Albe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!