Description\n-----------\n\nMariaDB supports metadata locking. This means that when a transaction (including XA transactions) uses a table, it locks its metadata until the end of transaction. Non-transactional tables are also locked, as well as views and objects which are related to locked tables/views (stored functions, triggers, etc). When a connection tries to use a DDL statement (like an ALTER TABLE) which modifies a table that is locked, that connection is queued, and has to wait until it's unlocked. Using savepoints and performing a partial rollback does not release metadata locks.\n\nLOCK TABLES ... WRITE are also queued. Some wrong statements which produce an error may not need to wait for the lock to be freed.\n\nThe metadata lock's timeout is determined by the value of the lock_wait_timeout server system variable (in seconds). However, note that its default value is 31536000 (1 year). If this timeout is exceeded, the following error is returned:\n\n``sql\nERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction\n`\n\nIf the metadata_lock_info plugin is installed, the Information Schema metadata_lock_info table stores information about existing metadata locks.\n\nThe Performance Schema metadata_locks table contains metadata lock information.\n\nExample\n\nLet's use the following MEMORY (non-transactional) table:\n\n`sql\nCREATE TABLE t (a INT) ENGINE = MEMORY;\n`\n\nConnection 1 starts a transaction, and INSERTs a row into t:\n\n`sql\nSTART TRANSACTION;\n\nINSERT INTO t SET a=1;\n`\n\nt's metadata is now locked by connection 1. Connection 2 tries to alter t, but has to wait:\n\n`sql\nALTER TABLE t ADD COLUMN b INT;\n`\n\nConnection 2's prompt is blocked now.\n\nNow connection 1 ends the transaction:\n\n`sql\nCOMMIT;\n`\n\n...and connection 2 finally gets the output of its command:\n\n`sql\nQuery OK, 1 row affected (35.23 sec)\nRecords: 1  Duplicates: 0  Warnings: 0\n``\n\nThe Performance Schema metadata_locks table does not contain metadata lock information.\n\nURL: https://mariadb.com/docs/server/reference/sql-statements/transactions/metadata-locking