pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Julien Rouhaud <rjuju123@gmail.com>
To: qihua wu <staywithpin@gmail.com>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: invisible commit question for sync replication
Date: Wed, 1 Feb 2023 15:11:28 +0800
Message-ID: <20230201071128.zhhff44qlbahsc6h@jrouhaud> (raw)
In-Reply-To: <CAPoYtoLLjg1rPLNsPoF5E4dAPgGaMnBEpxP-yW8xjgGkm1q16w@mail.gmail.com>
References: <CAPoYtoLLjg1rPLNsPoF5E4dAPgGaMnBEpxP-yW8xjgGkm1q16w@mail.gmail.com>

Hi,

On Wed, Feb 01, 2023 at 02:52:49PM +0800, qihua wu wrote:
> When run a cluster with sync replication, if DML is done on primary, but
> primary is isolated from all slave, then the DML will hang, if cancel it
> DML, it will say:
> WARNING:  canceling wait for synchronous replication due to user request
> DETAIL:  The transaction has already committed locally, but might not have
> been replicated to the standby
>
> So the workflow is
> 1: commit to local.
> 2: waiting for ACK from remote sync.
>
> When cancel the DML at step 2. the data are arealy on local, that's why
> it's warning.
>
> But when runs an insert which is waiting for remote ACK, and then query
> from another session, I didn't find that row. Why this happen? If the
> insert is already one locally, whey another session can't read it?

It works as expected for me, are you sure both sessions are actually connected
to the same server and/or querying the same table?

[1456]rjuju@127.0.0.1:14295) rjuju=# select * from tt;
 id | val
----+-----
(0 rows)

[1456]rjuju@127.0.0.1:14295) rjuju=# insert into tt select 1;
^CCancel request sent
WARNING:  01000: canceling wait for synchronous replication due to user request
DETAIL:  The transaction has already committed locally, but might not have been replicated to the standby.
LOCATION:  SyncRepWaitForLSN, syncrep.c:287
INSERT 0 1

[1456]rjuju@127.0.0.1:14295) rjuju=# select pg_backend_pid(), * from tt;
 pg_backend_pid | id |  val
----------------+----+--------
           1456 |  1 | <NULL>
(1 row)


and another session:

[3327]rjuju@127.0.0.1:14295) rjuju=# select pg_backend_pid(), * from tt;
 pg_backend_pid | id |  val
----------------+----+--------
           3327 |  1 | <NULL>
(1 row)





view thread (6+ messages)  latest in thread

Message-ID: <20230201071128.zhhff44qlbahsc6h@jrouhaud>
Permalink:  ../20230201071128.zhhff44qlbahsc6h@jrouhaud/
Also on:    postgresql.org/message-id/20230201071128.zhhff44qlbahsc6h@jrouhaud

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: rjuju123@gmail.com, staywithpin@gmail.com
  Subject: Re: invisible commit question for sync replication
  In-Reply-To: <20230201071128.zhhff44qlbahsc6h@jrouhaud>
  References: <CAPoYtoLLjg1rPLNsPoF5E4dAPgGaMnBEpxP-yW8xjgGkm1q16w@mail.gmail.com> <20230201071128.zhhff44qlbahsc6h@jrouhaud>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox