All pages
Powered by GitBook
1 of 1

Loading...

Transaction Timeouts

Understand how timeouts affect transactions. This section explains system variables that control wait times for locks and transaction duration.

MariaDB has always had the wait_timeout and interactive_timeout settings, which close connections after a certain period of inactivity.

However, these are by default set to a long wait period. In situations where transactions may be started, but not committed or rolled back, more granular control and a shorter timeout may be desirable so as to avoid locks being held for too long.

These variables help handle this situation:

  • idle_transaction_timeout (all transactions)

  • idle_write_transaction_timeout (write transactions)

  • (read transactions)

There is no variables for more granular control.

These accept a time in seconds to time out, by closing the connection, transactions that are idle for longer than this period. By default all are set to zero, or no timeout.

affects all transactions, affects write transactions only and affects read transactions only. The latter two variables work independently. However, if either is set along with , the settings for or will take precedence.

Examples

This page is licensed: CC BY-SA / Gnu FDL

idle_readonly_transaction_timeout
idle_transaction_timeout
idle_write_transaction_timeout
idle_readonly_transaction_timeout
idle_transaction_timeout
idle_write_transaction_timeout
idle_readonly_transaction_timeout
SET SESSION idle_transaction_timeout=2;
BEGIN;
SELECT * FROM t;
Empty set (0.000 sec)
## wait 3 seconds
SELECT * FROM t;
ERROR 2006 (HY000): MySQL server has gone away
SET SESSION idle_write_transaction_timeout=2;
BEGIN;
SELECT * FROM t;
Empty set (0.000 sec)
## wait 3 seconds
SELECT * FROM t;
Empty set (0.000 sec)
INSERT INTO t VALUES(1);
## wait 3 seconds
SELECT * FROM t;
ERROR 2006 (HY000): MySQL server has gone away
SET SESSION idle_transaction_timeout=2, SESSION idle_readonly_transaction_timeout=10;
BEGIN;
SELECT * FROM t;
Empty set (0.000 sec)
 ## wait 3 seconds
SELECT * FROM t;
Empty set (0.000 sec)
## wait 11 seconds
SELECT * FROM t;
ERROR 2006 (HY000): MySQL server has gone away