文章

DML锁等待分析解决

DML锁等待分析解决

定位锁等待

  • information_schema.innodb_lock_waits: 记录innodb引擎的DML事务产生的锁等待信息
FieldTypeNullKeyDefaultRemark
requesting_trx_idvarchar(18)NO请求锁的事务ID
requested_lock_idvarchar(81)NO请求锁的锁ID
blocking_trx_idvarchar(18)NO当前拥有锁的事务ID
blocking_lock_idvarchar(81)NO当前拥有锁的锁ID

select * from information schema.innodb_lock_waits;

  • information_schema.innodb_locks: 记录innodb引擎中正在等待锁的所有相关进程
FieldTypeNullKeyDefaultRemark
lock_idvarchar(81)NO锁ID
lock_trx_idvarchar(18)NO拥有锁的事务ID
lock_modevarchar(32)NO锁模式
lock_typevarchar(32)NO锁类型
lock_tablevarchar(1024)NO被锁的表
lock_indexvarchar(1024)YESNULL被锁的索引
lock_spacebigint(21) unsignedYESNULL被锁的表空间号
lock_pagebigint(21) unsignedYESNULL柀锁的页号
lock_recbigint(21) unsignedYESNULL被锁的记录号
lock_datavarchar(8192)YESNULL被锁的数据

select * from information schema.innodb_locks;

  • information_schema.innodb_trx: 记录innodb引擎的事务信息 select trx_id,trx_started,trx_requested_lock_id,trx_query,trx_mysql_thread_id from information_schema.innodb_trx; 可以直接kill对应的trx_mysql_thread_id(不推荐)
FieldTypeNullKeyDefaultRemark
trx_idbigint unsignedNO事务ID
trx_statevarchar(13)NO事务状态
trx_starteddatetimeNO事务开始时间
trx_requested_lock_idvarchar(105)YESinnodb_locks_lock_id
trx_wait_starteddatetimeYES事务开始等待时间
trx_weightbigint unsignedNO#
trx_mysql_thread_idbigint unsignedNO事务线程ID
trx_queryvarchar(1024)YES具体SQL语句
trx_operation_statevarchar(64)YES事务当前操作状态
trx_tables_in_usebigint unsignedNO事务中有多少表在使用
trx_tables_lockedbigint unsignedNO事务拥有多少个锁
trx_lock_structsbigint unsignedNO#
trx_lock_memory_bytesbigint unsignedNO事务锁住的内存大小(B)
trx_rows_lockedbigint unsignedNO事务锁住的行数
trx_rows_modifiedbigint unsignedNO事务更改的行数
trx_concurrency_ticketsbigint unsignedNO事务并发票数
trx_isolation_levelvarchar(16)NO事务隔离级别
trx_unique_checksintNO是否唯一性检查
trx_foreign_key_checksintNO是否外键检查
trx_last_foreign_key_errorvarchar(256)YES最后的外键错误
trx_adaptive_hash_latchedintNO自适应哈希索引是否被当前事务阻塞
trx_adaptive_hash_timeoutbigint unsignedNO是否为了自适应hash索引立即放弃查询锁
trx_is_read_onlyintNO只读事务标识
trx_autocommit_non_lockingintNO无锁自动提交标识
trx_schedule_weightbigint unsignedYES#

定位线程

  • performance_schema.threads:记录线程信息表 select * from performance_schema.threads where processlist_id=38;

定位加锁SQL

  • performance_schema.events_statements_current:记录当前SOL语句以及线程事件 select * from performance_schema.events_statements_current where thread_id=63;

performance_schema.data_locks

当前存在的表锁

performance_schema.metadata_locks

元数据锁

information_schema.innodb_trx

一般事务信息和锁状态

performance_schema.data_lock_await

被阻塞的事务和阻塞它的事务

License:  CC BY 4.0