Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf84a172

Browse files
author
Alexander Korotkov
committed
Initial.
1 parent4ebc0a6 commitf84a172

File tree

13 files changed

+89
-34
lines changed

13 files changed

+89
-34
lines changed

‎doc/src/sgml/config.sgml

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6293,6 +6293,23 @@ COPY postgres_log FROM '/full/path/to/logfile.csv' WITH csv;
62936293
</listitem>
62946294
</varlistentry>
62956295

6296+
<varlistentry id="guc-idle-session-timeout" xreflabel="idle_session_timeout">
6297+
<term><varname>idle_session_timeout</varname> (<type>integer</type>)
6298+
<indexterm>
6299+
<primary><varname>idle_session_timeout</> configuration parameter</primary>
6300+
</indexterm>
6301+
</term>
6302+
<listitem>
6303+
<para>
6304+
Terminate any session that has been idle for longer than the specified
6305+
duration in milliseconds.
6306+
</para>
6307+
<para>
6308+
The default value of 0 disables this feature.
6309+
</para>
6310+
</listitem>
6311+
</varlistentry>
6312+
62966313
<varlistentry id="guc-idle-in-transaction-session-timeout" xreflabel="idle_in_transaction_session_timeout">
62976314
<term><varname>idle_in_transaction_session_timeout</varname> (<type>integer</type>)
62986315
<indexterm>
@@ -6302,9 +6319,11 @@ COPY postgres_log FROM '/full/path/to/logfile.csv' WITH csv;
63026319
<listitem>
63036320
<para>
63046321
Terminate any session with an open transaction that has been idle for
6305-
longer than the specified duration in milliseconds. This allows any
6306-
locks held by that session to be released and the connection slot to be reused;
6307-
it also allows tuples visible only to this transaction to be vacuumed. See
6322+
longer than the specified duration in milliseconds. When enabled
6323+
this setting overrides <xref linkend="guc-idle-session-timeout"> for
6324+
open transaction. This allows any locks held by that session to be
6325+
released and the connection slot to be reused; it also allows tuples
6326+
visible only to this transaction to be vacuumed. See
63086327
<xref linkend="routine-vacuuming"> for more details about this.
63096328
</para>
63106329
<para>

‎src/backend/postmaster/autovacuum.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,8 @@ AutoVacLauncherMain(int argc, char *argv[])
545545
SetConfigOption("lock_timeout","0",PGC_SUSET,PGC_S_OVERRIDE);
546546
SetConfigOption("idle_in_transaction_session_timeout","0",
547547
PGC_SUSET,PGC_S_OVERRIDE);
548+
SetConfigOption("idle_session_timeout","0",
549+
PGC_SUSET,PGC_S_OVERRIDE);
548550

549551
/*
550552
* Force default_transaction_isolation to READ COMMITTED. We don't want
@@ -1560,6 +1562,8 @@ AutoVacWorkerMain(int argc, char *argv[])
15601562
SetConfigOption("lock_timeout","0",PGC_SUSET,PGC_S_OVERRIDE);
15611563
SetConfigOption("idle_in_transaction_session_timeout","0",
15621564
PGC_SUSET,PGC_S_OVERRIDE);
1565+
SetConfigOption("idle_session_timeout","0",
1566+
PGC_SUSET,PGC_S_OVERRIDE);
15631567

15641568
/*
15651569
* Force default_transaction_isolation to READ COMMITTED. We don't want

‎src/backend/storage/lmgr/proc.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ intDeadlockTimeout = 1000;
5959
intStatementTimeout=0;
6060
intLockTimeout=0;
6161
intIdleInTransactionSessionTimeout=0;
62+
intIdleSessionTimeout=0;
6263
boollog_lock_waits= false;
6364

6465
/* Pointer to this process's PGPROC and PGXACT structs, if any */

‎src/backend/tcop/postgres.c

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2993,15 +2993,21 @@ ProcessInterrupts(void)
29932993
}
29942994
}
29952995

2996-
if (IdleInTransactionSessionTimeoutPending)
2996+
if (IdleSessionTimeoutPending)
29972997
{
29982998
/* Has the timeout setting changed since last we looked? */
2999-
if (IdleInTransactionSessionTimeout>0)
2999+
if (IdleInTransactionSessionTimeout>0
3000+
&& (IsAbortedTransactionBlockState()
3001+
||IsTransactionOrTransactionBlock()))
30003002
ereport(FATAL,
30013003
(errcode(ERRCODE_IDLE_IN_TRANSACTION_SESSION_TIMEOUT),
30023004
errmsg("terminating connection due to idle-in-transaction timeout")));
3005+
elseif (IdleSessionTimeout>0)
3006+
ereport(FATAL,
3007+
(errcode(ERRCODE_IDLE_IN_TRANSACTION_SESSION_TIMEOUT),
3008+
errmsg("terminating connection due to idle timeout")));
30033009
else
3004-
IdleInTransactionSessionTimeoutPending= false;
3010+
IdleSessionTimeoutPending= false;
30053011

30063012
}
30073013

