一个 INFORMATION_SCHEMA 表和两个 Performance Schema 表让您能够监控 InnoDB 事务并诊断潜在的锁问题:One INFORMATION_SCHEMA table and two
Performance Schema tables enable you to monitor
InnoDB transactions and diagnose potential
locking problems:
INNODB_TRX:此INFORMATION_SCHEMA表提供有关当前正在InnoDB内执行的每个事务的信息,包括事务状态(例如,它是运行中还是在等待锁)、事务开始时间以及事务正在执行的特定 SQL 语句。INNODB_TRX: ThisINFORMATION_SCHEMAtable provides information about every transaction currently executing insideInnoDB, including the transaction state (for example, whether it is running or waiting for a lock), when the transaction started, and the particular SQL statement the transaction is executing.data_locks:此 Performance Schema 表包含每个持有锁和每个因等待已持有的锁而被阻塞的锁请求的行:data_locks: This Performance Schema table contains a row for each hold lock and each lock request that is blocked waiting for a held lock to be released:对于每个已持有的锁都有一行,无论持有锁的事务状态如何(
INNODB_TRX.TRX_STATE是RUNNING、LOCK WAIT、ROLLING BACK或COMMITTING)。There is one row for each held lock, whatever the state of the transaction that holds the lock (INNODB_TRX.TRX_STATEisRUNNING,LOCK WAIT,ROLLING BACKorCOMMITTING).每个在 InnoDB 中等待其他事务释放锁的事务(
INNODB_TRX.TRX_STATE为LOCK WAIT)都被一个阻塞锁请求阻止。该阻塞锁请求是针对另一个事务以不兼容模式持有的行或表锁。锁请求始终具有与持有锁阻止该请求的模式不兼容的模式(读与写,共享与独占)。Each transaction in InnoDB that is waiting for another transaction to release a lock (INNODB_TRX.TRX_STATEisLOCK WAIT) is blocked by exactly one blocking lock request. That blocking lock request is for a row or table lock held by another transaction in an incompatible mode. A lock request always has a mode that is incompatible with the mode of the held lock that blocks the request (read vs. write, shared vs. exclusive).被阻止的事务无法继续,直到另一个事务提交或回滚,从而释放所请求的锁。对于每个被阻止的事务,
data_locks包含一行,描述事务所请求并正在等待的每个锁。The blocked transaction cannot proceed until the other transaction commits or rolls back, thereby releasing the requested lock. For every blocked transaction,data_lockscontains one row that describes each lock the transaction has requested, and for which it is waiting.
data_lock_waits:此 Performance Schema 表显示哪些事务正在等待某个锁,或者某个事务正在等待哪个锁。对于每个被阻塞的事务,此表包含一行或多行,显示其请求的锁以及阻塞该请求的任何锁。REQUESTING_ENGINE_LOCK_ID值指的是事务请求的锁,而BLOCKING_ENGINE_LOCK_ID值指的是阻止该事务继续进行的锁(由另一个事务持有)。对于任何给定的被阻塞事务,data_lock_waits中的所有行REQUESTING_ENGINE_LOCK_ID值相同,而BLOCKING_ENGINE_LOCK_ID值则不同。data_lock_waits: This Performance Schema table indicates which transactions are waiting for a given lock, or for which lock a given transaction is waiting. This table contains one or more rows for each blocked transaction, indicating the lock it has requested and any locks that are blocking that request. TheREQUESTING_ENGINE_LOCK_IDvalue refers to the lock requested by a transaction, and theBLOCKING_ENGINE_LOCK_IDvalue refers to the lock (held by another transaction) that prevents the first transaction from proceeding. For any given blocked transaction, all rows indata_lock_waitshave the same value forREQUESTING_ENGINE_LOCK_IDand different values forBLOCKING_ENGINE_LOCK_ID.
有关前述表的更多信息,请参见 第 28.4.28 节,“INFORMATION_SCHEMA INNODB_TRX 表”、第 29.12.13.1 节,“data_locks 表” 和 第 29.12.13.2 节,“data_lock_waits 表”。For more information about the preceding tables, see Section 28.4.28, “The INFORMATION_SCHEMA INNODB_TRX Table”, Section 29.12.13.1, “The data_locks Table”, and Section 29.12.13.2, “The data_lock_waits Table”.