Use SHOW METADATA LOCK to identify transactions that hold a metadata lock on PolarDB-X 1.0 nodes, so you can diagnose and unblock schema changes stalled during global secondary index (GSI) creation.
How it works
When PolarDB-X 1.0 creates a GSI, it uses a built-in metadata lock to maintain transaction and data consistency. Creating a GSI on a large existing table can take a long time. If a transaction is already holding a metadata lock when the GSI creation starts, schema changes are blocked until that transaction completes.
SHOW METADATA LOCK lets you find which connection and SQL statement are holding the lock, so you can decide whether to wait or stop the blocking transaction.
Syntax
SHOW METADATA {LOCK | LOCKS} [schema_name[.table_name]]schema_name and table_name are optional filters. Omit them to see all connections holding a metadata lock on the current node.
-- All connections holding a metadata lock on the node
SHOW METADATA LOCK;
-- Connections holding a metadata lock in the specified database
SHOW METADATA LOCK xxx_db;
-- Connections holding a metadata lock on the specified table
SHOW METADATA LOCK xxx_db.tb_name;Query metadata locks
Run SHOW METADATA LOCK to see which connections are blocking schema changes:
mysql> SHOW METADATA LOCK;Example output:
+---------+--------+-----------------+---------------------+--------------+------------------+-----------------+----------+-------------------------------------+-----------------------------------------------+
| CONN_ID | TRX_ID | TRACE_ID | SCHEMA | TABLE | TYPE | DURATION | VALIDATE | FRONTEND | SQL |
+---------+--------+-----------------+---------------------+--------------+------------------+-----------------+----------+-------------------------------------+-----------------------------------------------+
| 4 | 0 | f88cf71cbc00001 | XXXX_DRDS_LOCAL_APP | full_gsi_ddl | MDL_SHARED_WRITE | MDL_TRANSACTION | 1 | XXXX_DRDS_LOCAL_APP@127.0.0.1:54788 | insert into `full_gsi_ddl` (id) VALUE (null); |
| 5 | 0 | f88cf71cbc00000 | XXXX_DRDS_LOCAL_APP | full_gsi_ddl | MDL_SHARED_WRITE | MDL_TRANSACTION | 1 | XXXX_DRDS_LOCAL_APP@127.0.0.1:54789 | insert into `full_gsi_ddl` (id) VALUE (null); |
+---------+--------+-----------------+---------------------+--------------+------------------+-----------------+----------+-------------------------------------+-----------------------------------------------+
2 rows in set (0.00 sec)SHOW METADATA LOCK shows only connections that currently hold a metadata lock. It does not show connections waiting to acquire one.Output columns
| Column | Description |
|---|---|
CONN_ID | The ID of the connection holding the metadata lock. |
TRX_ID | The ID of the transaction holding the metadata lock. |
TRACE_ID | The trace ID of the SQL statement holding the metadata lock. |
SCHEMA | The database name. |
TABLE | The table name. |
TYPE | The type of the metadata lock that is held. |
DURATION | The period for which the metadata lock is held. |
VALIDATE | Indicates whether the metadata lock is released. |
FRONTEND | The frontend connection information, in the format user@host:port. |
SQL | The SQL statement currently holding the metadata lock. |