@@ -3580,7 +3586,7 @@ PostgresMain(int argc, char *argv[],
35803586
StringInfoDatainput_message;
35813587
sigjmp_buflocal_sigjmp_buf;
35823588
volatileboolsend_ready_for_query= true;
3583-
booldisable_idle_in_transaction_timeout= false;
3589+
booldisable_idle_timeout= false;
35843590

35853591
/* Initialize startup process environment if necessary. */
35863592
if (!IsUnderPostmaster)
@@ -3966,31 +3972,32 @@ PostgresMain(int argc, char *argv[],
39663972
*/
39673973
if (send_ready_for_query)
39683974
{
3969-
if (IsAbortedTransactionBlockState())
3975+
if (IsAbortedTransactionBlockState()||IsTransactionOrTransactionBlock())
39703976
{
3971-
set_ps_display("idle in transaction (aborted)", false);
3972-
pgstat_report_activity(STATE_IDLEINTRANSACTION_ABORTED,NULL);
3973-
3974-
/* Start the idle-in-transaction timer */
3975-
if (IdleInTransactionSessionTimeout>0)
3977+
if (IsAbortedTransactionBlockState())
39763978
{
3977-
disable_idle_in_transaction_timeout= true;
3978-
enable_timeout_after(IDLE_IN_TRANSACTION_SESSION_TIMEOUT,
3979-
IdleInTransactionSessionTimeout);
3979+
set_ps_display("idle in transaction (aborted)", false);
3980+
pgstat_report_activity(STATE_IDLEINTRANSACTION_ABORTED,NULL);
3981+
}
3982+
else
3983+
{
3984+
set_ps_display("idle in transaction", false);
3985+
pgstat_report_activity(STATE_IDLEINTRANSACTION,NULL);
39803986
}
3981-
}
3982-
elseif (IsTransactionOrTransactionBlock())
3983-
{
3984-
set_ps_display("idle in transaction", false);
3985-
pgstat_report_activity(STATE_IDLEINTRANSACTION,NULL);
39863987

39873988
/* Start the idle-in-transaction timer */
39883989
if (IdleInTransactionSessionTimeout>0)
39893990
{
3990-
disable_idle_in_transaction_timeout= true;
3991-
enable_timeout_after(IDLE_IN_TRANSACTION_SESSION_TIMEOUT,
3991+
disable_idle_timeout= true;
3992+
enable_timeout_after(IDLE_SESSION_TIMEOUT,
39923993
IdleInTransactionSessionTimeout);
39933994
}
3995+
elseif (IdleSessionTimeout>0)
3996+
{
3997+
disable_idle_timeout= true;
3998+
enable_timeout_after(IDLE_SESSION_TIMEOUT,
3999+
IdleSessionTimeout);
4000+
}
39944001
}
39954002
else
39964003
{
@@ -3999,6 +4006,13 @@ PostgresMain(int argc, char *argv[],
39994006

40004007
set_ps_display("idle", false);
40014008
pgstat_report_activity(STATE_IDLE,NULL);
4009+
if (IdleSessionTimeout>0)
4010+
{
4011+
disable_idle_timeout= true;
4012+
enable_timeout_after(IDLE_SESSION_TIMEOUT,
4013+
IdleSessionTimeout);
4014+
}
4015+
40024016
}
40034017

40044018
ReadyForQuery(whereToSendOutput);
@@ -4033,10 +4047,10 @@ PostgresMain(int argc, char *argv[],
40334047
/*
40344048
* (5) turn off the idle-in-transaction timeout
40354049
*/
4036-
if (disable_idle_in_transaction_timeout)
4050+
if (disable_idle_timeout)
40374051
{
4038-
disable_timeout(IDLE_IN_TRANSACTION_SESSION_TIMEOUT, false);
4039-
disable_idle_in_transaction_timeout= false;
4052+
disable_timeout(IDLE_SESSION_TIMEOUT, false);
4053+
disable_idle_timeout= false;
40404054
}
40414055

40424056
/*

‎src/backend/utils/init/globals.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ volatile bool InterruptPending = false;
3030
volatileboolQueryCancelPending= false;
3131
volatileboolProcDiePending= false;
3232
volatileboolClientConnectionLost= false;
33-
volatileboolIdleInTransactionSessionTimeoutPending= false;
33+
volatileboolIdleSessionTimeoutPending= false;
3434
volatileuint32InterruptHoldoffCount=0;
3535
volatileuint32QueryCancelHoldoffCount=0;
3636
volatileuint32CritSectionCount=0;

‎src/backend/utils/init/postinit.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ static void InitCommunication(void);
7070
staticvoidShutdownPostgres(intcode,Datumarg);
7171
staticvoidStatementTimeoutHandler(void);
7272
staticvoidLockTimeoutHandler(void);
73-
staticvoidIdleInTransactionSessionTimeoutHandler(void);
73+
staticvoidIdleSessionTimeoutHandler(void);
7474
staticboolThereIsAtLeastOneRole(void);
7575
staticvoidprocess_startup_options(Port*port,boolam_superuser);
7676
staticvoidprocess_settings(Oiddatabaseid,Oidroleid);
@@ -599,8 +599,8 @@ InitPostgres(const char *in_dbname, Oid dboid, const char *username,
599599
RegisterTimeout(DEADLOCK_TIMEOUT,CheckDeadLockAlert);
600600
RegisterTimeout(STATEMENT_TIMEOUT,StatementTimeoutHandler);
601601
RegisterTimeout(LOCK_TIMEOUT,LockTimeoutHandler);
602-
RegisterTimeout(IDLE_IN_TRANSACTION_SESSION_TIMEOUT,
603-
IdleInTransactionSessionTimeoutHandler);
602+
RegisterTimeout(IDLE_SESSION_TIMEOUT,
603+
IdleSessionTimeoutHandler);
604604
}
605605

606606
/*
@@ -1183,9 +1183,9 @@ LockTimeoutHandler(void)
11831183
}
11841184

11851185
staticvoid
1186-
IdleInTransactionSessionTimeoutHandler(void)
1186+
IdleSessionTimeoutHandler(void)
11871187
{
1188-
IdleInTransactionSessionTimeoutPending= true;
1188+
IdleSessionTimeoutPending= true;
11891189
InterruptPending= true;
11901190
SetLatch(MyLatch);
11911191
}

‎src/backend/utils/misc/guc.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2107,6 +2107,17 @@ static struct config_int ConfigureNamesInt[] =
21072107
NULL,NULL,NULL
21082108
},
21092109

2110+
{
2111+
{"idle_session_timeout",PGC_USERSET,CLIENT_CONN_STATEMENT,
2112+
gettext_noop("Sets the maximum allowed duration of any idling session."),
2113+
gettext_noop("A value of 0 turns off the timeout."),
2114+
GUC_UNIT_MS
2115+
},
2116+
&IdleSessionTimeout,
2117+
0,0,INT_MAX,
2118+
NULL,NULL,NULL
2119+
},
2120+
21102121
{
21112122
{"vacuum_freeze_min_age",PGC_USERSET,CLIENT_CONN_STATEMENT,
21122123
gettext_noop("Minimum age at which VACUUM should freeze a table row."),

‎src/backend/utils/misc/postgresql.conf.sample

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,7 @@
538538
#session_replication_role = 'origin'
539539
#statement_timeout = 0# in milliseconds, 0 is disabled
540540
#lock_timeout = 0# in milliseconds, 0 is disabled
541+
#idle_session_timeout = 0# in milliseconds, 0 is disabled
541542
#idle_in_transaction_session_timeout = 0# in milliseconds, 0 is disabled
542543
#vacuum_freeze_min_age = 50000000
543544
#vacuum_freeze_table_age = 150000000

‎src/bin/pg_dump/pg_backup_archiver.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2865,6 +2865,7 @@ _doSetFixedOutputState(ArchiveHandle *AH)
28652865
ahprintf(AH,"SET statement_timeout = 0;\n");
28662866
ahprintf(AH,"SET lock_timeout = 0;\n");
28672867
ahprintf(AH,"SET idle_in_transaction_session_timeout = 0;\n");
2868+
ahprintf(AH,"SET idle_session_timeout = 0;\n");
28682869

28692870
/* Select the correct character set encoding */
28702871
ahprintf(AH,"SET client_encoding = '%s';\n",

‎src/bin/pg_dump/pg_dump.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,7 +1023,10 @@ setup_connection(Archive *AH, const char *dumpencoding,
10231023
if (AH->remoteVersion >= 90300)
10241024
ExecuteSqlStatement(AH, "SET lock_timeout = 0");
10251025
if (AH->remoteVersion >= 90600)
1026+
{
10261027
ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0");
1028+
ExecuteSqlStatement(AH, "SET idle_session_timeout = 0");
1029+
}
10271030

10281031
/*
10291032
* Quote all identifiers, if requested.

‎src/include/miscadmin.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
externPGDLLIMPORTvolatileboolInterruptPending;
8181
externPGDLLIMPORTvolatileboolQueryCancelPending;
8282
externPGDLLIMPORTvolatileboolProcDiePending;
83-
externPGDLLIMPORTvolatileboolIdleInTransactionSessionTimeoutPending;
83+
externPGDLLIMPORTvolatileboolIdleSessionTimeoutPending;
8484

8585
externvolatileboolClientConnectionLost;
8686

‎src/include/storage/proc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ extern intDeadlockTimeout;
259259
externintStatementTimeout;
260260
externintLockTimeout;
261261
externintIdleInTransactionSessionTimeout;
262+
externintIdleSessionTimeout;
262263
externboollog_lock_waits;
263264

264265

‎src/include/utils/timeout.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ typedef enum TimeoutId
3030
STANDBY_DEADLOCK_TIMEOUT,
3131
STANDBY_TIMEOUT,
3232
STANDBY_LOCK_TIMEOUT,
33-
IDLE_IN_TRANSACTION_SESSION_TIMEOUT,
33+
IDLE_SESSION_TIMEOUT,
3434
/* First user-definable timeout reason */
3535
USER_TIMEOUT,
3636
/* Maximum number of timeout reasons */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp