MySQL :: MySQL 8.4 Reference Manual :: 29.12.13.3 The metadata_locks Table (original) (raw)

29.12.13.3 The metadata_locks Table

MySQL uses metadata locking to manage concurrent access to database objects and to ensure data consistency; seeSection 10.11.4, “Metadata Locking”. Metadata locking applies not just to tables, but also to schemas, stored programs (procedures, functions, triggers, scheduled events), tablespaces, user locks acquired with theGET_LOCK() function (seeSection 14.14, “Locking Functions”), and locks acquired with the locking service described inSection 7.6.9.1, “The Locking Service”.

The Performance Schema exposes metadata lock information through the metadata_locks table:

This information enables you to understand metadata lock dependencies between sessions. You can see not only which lock a session is waiting for, but which session currently holds that lock.

The metadata_locks table is read only and cannot be updated. It is autosized by default; to configure the table size, set theperformance_schema_max_metadata_locks system variable at server startup.

Metadata lock instrumentation uses thewait/lock/metadata/sql/mdl instrument, which is enabled by default.

To control metadata lock instrumentation state at server startup, use lines like these in yourmy.cnf file:

[mysqld]  
performance-schema-instrument='wait/lock/metadata/sql/mdl=ON'  
[mysqld]  
performance-schema-instrument='wait/lock/metadata/sql/mdl=OFF'  

To control metadata lock instrumentation state at runtime, update the setup_instruments table:

UPDATE performance_schema.setup_instruments  
SET ENABLED = 'YES', TIMED = 'YES'  
WHERE NAME = 'wait/lock/metadata/sql/mdl';  
UPDATE performance_schema.setup_instruments  
SET ENABLED = 'NO', TIMED = 'NO'  
WHERE NAME = 'wait/lock/metadata/sql/mdl';  

The Performance Schema maintainsmetadata_locks table content as follows, using the LOCK_STATUS column to indicate the status of each lock:

The metadata_locks table has these columns:

The metadata_locks table has these indexes:

TRUNCATE TABLE is not permitted for the metadata_locks table.