> For the complete documentation index, see [llms.txt](https://mariadb.com/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://mariadb.com/docs/server/reference/error-codes/mariadb-error-codes-1200-to-1299/e1205.md).

# Error 1205: Lock wait timeout exceeded; try restarting transaction

| Error Code | SQLSTATE | Error                   | Description                                            |
| ---------- | -------- | ----------------------- | ------------------------------------------------------ |
| 1205       | HY000    | ER\_LOCK\_WAIT\_TIMEOUT | Lock wait timeout exceeded; try restarting transaction |

## Possible Causes and Solutions

The statement waited for a lock that another transaction holds, and gave up when the time limit passed. There are two kinds of locks, with their own time limits:

* **Row locks.** InnoDB waits [innodb\_lock\_wait\_timeout](/docs/server/server-usage/storage-engines/innodb/innodb-system-variables.md#innodb_lock_wait_timeout) seconds, 50 by default, for a row that another transaction has locked with an `UPDATE`, `DELETE`, `INSERT` or a locking read.
* **Metadata locks.** A statement such as [ALTER TABLE](/docs/server/reference/sql-statements/data-definition/alter/alter-table.md) waits [lock\_wait\_timeout](/docs/server/server-management/variables-and-modes/server-system-variables.md#lock_wait_timeout) seconds, one day by default, while any open transaction has used the table. See [Metadata Locking](/docs/server/reference/sql-statements/transactions/metadata-locking.md).

The same error comes right away from a locking statement with [NOWAIT](/docs/server/reference/sql-statements/transactions/wait-and-nowait.md), or after `n` seconds with `WAIT n`, when the lock isn't free.

By default, only the statement that timed out is rolled back. The transaction stays open, with its earlier changes, so you have to commit it or roll it back. With [innodb\_rollback\_on\_timeout](/docs/server/server-usage/storage-engines/innodb/innodb-system-variables.md#innodb_rollback_on_timeout) set, InnoDB rolls back the whole transaction instead.

To solve the error:

* Find the transaction that holds the lock. [SHOW ENGINE INNODB STATUS](/docs/server/reference/sql-statements/administrative-sql-statements/show/show-engine-innodb-status.md) lists the open transactions, and the [Information Schema INNODB\_TRX table](/docs/server/reference/system-tables/information-schema/information-schema-tables/information-schema-innodb-tables/information-schema-innodb_trx-table.md) shows how long each has been running. Often it is a session that started a transaction and never committed it, for example a client with [autocommit](/docs/server/server-management/variables-and-modes/server-system-variables.md#autocommit) turned off.
* Commit or roll back that transaction, or end the session with [KILL](/docs/server/reference/sql-statements/administrative-sql-statements/kill.md).
* Keep transactions short, and don't wait for user input while a transaction is open.
* Add indexes, so that statements lock fewer rows.
* Retry the statement or the transaction in the application.
* Increase the time limit only when long waits are expected, for example for a batch job.
* To skip rows that other transactions have locked, instead of waiting for them, use [SKIP LOCKED](/docs/server/reference/sql-statements/data-manipulation/selecting-data/select.md#skip-locked).

A deadlock, where transactions wait for each other, gives [error 1213](/docs/server/reference/error-codes/mariadb-error-codes-1200-to-1299/e1213.md) right away, unless [innodb\_deadlock\_detect](/docs/server/server-usage/storage-engines/innodb/innodb-system-variables.md#innodb_deadlock_detect) is OFF.

<sub>*This page is licensed: CC BY-SA / Gnu FDL*</sub>

{% @marketo/form formId="4316" %}
