Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rUhWZ-00CYWj-Co for pgsql-hackers@arkaria.postgresql.org; Tue, 30 Jan 2024 06:23:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rUhWY-002nke-Gf for pgsql-hackers@arkaria.postgresql.org; Tue, 30 Jan 2024 06:23:10 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rUhWX-002nhf-VM for pgsql-hackers@lists.postgresql.org; Tue, 30 Jan 2024 06:23:10 +0000 Received: from forwardcorp1c.mail.yandex.net ([178.154.239.200]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rUhWU-004TGX-Kd for pgsql-hackers@postgresql.org; Tue, 30 Jan 2024 06:23:09 +0000 Received: from mail-nwsmtp-smtp-corp-main-26.myt.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-26.myt.yp-c.yandex.net [IPv6:2a02:6b8:c12:36ad:0:640:5aad:0]) by forwardcorp1c.mail.yandex.net (Yandex) with ESMTPS id B1EE6613C1; Tue, 30 Jan 2024 09:23:04 +0300 (MSK) Received: from smtpclient.apple (unknown [2a02:6b8:82:604:89db:a33b:f438:835]) by mail-nwsmtp-smtp-corp-main-26.myt.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id 1NS7g22EWeA0-J9J7Unuh; Tue, 30 Jan 2024 09:23:03 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1706595783; bh=hAw7fyqWLw79ASKJSl3y2q+0r4eC3ScuL78sX83KUeU=; h=References:To:Cc:In-Reply-To:From:Date:Subject:Message-Id; b=QLnZn0YjPOLPE6dD5JEyrv9EtDVqVQ3tjJ1Ms+zOzyKkYm/mCf2psCUnTKoP3vqXv Wti/kfTDupheqNze2vlhNBCTIhQWFv48+EtCWLDH4R5VVDrnDmF5WOhRXHQZWkFVb1 bNOXE69hF/PTf+REMMb49vLNcMouseDDWmmUaRQQ= Authentication-Results: mail-nwsmtp-smtp-corp-main-26.myt.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: "Andrey M. Borodin" Message-Id: Content-Type: multipart/mixed; boundary="Apple-Mail=_198FA4EF-F6B4-41A9-B2D9-373A21FA3253" Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3731.700.6\)) Subject: Re: Transaction timeout Date: Tue, 30 Jan 2024 11:22:51 +0500 In-Reply-To: Cc: Peter Smith , Junwang Zhao , =?utf-8?B?6YKx5a6H6Iiq?= , Fujii Masao , Andrey Borodin , Andres Freund , Michael Paquier , Nikolay Samokhvalov , pgsql-hackers , "pgsql-hackers@lists.postgresql.org" To: Japin Li References: <79905780-F316-4DD3-812E-654D460E381C@yandex-team.ru> <68965408-F5A3-459F-A84E-5F4F2C237A5B@yandex-team.ru> <03431609-49D0-445E-97F0-ACF6C526F3EB@yandex-team.ru> <59B505DD-1931-49A3-9716-2DD7A002CCC6@yandex-team.ru> <4C30F833-C0F2-4664-B0FF-192FD8AB2E2E@yandex-team.ru> X-Mailer: Apple Mail (2.3731.700.6) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --Apple-Mail=_198FA4EF-F6B4-41A9-B2D9-373A21FA3253 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On 26 Jan 2024, at 19:58, Japin Li wrote: >=20 > Thanks for updating the patch. Here are some comments for v24. >=20 > + > + Terminate any session that spans longer than the specified = amount of > + time in transaction. The limit applies both to explicit = transactions > + (started with BEGIN) and to implicitly = started > + transaction corresponding to single statement. But this limit = is not > + applied to prepared transactions. > + If this value is specified without units, it is taken as = milliseconds. > + A value of zero (the default) disables the timeout. > + > The sentence "But this limit is not applied to prepared transactions" = is redundant, > since we have a paragraph to describe this later. Fixed. >=20 > + > + > + If transaction_timeout is shorter than > + idle_in_transaction_session_timeout or = statement_timeout > + transaction_timeout will invalidate longer = timeout. > + > + >=20 > Since we are already try to disable the timeouts, should we try to = disable > them even if they are equal. Well, we disable timeouts on equality. Fixed docs. >=20 > + > + > + Prepared transactions are not subject for this timeout. > + >=20 > Maybe wrap this with is a good idea. Done. >=20 >> I=E2=80=99ve inspected CI fails and they were caused by two different = problems: >> 1. It=E2=80=99s unsafe for isaoltion tester to await = transaction_timeout within a query. Usually it gets >> FATAL: terminating connection due to transaction timeout >> But if VM is a bit slow it can get occasional >> PQconsumeInput failed: server closed the connection unexpectedly >> So, currently all tests use =E2=80=9Cpassive waiting=E2=80=9D, in a = session that will not timeout. >>=20 >> 2. In some cases pg_sleep(0.1) were sleeping up to 200 ms. That was = making s7 and s8 fail, because they rely on this margin. >=20 > I'm curious why this happened. I think pg_sleep() cannot provide guarantees on when next query will be = executed. In our case we need that isolation tester see that sleep is = over and continue in other session... >> I=E2=80=99ve separated these tests into different test timeouts-long = and increased margin to 300ms. Now tests run horrible 2431 ms. Moreover = I=E2=80=99m afraid that on buildfarm we can have much randomly-slower = machines so this test might be excluded. >> This test checks COMMIT AND CHAIN and flow of small queries (Nik=E2=80=99= s case). >>=20 >> Also I=E2=80=99ve verified that every = "enable_timeout_after(TRANSACTION_TIMEOUT)=E2=80=9D and = =E2=80=9Cdisable_timeout(TRANSACTION_TIMEOUT)=E2=80=9D is necessary and = found that case of aborting "idle in transaction (aborted)=E2=80=9D is = not covered by tests. I=E2=80=99m not sure we need a test for this. >=20 > I see there is a test about idle_in_transaction_timeout and = transaction_timeout. >=20 > Both of them only check the session, but don't check the reason, so we = cannot > distinguish the reason they are terminated. Right? Yes. >=20 >> Japin, Junwang, what do you think? >=20 > However, checking the reason on the timeout session may cause = regression test > failed (as you point in 1), I don't strongly insist on it. Indeed, if we check a reason of FATAL timeouts - we get flaky tests. Best regards, Andrey Borodin. --Apple-Mail=_198FA4EF-F6B4-41A9-B2D9-373A21FA3253 Content-Disposition: attachment; filename=v25-0001-Introduce-transaction_timeout.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="v25-0001-Introduce-transaction_timeout.patch" Content-Transfer-Encoding: quoted-printable =46rom=205154fbc3377aa9a4025f04c90da61861ac558761=20Mon=20Sep=2017=20= 00:00:00=202001=0AFrom:=20"Andrey=20M.=20Borodin"=20=0A= Date:=20Sun,=203=20Dec=202023=2023:18:00=20+0500=0ASubject:=20[PATCH=20= v25]=20Introduce=20transaction_timeout=0A=0AThis=20commit=20adds=20= timeout=20that=20is=20expected=20to=20be=20used=20as=20a=20prevention=0A= of=20long-running=20queries.=20Any=20session=20within=20transaction=20= will=20be=0Aterminated=20after=20spanning=20longer=20than=20this=20= timeout.=0A=0AHowever,=20this=20timeout=20is=20not=20applied=20to=20= prepared=20transactions.=0AOnly=20transactions=20with=20user=20= connections=20are=20affected.=0A=0AAuthor:=20Andrey=20Borodin=20= =0AAuthor:=20Japin=20Li=20=0A= Author:=20Junwang=20Zhao=20=0AReviewed-by:=20Nikolay=20= Samokhvalov=20=0AReviewed-by:=20Andres=20Freund=20= =0AReviewed-by:=20Fujii=20Masao=20= =0AReviewed-by:=20bt23nguyent=20= =0AReviewed-by:=20Yuhang=20Qiu=20= =0A=0ADiscussion:=20= https://postgr.es/m/CAAhFRxiQsRs2Eq5kCo9nXE3HTugsAAJdSQSmxncivebAxdmBjQ%40= mail.gmail.com=0A---=0A=20doc/src/sgml/config.sgml=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20|=2036=20+++++++++=0A=20= src/backend/access/transam/xact.c=20=20=20=20=20=20=20=20=20=20=20=20=20= |=20=204=20+=0A=20src/backend/postmaster/autovacuum.c=20=20=20=20=20=20=20= =20=20=20=20|=20=202=20+=0A=20src/backend/storage/lmgr/proc.c=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20|=20=201=20+=0A=20= src/backend/tcop/postgres.c=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20|=2033=20+++++++-=0A=20src/backend/utils/errcodes.txt=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20|=20=201=20+=0A=20= src/backend/utils/init/globals.c=20=20=20=20=20=20=20=20=20=20=20=20=20=20= |=20=201=20+=0A=20src/backend/utils/init/postinit.c=20=20=20=20=20=20=20=20= =20=20=20=20=20|=2010=20+++=0A=20src/backend/utils/misc/guc_tables.c=20=20= =20=20=20=20=20=20=20=20=20|=2011=20+++=0A=20= src/backend/utils/misc/postgresql.conf.sample=20|=20=201=20+=0A=20= src/bin/pg_dump/pg_backup_archiver.c=20=20=20=20=20=20=20=20=20=20|=20=20= 2=20+=0A=20src/bin/pg_dump/pg_dump.c=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20|=20=202=20+=0A=20= src/bin/pg_rewind/libpq_source.c=20=20=20=20=20=20=20=20=20=20=20=20=20=20= |=20=201=20+=0A=20src/include/miscadmin.h=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20|=20=201=20+=0A=20= src/include/storage/proc.h=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20|=20=201=20+=0A=20src/include/utils/timeout.h=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20|=20=201=20+=0A=20= src/test/isolation/Makefile=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20|=20=203=20+=0A=20src/test/isolation/expected/timeouts-long.out=20= |=2069=20++++++++++++++++=0A=20src/test/isolation/expected/timeouts.out=20= =20=20=20=20=20|=2079=20++++++++++++++++++-=0A=20= src/test/isolation/isolation_schedule=20=20=20=20=20=20=20=20=20|=20=201=20= +=0A=20src/test/isolation/specs/timeouts-long.spec=20=20=20|=2035=20= ++++++++=0A=20src/test/isolation/specs/timeouts.spec=20=20=20=20=20=20=20= =20|=2040=20+++++++++-=0A=2022=20files=20changed,=20330=20insertions(+),=20= 5=20deletions(-)=0A=20create=20mode=20100644=20= src/test/isolation/expected/timeouts-long.out=0A=20create=20mode=20= 100644=20src/test/isolation/specs/timeouts-long.spec=0A=0Adiff=20--git=20= a/doc/src/sgml/config.sgml=20b/doc/src/sgml/config.sgml=0Aindex=20= 61038472c5a..ddbfa9a631b=20100644=0A---=20a/doc/src/sgml/config.sgml=0A= +++=20b/doc/src/sgml/config.sgml=0A@@=20-9135,6=20+9135,42=20@@=20COPY=20= postgres_log=20FROM=20'/full/path/to/logfile.csv'=20WITH=20csv;=0A=20=20=20= =20=20=20=20=0A=20=20=20=20=20=20=0A=20=0A+=20=20= =20=20=20=0A+=20=20=20=20=20=20= transaction_timeout=20(integer)=0A= +=20=20=20=20=20=20=0A+=20=20=20=20=20=20=20= transaction_timeout=20configuration=20= parameter=0A+=20=20=20=20=20=20=0A+=20=20=20=20=20=20= =0A+=20=20=20=20=20=20=0A+=20=20=20=20=20=20=20=0A= +=20=20=20=20=20=20=20=20Terminate=20any=20session=20that=20spans=20= longer=20than=20the=20specified=20amount=20of=0A+=20=20=20=20=20=20=20=20= time=20in=20transaction.=20The=20limit=20applies=20both=20to=20explicit=20= transactions=0A+=20=20=20=20=20=20=20=20(started=20with=20= BEGIN)=20and=20to=20implicitly=20started=0A+=20=20=20=20= =20=20=20=20transaction=20corresponding=20to=20single=20statement.=0A+=20= =20=20=20=20=20=20=20If=20this=20value=20is=20specified=20without=20= units,=20it=20is=20taken=20as=20milliseconds.=0A+=20=20=20=20=20=20=20=20= A=20value=20of=20zero=20(the=20default)=20disables=20the=20timeout.=0A+=20= =20=20=20=20=20=20=0A+=0A+=20=20=20=20=20=20=20=0A+=20=20=20= =20=20=20=20=20If=20transaction_timeout=20is=20= shorter=20or=20eqaul=20to=0A+=20=20=20=20=20=20=20=20= idle_in_transaction_session_timeout=20or=20= statement_timeout=0A+=20=20=20=20=20=20=20=20= transaction_timeout=20will=20invalidate=20longer=20= timeout.=0A+=20=20=20=20=20=20=20=0A+=0A+=20=20=20=20=20=20=20= =0A+=20=20=20=20=20=20=20=20Setting=20= transaction_timeout=20in=0A+=20=20=20=20=20=20=20=20= postgresql.conf=20is=20not=20recommended=20because=20= it=20would=0A+=20=20=20=20=20=20=20=20affect=20all=20sessions.=0A+=20=20=20= =20=20=20=20=0A+=0A+=20=20=20=20=20=20=20=0A+=20=20=20=20=20= =20=20=20=0A+=20=20=20=20=20=20=20=20=20Prepared=20transactions=20= are=20not=20subject=20for=20this=20timeout.=0A+=20=20=20=20=20=20=20=20= =0A+=20=20=20=20=20=20=20=0A+=20=20=20=20=20=20=0A= +=20=20=20=20=20=0A+=0A=20=20=20=20=20=20=0A=20=20=20=20=20=20= =20lock_timeout=20(integer)=0A=20=20= =20=20=20=20=20=0Adiff=20--git=20= a/src/backend/access/transam/xact.c=20= b/src/backend/access/transam/xact.c=0Aindex=20464858117e0..a124ba59330=20= 100644=0A---=20a/src/backend/access/transam/xact.c=0A+++=20= b/src/backend/access/transam/xact.c=0A@@=20-2139,6=20+2139,10=20@@=20= StartTransaction(void)=0A=20=09=20*/=0A=20=09s->state=20=3D=20= TRANS_INPROGRESS;=0A=20=0A+=09/*=20Schedule=20transaction=20timeout=20*/=0A= +=09if=20(TransactionTimeout=20>=200)=0A+=09=09= enable_timeout_after(TRANSACTION_TIMEOUT,=20TransactionTimeout);=0A+=0A=20= =09ShowTransactionState("StartTransaction");=0A=20}=0A=20=0Adiff=20--git=20= a/src/backend/postmaster/autovacuum.c=20= b/src/backend/postmaster/autovacuum.c=0Aindex=202c3099f76f1..c12fc6594ce=20= 100644=0A---=20a/src/backend/postmaster/autovacuum.c=0A+++=20= b/src/backend/postmaster/autovacuum.c=0A@@=20-586,6=20+586,7=20@@=20= AutoVacLauncherMain(int=20argc,=20char=20*argv[])=0A=20=09=20*=20regular=20= maintenance=20from=20being=20executed.=0A=20=09=20*/=0A=20=09= SetConfigOption("statement_timeout",=20"0",=20PGC_SUSET,=20= PGC_S_OVERRIDE);=0A+=09SetConfigOption("transaction_timeout",=20"0",=20= PGC_SUSET,=20PGC_S_OVERRIDE);=0A=20=09SetConfigOption("lock_timeout",=20= "0",=20PGC_SUSET,=20PGC_S_OVERRIDE);=0A=20=09= SetConfigOption("idle_in_transaction_session_timeout",=20"0",=0A=20=09=09= =09=09=09PGC_SUSET,=20PGC_S_OVERRIDE);=0A@@=20-1591,6=20+1592,7=20@@=20= AutoVacWorkerMain(int=20argc,=20char=20*argv[])=0A=20=09=20*=20regular=20= maintenance=20from=20being=20executed.=0A=20=09=20*/=0A=20=09= SetConfigOption("statement_timeout",=20"0",=20PGC_SUSET,=20= PGC_S_OVERRIDE);=0A+=09SetConfigOption("transaction_timeout",=20"0",=20= PGC_SUSET,=20PGC_S_OVERRIDE);=0A=20=09SetConfigOption("lock_timeout",=20= "0",=20PGC_SUSET,=20PGC_S_OVERRIDE);=0A=20=09= SetConfigOption("idle_in_transaction_session_timeout",=20"0",=0A=20=09=09= =09=09=09PGC_SUSET,=20PGC_S_OVERRIDE);=0Adiff=20--git=20= a/src/backend/storage/lmgr/proc.c=20b/src/backend/storage/lmgr/proc.c=0A= index=20e5977548fe2..1afcbfc052c=20100644=0A---=20= a/src/backend/storage/lmgr/proc.c=0A+++=20= b/src/backend/storage/lmgr/proc.c=0A@@=20-59,6=20+59,7=20@@=20int=09=09=09= DeadlockTimeout=20=3D=201000;=0A=20int=09=09=09StatementTimeout=20=3D=20= 0;=0A=20int=09=09=09LockTimeout=20=3D=200;=0A=20int=09=09=09= IdleInTransactionSessionTimeout=20=3D=200;=0A+int=09=09=09= TransactionTimeout=20=3D=200;=0A=20int=09=09=09IdleSessionTimeout=20=3D=20= 0;=0A=20bool=09=09log_lock_waits=20=3D=20false;=0A=20=0Adiff=20--git=20= a/src/backend/tcop/postgres.c=20b/src/backend/tcop/postgres.c=0Aindex=20= 1a34bd3715f..af28f425ce6=20100644=0A---=20a/src/backend/tcop/postgres.c=0A= +++=20b/src/backend/tcop/postgres.c=0A@@=20-3426,6=20+3426,17=20@@=20= ProcessInterrupts(void)=0A=20=09=09=09= IdleInTransactionSessionTimeoutPending=20=3D=20false;=0A=20=09}=0A=20=0A= +=09if=20(TransactionTimeoutPending)=0A+=09{=0A+=09=09/*=20As=20above,=20= ignore=20the=20signal=20if=20the=20GUC=20has=20been=20reset=20to=20zero.=20= */=0A+=09=09if=20(TransactionTimeout=20>=200)=0A+=09=09=09ereport(FATAL,=0A= +=09=09=09=09=09(errcode(ERRCODE_TRANSACTION_TIMEOUT),=0A+=09=09=09=09=09= =20errmsg("terminating=20connection=20due=20to=20transaction=20= timeout")));=0A+=09=09else=0A+=09=09=09TransactionTimeoutPending=20=3D=20= false;=0A+=09}=0A+=0A=20=09if=20(IdleSessionTimeoutPending)=0A=20=09{=0A=20= =09=09/*=20As=20above,=20ignore=20the=20signal=20if=20the=20GUC=20has=20= been=20reset=20to=20zero.=20*/=0A@@=20-4491,12=20+4502,18=20@@=20= PostgresMain(const=20char=20*dbname,=20const=20char=20*username)=0A=20=09= =09=09=09pgstat_report_activity(STATE_IDLEINTRANSACTION_ABORTED,=20= NULL);=0A=20=0A=20=09=09=09=09/*=20Start=20the=20idle-in-transaction=20= timer=20*/=0A-=09=09=09=09if=20(IdleInTransactionSessionTimeout=20>=200)=0A= +=09=09=09=09if=20(IdleInTransactionSessionTimeout=20>=200=0A+=09=09=09=09= =09&&=20(IdleInTransactionSessionTimeout=20<=20TransactionTimeout=20||=20= TransactionTimeout=20=3D=3D=200))=0A=20=09=09=09=09{=0A=20=09=09=09=09=09= idle_in_transaction_timeout_enabled=20=3D=20true;=0A=20=09=09=09=09=09= enable_timeout_after(IDLE_IN_TRANSACTION_SESSION_TIMEOUT,=0A=20=09=09=09=09= =09=09=09=09=09=09=20IdleInTransactionSessionTimeout);=0A=20=09=09=09=09= }=0A+=0A+=09=09=09=09/*=20Schedule=20or=20reschedule=20transaction=20= timeout=20*/=0A+=09=09=09=09if=20(TransactionTimeout=20>=200=20&&=20= !get_timeout_active(TRANSACTION_TIMEOUT))=0A+=09=09=09=09=09= enable_timeout_after(TRANSACTION_TIMEOUT,=0A+=09=09=09=09=09=09=09=09=09=09= =20TransactionTimeout);=0A=20=09=09=09}=0A=20=09=09=09else=20if=20= (IsTransactionOrTransactionBlock())=0A=20=09=09=09{=0A@@=20-4504,12=20= +4521,18=20@@=20PostgresMain(const=20char=20*dbname,=20const=20char=20= *username)=0A=20=09=09=09=09= pgstat_report_activity(STATE_IDLEINTRANSACTION,=20NULL);=0A=20=0A=20=09=09= =09=09/*=20Start=20the=20idle-in-transaction=20timer=20*/=0A-=09=09=09=09= if=20(IdleInTransactionSessionTimeout=20>=200)=0A+=09=09=09=09if=20= (IdleInTransactionSessionTimeout=20>=200=0A+=09=09=09=09=09&&=20= (IdleInTransactionSessionTimeout=20<=20TransactionTimeout=20||=20= TransactionTimeout=20=3D=3D=200))=0A=20=09=09=09=09{=0A=20=09=09=09=09=09= idle_in_transaction_timeout_enabled=20=3D=20true;=0A=20=09=09=09=09=09= enable_timeout_after(IDLE_IN_TRANSACTION_SESSION_TIMEOUT,=0A=20=09=09=09=09= =09=09=09=09=09=09=20IdleInTransactionSessionTimeout);=0A=20=09=09=09=09= }=0A+=0A+=09=09=09=09/*=20Schedule=20or=20reschedule=20transaction=20= timeout=20*/=0A+=09=09=09=09if=20(TransactionTimeout=20>=200=20&&=20= !get_timeout_active(TRANSACTION_TIMEOUT))=0A+=09=09=09=09=09= enable_timeout_after(TRANSACTION_TIMEOUT,=0A+=09=09=09=09=09=09=09=09=09=09= =20TransactionTimeout);=0A=20=09=09=09}=0A=20=09=09=09else=0A=20=09=09=09= {=0A@@=20-4562,6=20+4585,9=20@@=20PostgresMain(const=20char=20*dbname,=20= const=20char=20*username)=0A=20=09=09=09=09=09= enable_timeout_after(IDLE_SESSION_TIMEOUT,=0A=20=09=09=09=09=09=09=09=09=09= =09=20IdleSessionTimeout);=0A=20=09=09=09=09}=0A+=0A+=09=09=09=09if=20= (get_timeout_active(TRANSACTION_TIMEOUT))=0A+=09=09=09=09=09= disable_timeout(TRANSACTION_TIMEOUT,=20false);=0A=20=09=09=09}=0A=20=0A=20= =09=09=09/*=20Report=20any=20recently-changed=20GUC=20options=20*/=0A@@=20= -5120,7=20+5146,8=20@@=20enable_statement_timeout(void)=0A=20=09/*=20= must=20be=20within=20an=20xact=20*/=0A=20=09Assert(xact_started);=0A=20=0A= -=09if=20(StatementTimeout=20>=200)=0A+=09if=20(StatementTimeout=20>=200=0A= +=09=09&&=20(StatementTimeout=20<=20TransactionTimeout=20||=20= TransactionTimeout=20=3D=3D=200))=0A=20=09{=0A=20=09=09if=20= (!get_timeout_active(STATEMENT_TIMEOUT))=0A=20=09=09=09= enable_timeout_after(STATEMENT_TIMEOUT,=20StatementTimeout);=0Adiff=20= --git=20a/src/backend/utils/errcodes.txt=20= b/src/backend/utils/errcodes.txt=0Aindex=2029f367a5e1c..3250d539e1c=20= 100644=0A---=20a/src/backend/utils/errcodes.txt=0A+++=20= b/src/backend/utils/errcodes.txt=0A@@=20-252,6=20+252,7=20@@=20Section:=20= Class=2025=20-=20Invalid=20Transaction=20State=0A=2025P01=20=20=20=20E=20= =20=20=20ERRCODE_NO_ACTIVE_SQL_TRANSACTION=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= no_active_sql_transaction=0A=2025P02=20=20=20=20E=20=20=20=20= ERRCODE_IN_FAILED_SQL_TRANSACTION=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= in_failed_sql_transaction=0A=2025P03=20=20=20=20E=20=20=20=20= ERRCODE_IDLE_IN_TRANSACTION_SESSION_TIMEOUT=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20idle_in_transaction_session_timeout=0A= +25P04=20=20=20=20E=20=20=20=20ERRCODE_TRANSACTION_TIMEOUT=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20transaction_timeout=0A=20=0A=20Section:=20Class=2026=20= -=20Invalid=20SQL=20Statement=20Name=0A=20=0Adiff=20--git=20= a/src/backend/utils/init/globals.c=20b/src/backend/utils/init/globals.c=0A= index=2088b03e8fa3c..f024b1a8497=20100644=0A---=20= a/src/backend/utils/init/globals.c=0A+++=20= b/src/backend/utils/init/globals.c=0A@@=20-33,6=20+33,7=20@@=20volatile=20= sig_atomic_t=20ProcDiePending=20=3D=20false;=0A=20volatile=20= sig_atomic_t=20CheckClientConnectionPending=20=3D=20false;=0A=20volatile=20= sig_atomic_t=20ClientConnectionLost=20=3D=20false;=0A=20volatile=20= sig_atomic_t=20IdleInTransactionSessionTimeoutPending=20=3D=20false;=0A= +volatile=20sig_atomic_t=20TransactionTimeoutPending=20=3D=20false;=0A=20= volatile=20sig_atomic_t=20IdleSessionTimeoutPending=20=3D=20false;=0A=20= volatile=20sig_atomic_t=20ProcSignalBarrierPending=20=3D=20false;=0A=20= volatile=20sig_atomic_t=20LogMemoryContextPending=20=3D=20false;=0Adiff=20= --git=20a/src/backend/utils/init/postinit.c=20= b/src/backend/utils/init/postinit.c=0Aindex=201ad33671598..7797876d008=20= 100644=0A---=20a/src/backend/utils/init/postinit.c=0A+++=20= b/src/backend/utils/init/postinit.c=0A@@=20-75,6=20+75,7=20@@=20static=20= void=20ShutdownPostgres(int=20code,=20Datum=20arg);=0A=20static=20void=20= StatementTimeoutHandler(void);=0A=20static=20void=20= LockTimeoutHandler(void);=0A=20static=20void=20= IdleInTransactionSessionTimeoutHandler(void);=0A+static=20void=20= TransactionTimeoutHandler(void);=0A=20static=20void=20= IdleSessionTimeoutHandler(void);=0A=20static=20void=20= IdleStatsUpdateTimeoutHandler(void);=0A=20static=20void=20= ClientCheckTimeoutHandler(void);=0A@@=20-764,6=20+765,7=20@@=20= InitPostgres(const=20char=20*in_dbname,=20Oid=20dboid,=0A=20=09=09= RegisterTimeout(LOCK_TIMEOUT,=20LockTimeoutHandler);=0A=20=09=09= RegisterTimeout(IDLE_IN_TRANSACTION_SESSION_TIMEOUT,=0A=20=09=09=09=09=09= =09IdleInTransactionSessionTimeoutHandler);=0A+=09=09= RegisterTimeout(TRANSACTION_TIMEOUT,=20TransactionTimeoutHandler);=0A=20=09= =09RegisterTimeout(IDLE_SESSION_TIMEOUT,=20IdleSessionTimeoutHandler);=0A= =20=09=09RegisterTimeout(CLIENT_CONNECTION_CHECK_TIMEOUT,=20= ClientCheckTimeoutHandler);=0A=20=09=09= RegisterTimeout(IDLE_STATS_UPDATE_TIMEOUT,=0A@@=20-1395,6=20+1397,14=20= @@=20LockTimeoutHandler(void)=0A=20=09kill(MyProcPid,=20SIGINT);=0A=20}=0A= =20=0A+static=20void=0A+TransactionTimeoutHandler(void)=0A+{=0A+=09= TransactionTimeoutPending=20=3D=20true;=0A+=09InterruptPending=20=3D=20= true;=0A+=09SetLatch(MyLatch);=0A+}=0A+=0A=20static=20void=0A=20= IdleInTransactionSessionTimeoutHandler(void)=0A=20{=0Adiff=20--git=20= a/src/backend/utils/misc/guc_tables.c=20= b/src/backend/utils/misc/guc_tables.c=0Aindex=207fe58518d7d..0fb5ec648e4=20= 100644=0A---=20a/src/backend/utils/misc/guc_tables.c=0A+++=20= b/src/backend/utils/misc/guc_tables.c=0A@@=20-2577,6=20+2577,17=20@@=20= struct=20config_int=20ConfigureNamesInt[]=20=3D=0A=20=09=09NULL,=20NULL,=20= NULL=0A=20=09},=0A=20=0A+=09{=0A+=09=09{"transaction_timeout",=20= PGC_USERSET,=20CLIENT_CONN_STATEMENT,=0A+=09=09=09gettext_noop("Sets=20= the=20maximum=20allowed=20time=20in=20a=20transaction=20with=20session=20= (not=20a=20prepared=20transaction)."),=0A+=09=09=09gettext_noop("A=20= value=20of=200=20turns=20off=20the=20timeout."),=0A+=09=09=09GUC_UNIT_MS=0A= +=09=09},=0A+=09=09&TransactionTimeout,=0A+=09=090,=200,=20INT_MAX,=0A+=09= =09NULL,=20NULL,=20NULL=0A+=09},=0A+=0A=20=09{=0A=20=09=09= {"idle_session_timeout",=20PGC_USERSET,=20CLIENT_CONN_STATEMENT,=0A=20=09= =09=09gettext_noop("Sets=20the=20maximum=20allowed=20idle=20time=20= between=20queries,=20when=20not=20in=20a=20transaction."),=0Adiff=20= --git=20a/src/backend/utils/misc/postgresql.conf.sample=20= b/src/backend/utils/misc/postgresql.conf.sample=0Aindex=20= da10b43dac3..3b8992f0fbf=20100644=0A---=20= a/src/backend/utils/misc/postgresql.conf.sample=0A+++=20= b/src/backend/utils/misc/postgresql.conf.sample=0A@@=20-701,6=20+701,7=20= @@=0A=20#default_transaction_deferrable=20=3D=20off=0A=20= #session_replication_role=20=3D=20'origin'=0A=20#statement_timeout=20=3D=20= 0=09=09=09=09#=20in=20milliseconds,=200=20is=20disabled=0A= +#transaction_timeout=20=3D=200=09=09=09#=20in=20milliseconds,=200=20is=20= disabled=0A=20#lock_timeout=20=3D=200=09=09=09=09#=20in=20milliseconds,=20= 0=20is=20disabled=0A=20#idle_in_transaction_session_timeout=20=3D=200=09= #=20in=20milliseconds,=200=20is=20disabled=0A=20#idle_session_timeout=20= =3D=200=09=09=09#=20in=20milliseconds,=200=20is=20disabled=0Adiff=20= --git=20a/src/bin/pg_dump/pg_backup_archiver.c=20= b/src/bin/pg_dump/pg_backup_archiver.c=0Aindex=20= 256d1e35a4e..3342971bd01=20100644=0A---=20= a/src/bin/pg_dump/pg_backup_archiver.c=0A+++=20= b/src/bin/pg_dump/pg_backup_archiver.c=0A@@=20-3115,6=20+3115,8=20@@=20= _doSetFixedOutputState(ArchiveHandle=20*AH)=0A=20=09ahprintf(AH,=20"SET=20= statement_timeout=20=3D=200;\n");=0A=20=09ahprintf(AH,=20"SET=20= lock_timeout=20=3D=200;\n");=0A=20=09ahprintf(AH,=20"SET=20= idle_in_transaction_session_timeout=20=3D=200;\n");=0A+=09//=20TODO:=20= AB:=20do=20we=20need=20spacial=20handling=20for=20this?=0A+=09= ahprintf(AH,=20"SET=20transaction_timeout=20=3D=200;\n");=0A=20=0A=20=09= /*=20Select=20the=20correct=20character=20set=20encoding=20*/=0A=20=09= ahprintf(AH,=20"SET=20client_encoding=20=3D=20'%s';\n",=0Adiff=20--git=20= a/src/bin/pg_dump/pg_dump.c=20b/src/bin/pg_dump/pg_dump.c=0Aindex=20= a19443becd6..119cfbcf0f5=20100644=0A---=20a/src/bin/pg_dump/pg_dump.c=0A= +++=20b/src/bin/pg_dump/pg_dump.c=0A@@=20-1252,6=20+1252,8=20@@=20= setup_connection(Archive=20*AH,=20const=20char=20*dumpencoding,=0A=20=09=09= ExecuteSqlStatement(AH,=20"SET=20lock_timeout=20=3D=200");=0A=20=09if=20= (AH->remoteVersion=20>=3D=2090600)=0A=20=09=09ExecuteSqlStatement(AH,=20= "SET=20idle_in_transaction_session_timeout=20=3D=200");=0A+=09if=20= (AH->remoteVersion=20>=3D=20170000)=0A+=09=09ExecuteSqlStatement(AH,=20= "SET=20transaction_timeout=20=3D=200");=0A=20=0A=20=09/*=0A=20=09=20*=20= Quote=20all=20identifiers,=20if=20requested.=0Adiff=20--git=20= a/src/bin/pg_rewind/libpq_source.c=20b/src/bin/pg_rewind/libpq_source.c=0A= index=2011347ab1824..7d898c3b501=20100644=0A---=20= a/src/bin/pg_rewind/libpq_source.c=0A+++=20= b/src/bin/pg_rewind/libpq_source.c=0A@@=20-117,6=20+117,7=20@@=20= init_libpq_conn(PGconn=20*conn)=0A=20=09run_simple_command(conn,=20"SET=20= statement_timeout=20=3D=200");=0A=20=09run_simple_command(conn,=20"SET=20= lock_timeout=20=3D=200");=0A=20=09run_simple_command(conn,=20"SET=20= idle_in_transaction_session_timeout=20=3D=200");=0A+=09= run_simple_command(conn,=20"SET=20transaction_timeout=20=3D=200");=0A=20=0A= =20=09/*=0A=20=09=20*=20we=20don't=20intend=20to=20do=20any=20updates,=20= put=20the=20connection=20in=20read-only=20mode=0Adiff=20--git=20= a/src/include/miscadmin.h=20b/src/include/miscadmin.h=0Aindex=20= 0b01c1f0935..0445fbf61d7=20100644=0A---=20a/src/include/miscadmin.h=0A= +++=20b/src/include/miscadmin.h=0A@@=20-91,6=20+91,7=20@@=20extern=20= PGDLLIMPORT=20volatile=20sig_atomic_t=20InterruptPending;=0A=20extern=20= PGDLLIMPORT=20volatile=20sig_atomic_t=20QueryCancelPending;=0A=20extern=20= PGDLLIMPORT=20volatile=20sig_atomic_t=20ProcDiePending;=0A=20extern=20= PGDLLIMPORT=20volatile=20sig_atomic_t=20= IdleInTransactionSessionTimeoutPending;=0A+extern=20PGDLLIMPORT=20= volatile=20sig_atomic_t=20TransactionTimeoutPending;=0A=20extern=20= PGDLLIMPORT=20volatile=20sig_atomic_t=20IdleSessionTimeoutPending;=0A=20= extern=20PGDLLIMPORT=20volatile=20sig_atomic_t=20= ProcSignalBarrierPending;=0A=20extern=20PGDLLIMPORT=20volatile=20= sig_atomic_t=20LogMemoryContextPending;=0Adiff=20--git=20= a/src/include/storage/proc.h=20b/src/include/storage/proc.h=0Aindex=20= 4bc226e36cd..20d6fa652dc=20100644=0A---=20a/src/include/storage/proc.h=0A= +++=20b/src/include/storage/proc.h=0A@@=20-429,6=20+429,7=20@@=20extern=20= PGDLLIMPORT=20int=20DeadlockTimeout;=0A=20extern=20PGDLLIMPORT=20int=20= StatementTimeout;=0A=20extern=20PGDLLIMPORT=20int=20LockTimeout;=0A=20= extern=20PGDLLIMPORT=20int=20IdleInTransactionSessionTimeout;=0A+extern=20= PGDLLIMPORT=20int=20TransactionTimeout;=0A=20extern=20PGDLLIMPORT=20int=20= IdleSessionTimeout;=0A=20extern=20PGDLLIMPORT=20bool=20log_lock_waits;=0A= =20=0Adiff=20--git=20a/src/include/utils/timeout.h=20= b/src/include/utils/timeout.h=0Aindex=2020e7cf72d0d..a5d8f078246=20= 100644=0A---=20a/src/include/utils/timeout.h=0A+++=20= b/src/include/utils/timeout.h=0A@@=20-31,6=20+31,7=20@@=20typedef=20enum=20= TimeoutId=0A=20=09STANDBY_TIMEOUT,=0A=20=09STANDBY_LOCK_TIMEOUT,=0A=20=09= IDLE_IN_TRANSACTION_SESSION_TIMEOUT,=0A+=09TRANSACTION_TIMEOUT,=0A=20=09= IDLE_SESSION_TIMEOUT,=0A=20=09IDLE_STATS_UPDATE_TIMEOUT,=0A=20=09= CLIENT_CONNECTION_CHECK_TIMEOUT,=0Adiff=20--git=20= a/src/test/isolation/Makefile=20b/src/test/isolation/Makefile=0Aindex=20= ade2256ed3a..91307e1a7e8=20100644=0A---=20a/src/test/isolation/Makefile=0A= +++=20b/src/test/isolation/Makefile=0A@@=20-72,3=20+72,6=20@@=20= installcheck-prepared-txns:=20all=20temp-install=0A=20=0A=20= check-prepared-txns:=20all=20temp-install=0A=20=09= $(pg_isolation_regress_check)=20--schedule=3D$(srcdir)/isolation_schedule=20= prepared-transactions=20prepared-transactions-cic=0A+=0A+check-timeouts:=20= all=20temp-install=0A+=09$(pg_isolation_regress_check)=20timeouts=20= timeouts-long=0Adiff=20--git=20= a/src/test/isolation/expected/timeouts-long.out=20= b/src/test/isolation/expected/timeouts-long.out=0Anew=20file=20mode=20= 100644=0Aindex=2000000000000..26a6672c051=0A---=20/dev/null=0A+++=20= b/src/test/isolation/expected/timeouts-long.out=0A@@=20-0,0=20+1,69=20@@=0A= +Parsed=20test=20spec=20with=203=20sessions=0A+=0A+starting=20= permutation:=20s7_begin=20s7_sleep=20s7_commit_and_chain=20s7_sleep=20= s7_check=20s7_abort=0A+step=20s7_begin:=20=0A+=20=20=20=20BEGIN=20= ISOLATION=20LEVEL=20READ=20COMMITTED;=0A+=20=20=20=20SET=20= transaction_timeout=20=3D=20'1s';=0A+=0A+step=20s7_sleep:=20SELECT=20= pg_sleep(0.6);=0A+pg_sleep=0A+--------=0A+=20=20=20=20=20=20=20=20=0A+(1=20= row)=0A+=0A+step=20s7_commit_and_chain:=20COMMIT=20AND=20CHAIN;=0A+step=20= s7_sleep:=20SELECT=20pg_sleep(0.6);=0A+pg_sleep=0A+--------=0A+=20=20=20=20= =20=20=20=20=0A+(1=20row)=0A+=0A+step=20s7_check:=20SELECT=20count(*)=20= FROM=20pg_stat_activity=20WHERE=20application_name=20=3D=20= 'isolation/timeouts/s7';=0A+count=0A+-----=0A+=20=20=20=200=0A+(1=20row)=0A= +=0A+step=20s7_abort:=20ABORT;=0A+=0A+starting=20permutation:=20s8_begin=20= s8_sleep=20s8_select_1=20s8_check=20checker_sleep=20checker_sleep=20= s8_check=0A+step=20s8_begin:=20=0A+=20=20=20=20BEGIN=20ISOLATION=20LEVEL=20= READ=20COMMITTED;=0A+=20=20=20=20SET=20transaction_timeout=20=3D=20= '900ms';=0A+=0A+step=20s8_sleep:=20SELECT=20pg_sleep(0.6);=0A+pg_sleep=0A= +--------=0A+=20=20=20=20=20=20=20=20=0A+(1=20row)=0A+=0A+step=20= s8_select_1:=20SELECT=201;=0A+?column?=0A+--------=0A+=20=20=20=20=20=20=20= 1=0A+(1=20row)=0A+=0A+step=20s8_check:=20SELECT=20count(*)=20FROM=20= pg_stat_activity=20WHERE=20application_name=20=3D=20= 'isolation/timeouts/s8';=0A+count=0A+-----=0A+=20=20=20=200=0A+(1=20row)=0A= +=0A+step=20checker_sleep:=20SELECT=20pg_sleep(0.3);=0A+pg_sleep=0A= +--------=0A+=20=20=20=20=20=20=20=20=0A+(1=20row)=0A+=0A+step=20= checker_sleep:=20SELECT=20pg_sleep(0.3);=0A+pg_sleep=0A+--------=0A+=20=20= =20=20=20=20=20=20=0A+(1=20row)=0A+=0A+step=20s8_check:=20SELECT=20= count(*)=20FROM=20pg_stat_activity=20WHERE=20application_name=20=3D=20= 'isolation/timeouts/s8';=0A+count=0A+-----=0A+=20=20=20=200=0A+(1=20row)=0A= +=0Adiff=20--git=20a/src/test/isolation/expected/timeouts.out=20= b/src/test/isolation/expected/timeouts.out=0Aindex=20= 9328676f1cc..81a0016375b=20100644=0A---=20= a/src/test/isolation/expected/timeouts.out=0A+++=20= b/src/test/isolation/expected/timeouts.out=0A@@=20-1,4=20+1,4=20@@=0A= -Parsed=20test=20spec=20with=202=20sessions=0A+Parsed=20test=20spec=20= with=207=20sessions=0A=20=0A=20starting=20permutation:=20rdtbl=20sto=20= locktbl=0A=20step=20rdtbl:=20SELECT=20*=20FROM=20accounts;=0A@@=20-79,3=20= +79,80=20@@=20step=20slto:=20SET=20lock_timeout=20=3D=20'10s';=20SET=20= statement_timeout=20=3D=20'10ms';=0A=20step=20update:=20DELETE=20FROM=20= accounts=20WHERE=20accountid=20=3D=20'checking';=20=0A=20= step=20update:=20<...=20completed>=0A=20ERROR:=20=20canceling=20= statement=20due=20to=20statement=20timeout=0A+=0A+starting=20= permutation:=20stto=20s3_begin=20s3_sleep=20s3_check=20s3_abort=0A+step=20= stto:=20SET=20statement_timeout=20=3D=20'10ms';=20SET=20= transaction_timeout=20=3D=20'1s';=0A+step=20s3_begin:=20BEGIN=20= ISOLATION=20LEVEL=20READ=20COMMITTED;=0A+step=20s3_sleep:=20SELECT=20= pg_sleep(0.1);=0A+ERROR:=20=20canceling=20statement=20due=20to=20= statement=20timeout=0A+step=20s3_check:=20SELECT=20count(*)=20FROM=20= pg_stat_activity=20WHERE=20application_name=20=3D=20= 'isolation/timeouts/s3';=0A+count=0A+-----=0A+=20=20=20=201=0A+(1=20row)=0A= +=0A+step=20s3_abort:=20ABORT;=0A+=0A+starting=20permutation:=20tsto=20= s3_begin=20checker_sleep=20s3_check=0A+step=20tsto:=20SET=20= statement_timeout=20=3D=20'1s';=20SET=20transaction_timeout=20=3D=20= '10ms';=0A+step=20s3_begin:=20BEGIN=20ISOLATION=20LEVEL=20READ=20= COMMITTED;=0A+step=20checker_sleep:=20SELECT=20pg_sleep(0.1);=0A= +pg_sleep=0A+--------=0A+=20=20=20=20=20=20=20=20=0A+(1=20row)=0A+=0A= +step=20s3_check:=20SELECT=20count(*)=20FROM=20pg_stat_activity=20WHERE=20= application_name=20=3D=20'isolation/timeouts/s3';=0A+count=0A+-----=0A+=20= =20=20=200=0A+(1=20row)=0A+=0A+=0A+starting=20permutation:=20itto=20= s4_begin=20checker_sleep=20s4_check=0A+step=20itto:=20SET=20= idle_in_transaction_session_timeout=20=3D=20'10ms';=20SET=20= transaction_timeout=20=3D=20'1s';=0A+step=20s4_begin:=20BEGIN=20= ISOLATION=20LEVEL=20READ=20COMMITTED;=0A+step=20checker_sleep:=20SELECT=20= pg_sleep(0.1);=0A+pg_sleep=0A+--------=0A+=20=20=20=20=20=20=20=20=0A+(1=20= row)=0A+=0A+step=20s4_check:=20SELECT=20count(*)=20FROM=20= pg_stat_activity=20WHERE=20application_name=20=3D=20= 'isolation/timeouts/s4';=0A+count=0A+-----=0A+=20=20=20=200=0A+(1=20row)=0A= +=0A+=0A+starting=20permutation:=20tito=20s5_begin=20checker_sleep=20= s5_check=0A+step=20tito:=20SET=20idle_in_transaction_session_timeout=20=3D= =20'1s';=20SET=20transaction_timeout=20=3D=20'10ms';=0A+step=20s5_begin:=20= BEGIN=20ISOLATION=20LEVEL=20READ=20COMMITTED;=0A+step=20checker_sleep:=20= SELECT=20pg_sleep(0.1);=0A+pg_sleep=0A+--------=0A+=20=20=20=20=20=20=20=20= =0A+(1=20row)=0A+=0A+step=20s5_check:=20SELECT=20count(*)=20FROM=20= pg_stat_activity=20WHERE=20application_name=20=3D=20= 'isolation/timeouts/s5';=0A+count=0A+-----=0A+=20=20=20=200=0A+(1=20row)=0A= +=0A+=0A+starting=20permutation:=20s6_begin=20s6_tt=20checker_sleep=20= s6_check=0A+step=20s6_begin:=20BEGIN=20ISOLATION=20LEVEL=20READ=20= COMMITTED;=0A+step=20s6_tt:=20SET=20statement_timeout=20=3D=20'1s';=20= SET=20transaction_timeout=20=3D=20'10ms';=0A+step=20checker_sleep:=20= SELECT=20pg_sleep(0.1);=0A+pg_sleep=0A+--------=0A+=20=20=20=20=20=20=20=20= =0A+(1=20row)=0A+=0A+step=20s6_check:=20SELECT=20count(*)=20FROM=20= pg_stat_activity=20WHERE=20application_name=20=3D=20= 'isolation/timeouts/s6';=0A+count=0A+-----=0A+=20=20=20=200=0A+(1=20row)=0A= +=0Adiff=20--git=20a/src/test/isolation/isolation_schedule=20= b/src/test/isolation/isolation_schedule=0Aindex=20= b2be88ead1d..86ef62bbcf6=20100644=0A---=20= a/src/test/isolation/isolation_schedule=0A+++=20= b/src/test/isolation/isolation_schedule=0A@@=20-89,6=20+89,7=20@@=20= test:=20sequence-ddl=0A=20test:=20async-notify=0A=20test:=20= vacuum-no-cleanup-lock=0A=20test:=20timeouts=0A+test:=20timeouts-long=0A=20= test:=20vacuum-concurrent-drop=0A=20test:=20vacuum-conflict=0A=20test:=20= vacuum-skip-locked=0Adiff=20--git=20= a/src/test/isolation/specs/timeouts-long.spec=20= b/src/test/isolation/specs/timeouts-long.spec=0Anew=20file=20mode=20= 100644=0Aindex=2000000000000..ce2c9a43011=0A---=20/dev/null=0A+++=20= b/src/test/isolation/specs/timeouts-long.spec=0A@@=20-0,0=20+1,35=20@@=0A= +#=20Tests=20for=20transaction=20timeout=20that=20require=20long=20wait=20= times=0A+=0A+session=20s7=0A+step=20s7_begin=0A+{=0A+=20=20=20=20BEGIN=20= ISOLATION=20LEVEL=20READ=20COMMITTED;=0A+=20=20=20=20SET=20= transaction_timeout=20=3D=20'1s';=0A+}=0A+step=20s7_commit_and_chain=20{=20= COMMIT=20AND=20CHAIN;=20}=0A+step=20s7_sleep=09{=20SELECT=20= pg_sleep(0.6);=20}=0A+step=20s7_abort=09{=20ABORT;=20}=0A+=0A+session=20= s8=0A+step=20s8_begin=0A+{=0A+=20=20=20=20BEGIN=20ISOLATION=20LEVEL=20= READ=20COMMITTED;=0A+=20=20=20=20SET=20transaction_timeout=20=3D=20= '900ms';=0A+}=0A+#=20to=20test=20that=20quick=20query=20does=20not=20= restart=20transaction_timeout=0A+step=20s8_select_1=20{=20SELECT=201;=20= }=0A+step=20s8_sleep=09{=20SELECT=20pg_sleep(0.6);=20}=0A+=0A+session=20= checker=0A+step=20checker_sleep=09{=20SELECT=20pg_sleep(0.3);=20}=0A= +step=20s7_check=09{=20SELECT=20count(*)=20FROM=20pg_stat_activity=20= WHERE=20application_name=20=3D=20'isolation/timeouts/s7';=20}=0A+step=20= s8_check=09{=20SELECT=20count(*)=20FROM=20pg_stat_activity=20WHERE=20= application_name=20=3D=20'isolation/timeouts/s8';=20}=0A+=0A+#=20COMMIT=20= AND=20CHAIN=20must=20restart=20transaction=20timeout=0A+permutation=20= s7_begin=20s7_sleep=20s7_commit_and_chain=20s7_sleep=20s7_check=20= s7_abort=0A+#=20transaction=20timeout=20expires=20in=20presence=20of=20= query=20flow,=20session=20s7=20FATAL-out=0A+#=20this=20relatevely=20long=20= sleeps=20are=20picked=20to=20ensure=20300ms=20gap=20between=20check=20= and=20timeouts=20firing=0A+#=20expected=20flow:=20timeouts=20is=20= scheduled=20after=20s8_begin=20and=20fires=20approximately=20after=20= checker_sleep=20(300ms=20before=20check)=0A+#=20possible=20buggy=20flow:=20= timeout=20is=20schedules=20after=20s8_select_1=20and=20fires=20300ms=20= after=20s8_check=0A+#=20to=20ensure=20this=20300ms=20gap=20we=20need=20= minimum=20transaction_timeout=20of=20300ms=0A+permutation=20s8_begin=20= s8_sleep=20s8_select_1=20s8_check=20checker_sleep=20checker_sleep=20= s8_check=0Adiff=20--git=20a/src/test/isolation/specs/timeouts.spec=20= b/src/test/isolation/specs/timeouts.spec=0Aindex=20= c747b4ae28d..c2cc5d8d37b=20100644=0A---=20= a/src/test/isolation/specs/timeouts.spec=0A+++=20= b/src/test/isolation/specs/timeouts.spec=0A@@=20-1,4=20+1,4=20@@=0A-#=20= Simple=20tests=20for=20statement_timeout=20and=20lock_timeout=20features=0A= +#=20Simple=20tests=20for=20statement_timeout,=20lock_timeout=20and=20= transaction_timeout=20features=0A=20=0A=20setup=0A=20{=0A@@=20-27,6=20= +27,33=20@@=20step=20locktbl=09{=20LOCK=20TABLE=20accounts;=20}=0A=20= step=20update=09{=20DELETE=20FROM=20accounts=20WHERE=20accountid=20=3D=20= 'checking';=20}=0A=20teardown=09{=20ABORT;=20}=0A=20=0A+session=20s3=0A= +step=20s3_begin=09{=20BEGIN=20ISOLATION=20LEVEL=20READ=20COMMITTED;=20}=0A= +step=20stto=09{=20SET=20statement_timeout=20=3D=20'10ms';=20SET=20= transaction_timeout=20=3D=20'1s';=20}=0A+step=20tsto=09{=20SET=20= statement_timeout=20=3D=20'1s';=20SET=20transaction_timeout=20=3D=20= '10ms';=20}=0A+step=20s3_sleep=09{=20SELECT=20pg_sleep(0.1);=20}=0A+step=20= s3_abort=09{=20ABORT;=20}=0A+=0A+session=20s4=0A+step=20s4_begin=09{=20= BEGIN=20ISOLATION=20LEVEL=20READ=20COMMITTED;=20}=0A+step=20itto=09{=20= SET=20idle_in_transaction_session_timeout=20=3D=20'10ms';=20SET=20= transaction_timeout=20=3D=20'1s';=20}=0A+=0A+session=20s5=0A+step=20= s5_begin=09{=20BEGIN=20ISOLATION=20LEVEL=20READ=20COMMITTED;=20}=0A+step=20= tito=09{=20SET=20idle_in_transaction_session_timeout=20=3D=20'1s';=20SET=20= transaction_timeout=20=3D=20'10ms';=20}=0A+=0A+session=20s6=0A+step=20= s6_begin=09{=20BEGIN=20ISOLATION=20LEVEL=20READ=20COMMITTED;=20}=0A+step=20= s6_tt=09{=20SET=20statement_timeout=20=3D=20'1s';=20SET=20= transaction_timeout=20=3D=20'10ms';=20}=0A+=0A+session=20checker=0A+step=20= checker_sleep=09{=20SELECT=20pg_sleep(0.1);=20}=0A+step=20s3_check=09{=20= SELECT=20count(*)=20FROM=20pg_stat_activity=20WHERE=20application_name=20= =3D=20'isolation/timeouts/s3';=20}=0A+step=20s4_check=09{=20SELECT=20= count(*)=20FROM=20pg_stat_activity=20WHERE=20application_name=20=3D=20= 'isolation/timeouts/s4';=20}=0A+step=20s5_check=09{=20SELECT=20count(*)=20= FROM=20pg_stat_activity=20WHERE=20application_name=20=3D=20= 'isolation/timeouts/s5';=20}=0A+step=20s6_check=09{=20SELECT=20count(*)=20= FROM=20pg_stat_activity=20WHERE=20application_name=20=3D=20= 'isolation/timeouts/s6';=20}=0A+=0A+=0A=20#=20It's=20possible=20that=20= the=20isolation=20tester=20will=20not=20observe=20the=20final=0A=20#=20= steps=20as=20"waiting",=20thanks=20to=20the=20relatively=20short=20= timeouts=20we=20use.=0A=20#=20We=20can=20ensure=20consistent=20test=20= output=20by=20marking=20those=20steps=20with=20(*).=0A@@=20-47,3=20= +74,14=20@@=20permutation=20wrtbl=20lto=20update(*)=0A=20permutation=20= wrtbl=20lsto=20update(*)=0A=20#=20statement=20timeout=20expires=20first,=20= row-level=20lock=0A=20permutation=20wrtbl=20slto=20update(*)=0A+=0A+#=20= statement=20timeout=20expires=20first=0A+permutation=20stto=20s3_begin=20= s3_sleep=20s3_check=20s3_abort=0A+#=20transaction=20timeout=20expires=20= first,=20session=20s3=20FATAL-out=0A+permutation=20tsto=20s3_begin=20= checker_sleep=20s3_check=0A+#=20idle=20in=20transaction=20timeout=20= expires=20first,=20session=20s4=20FATAL-out=0A+permutation=20itto=20= s4_begin=20checker_sleep=20s4_check=0A+#=20transaction=20timeout=20= expires=20first,=20session=20s5=20FATAL-out=0A+permutation=20tito=20= s5_begin=20checker_sleep=20s5_check=0A+#=20transaction=20timeout=20can=20= be=20schedule=20amid=20transaction,=20session=20s6=20FATAL-out=0A= +permutation=20s6_begin=20s6_tt=20checker_sleep=20s6_check=0A\=20No=20= newline=20at=20end=20of=20file=0A--=20=0A2.42.0=0A=0A= --Apple-Mail=_198FA4EF-F6B4-41A9-B2D9-373A21FA3253--