From: Laurenz Albe <laurenz.albe@cybertec.at>
To: qihua wu <staywithpin@gmail.com>
To: pgsql-general@lists.postgresql.org
Subject: Re: Does statement_timeout apply to commit?
Date: Mon, 30 Jan 2023 14:19:50 +0100
Message-ID: <84018b9c65559d57c854538f2a131edd4ab3d40d.camel@cybertec.at> (raw)
In-Reply-To: <CAPoYtoJZkq9ir=MRUiR-5d4NZr1RQtr8TDTVaQ-GQimGAyVxdA@mail.gmail.com>
References: <CAPoYtoJZkq9ir=MRUiR-5d4NZr1RQtr8TDTVaQ-GQimGAyVxdA@mail.gmail.com>
On Mon, 2023-01-30 at 17:10 +0800, qihua wu wrote:
> I have a patroni cluster running in sync mode and at least 2 nodes should be
> synced for commit. Now I brought down one node, so only one slave is in sync,
> and then write a java program to write the data to primary in autocommit = false
> mode, I set statement_timeout to 10, hopping the jave will throw exception
> after 10 seconds after I send a commit command to postgresq, but after 10 seconds,
> it didn't throw any exception, so looks like statement_timeout doesn't apply to
> commit. Is that theory right?.
I assume you are talking about synchronous replication.
static void
CommitTransaction(void)
{
[...]
/* Prevent cancel/die interrupt while cleaning up */
HOLD_INTERRUPTS();
[...]
if (!is_parallel_worker)
{
/*
* We need to mark our XIDs as committed in pg_xact. This is where we
* durably commit.
*/
latestXid = RecordTransactionCommit();
}
[...]
RESUME_INTERRUPTS();
}
static TransactionId
RecordTransactionCommit(void)
{
[...]
/*
* Wait for synchronous replication, if required. Similar to the decision
* above about using committing asynchronously we only want to wait if
* this backend assigned an xid and wrote WAL. No need to wait if an xid
* was assigned due to temporary/unlogged tables or due to HOT pruning.
*
* Note that at this stage we have marked clog, but still show as running
* in the procarray and continue to hold locks.
*/
if (wrote_xlog && markXidCommitted)
SyncRepWaitForLSN(XactLastRecEnd, true);
[...]
}
So yes, it looks like you are right.
Yours,
Laurenz Albe
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: laurenz.albe@cybertec.at, staywithpin@gmail.com
Subject: Re: Does statement_timeout apply to commit?
In-Reply-To: <84018b9c65559d57c854538f2a131edd4ab3d40d.camel@cybertec.at>
References: <CAPoYtoJZkq9ir=MRUiR-5d4NZr1RQtr8TDTVaQ-GQimGAyVxdA@mail.gmail.com> <84018b9c65559d57c854538f2a131edd4ab3d40d.camel@cybertec.at>
* 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