Обсуждение: PG replicas and transactions atomicity

Поиск
Список
Период
Сортировка

PG replicas and transactions atomicity

От
Louis Laborde
Дата:
Are PG replicas updated atomically following the same transactions boundaries as the source DB ?
For example, if 2 rows from a named table are updated atomically (with a transaction) in the source DB, is there a guarantee that both
changes will be done atomically in a replica, or is there a time window where only one changed row could be visible in the replica ? 

Re: PG replicas and transactions atomicity

От
Christophe Pettus
Дата:

> On Jan 5, 2023, at 12:07, Louis Laborde <louis.laborde@gmail.com> wrote:
>
> Are PG replicas updated atomically following the same transactions boundaries as the source DB ?

Yes.  The same transactional guarantees apply to the replica as do to the original transactions on the primary.


Re: PG replicas and transactions atomicity

От
Ron
Дата:
On 1/5/23 14:09, Christophe Pettus wrote:
>> On Jan 5, 2023, at 12:07, Louis Laborde <louis.laborde@gmail.com> wrote:
>>
>> Are PG replicas updated atomically following the same transactions boundaries as the source DB ?
> Yes.  The same transactional guarantees apply to the replica as do to the original transactions on the primary.

Even in asynchronous replication?

-- 
Born in Arizona, moved to Babylonia.



Re: PG replicas and transactions atomicity

От
Christophe Pettus
Дата:

> On Jan 5, 2023, at 16:03, Ron <ronljohnsonjr@gmail.com> wrote:
>
> Even in asynchronous replication?

Yes.  Asynchronous replication controls when the client doing the transaction is told that the transaction is complete;
itdoesn't allow for dirty reads on either the primary or secondary. 


Re: PG replicas and transactions atomicity

От
Christophe Pettus
Дата:

> On Jan 5, 2023, at 19:38, Bhautik Chudasama <bhautikrchudasama@gmail.com> wrote:
>
> Does it mean when we commit transaction, client will wait until all replicas successfully committed the transaction.

It depends.  If all the settings are the defaults, no, the client won't wait for the replicas to acknowledge the commit
ofthe transaction.  This is asynchronous replication. 

Synchronous replication can be set up, though, in which case the client will wait until some or all of the replicas
havereported back that they've committed, depending on how it is configured.  The documentation explains the detailsl: 

    https://www.postgresql.org/docs/current/warm-standby.html#SYNCHRONOUS-REPLICATION