Skip to content

Commit 0e9dec0

Browse files
authored
v7.6 introduces a system variable tidb_idle_transaction_timeout (#15693)
1 parent 645e5f3 commit 0e9dec0

File tree

4 files changed

+18
-2
lines changed

4 files changed

+18
-2
lines changed

develop/dev-guide-connection-parameters.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,4 +267,6 @@ After it is configured, you can check the monitoring to see a decreased number o
267267

268268
TiDB provides two MySQL-compatible parameters to control the timeout: [`wait_timeout`](/system-variables.md#wait_timeout) and [`max_execution_time`](/system-variables.md#max_execution_time). These two parameters respectively control the connection idle timeout with the Java application and the timeout of the SQL execution in the connection; that is to say, these parameters control the longest idle time and the longest busy time for the connection between TiDB and the Java application. Since TiDB v5.4, the default value of `wait_timeout` is `28800` seconds, which is 8 hours. For TiDB versions earlier than v5.4, the default value is `0`, which means the timeout is unlimited. The default value of `max_execution_time` is `0`, which means the maximum execution time of a SQL statement is unlimited.
269269

270+
The default value of [`wait_timeout`](/system-variables.md#wait_timeout) is relatively large. In scenarios where a transaction starts but is neither committed nor rolled back, you might need a finer-grained control and a shorter timeout to prevent prolonged lock holding. In this case, you can use [`tidb_idle_transaction_timeout`](/system-variables.md#tidb_idle_transaction_timeout-new-in-v760) (introduced in TiDB v7.6.0) to control the idle timeout for transactions in a user session.
271+
270272
However, in an actual production environment, idle connections and SQL statements with excessively long execution time negatively affect databases and applications. To avoid idle connections and SQL statements that are executed for too long, you can configure these two parameters in your application's connection string. For example, set `sessionVariables=wait_timeout=3600` (1 hour) and `sessionVariables=max_execution_time=300000` (5 minutes).

develop/dev-guide-timeouts-in-tidb.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ For more information about GC, see [GC Overview](/garbage-collection-overview.md
1919

2020
## Transaction timeout
2121

22+
In scenarios where a transaction starts but is neither committed nor rolled back, you might need a finer-grained control and a shorter timeout to prevent prolonged lock holding. In this case, you can use [`tidb_idle_transaction_timeout`](/system-variables.md#tidb_idle_transaction_timeout-new-in-v760) (introduced in TiDB v7.6.0) to control the idle timeout for transactions in a user session.
23+
2224
GC does not affect ongoing transactions. However, there is still an upper limit to the number of pessimistic transactions that can run, with a limit on the transaction timeout and a limit on the memory used by the transaction. You can modify the transaction timeout by `max-txn-ttl` under the `[performance]` category of the TiDB profile, `60` minutes by default.
2325

2426
SQL statements such as `INSERT INTO t10 SELECT * FROM t1` are not affected by GC, but will be rolled back due to timeout after exceeding `max-txn-ttl`.

faq/manage-cluster-faq.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ By default, TiDB/PD/TiKV outputs standard error in the logs. If a log file is sp
5555

5656
### Does TiDB support session timeout?
5757

58-
TiDB currently supports two timeouts, [`wait_timeout`](/system-variables.md#wait_timeout) and [`interactive_timeout`](/system-variables.md#interactive_timeout).
58+
TiDB currently supports the following timeouts: [`wait_timeout`](/system-variables.md#wait_timeout), [`interactive_timeout`](/system-variables.md#interactive_timeout), and [`tidb_idle_transaction_timeout`](/system-variables.md#tidb_idle_transaction_timeout-new-in-v760).
5959

6060
### What is the TiDB version management strategy?
6161

system-variables.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3098,10 +3098,22 @@ For a system upgraded to v5.0 from an earlier version, if you have not modified
30983098
- Scope: GLOBAL
30993099
- Persists to cluster: Yes
31003100
- Applies to hint [SET_VAR](/optimizer-hints.md#set_varvar_namevar_value): No
3101-
- Tyle: Duration
3101+
- Type: Duration
31023102
- Default value: `168h`, which means 7 days
31033103
- This variable controls the duration that the historical statistics are retained in the storage.
31043104
3105+
### tidb_idle_transaction_timeout <span class="version-mark">New in v7.6.0</span>
3106+
3107+
- Scope: SESSION | GLOBAL
3108+
- Persists to cluster: Yes
3109+
- Applies to hint [SET_VAR](/optimizer-hints.md#set_varvar_namevar_value): No
3110+
- Type: Integer
3111+
- Default value: `0`
3112+
- Range: `[0, 31536000]`
3113+
- Unit: Seconds
3114+
- This variable controls the idle timeout for transactions in a user session. When a user session is in a transactional state and remains idle for a duration exceeding the value of this variable, TiDB will terminate the session. An idle user session means that there are no active requests and the session is waiting for new requests.
3115+
- The default value `0` means unlimited.
3116+
31053117
### tidb_ignore_prepared_cache_close_stmt <span class="version-mark">New in v6.0.0</span>
31063118
31073119
- Scope: SESSION | GLOBAL

0 commit comments

Comments
 (0)