DML锁等待分析解决
DML锁等待分析解决
定位锁等待
- information_schema.innodb_lock_waits: 记录innodb引擎的DML事务产生的锁等待信息
Field | Type | Null | Key | Default | Remark |
---|---|---|---|---|---|
requesting_trx_id | varchar(18) | NO | 请求锁的事务ID | ||
requested_lock_id | varchar(81) | NO | 请求锁的锁ID | ||
blocking_trx_id | varchar(18) | NO | 当前拥有锁的事务ID | ||
blocking_lock_id | varchar(81) | NO | 当前拥有锁的锁ID |
select * from information schema.innodb_lock_waits;
- information_schema.innodb_locks: 记录innodb引擎中正在等待锁的所有相关进程
Field | Type | Null | Key | Default | Remark |
---|---|---|---|---|---|
lock_id | varchar(81) | NO | 锁ID | ||
lock_trx_id | varchar(18) | NO | 拥有锁的事务ID | ||
lock_mode | varchar(32) | NO | 锁模式 | ||
lock_type | varchar(32) | NO | 锁类型 | ||
lock_table | varchar(1024) | NO | 被锁的表 | ||
lock_index | varchar(1024) | YES | NULL | 被锁的索引 | |
lock_space | bigint(21) unsigned | YES | NULL | 被锁的表空间号 | |
lock_page | bigint(21) unsigned | YES | NULL | 柀锁的页号 | |
lock_rec | bigint(21) unsigned | YES | NULL | 被锁的记录号 | |
lock_data | varchar(8192) | YES | NULL | 被锁的数据 |
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(不推荐)
Field | Type | Null | Key | Default | Remark |
---|---|---|---|---|---|
trx_id | bigint unsigned | NO | 事务ID | ||
trx_state | varchar(13) | NO | 事务状态 | ||
trx_started | datetime | NO | 事务开始时间 | ||
trx_requested_lock_id | varchar(105) | YES | innodb_locks_lock_id | ||
trx_wait_started | datetime | YES | 事务开始等待时间 | ||
trx_weight | bigint unsigned | NO | # | ||
trx_mysql_thread_id | bigint unsigned | NO | 事务线程ID | ||
trx_query | varchar(1024) | YES | 具体SQL语句 | ||
trx_operation_state | varchar(64) | YES | 事务当前操作状态 | ||
trx_tables_in_use | bigint unsigned | NO | 事务中有多少表在使用 | ||
trx_tables_locked | bigint unsigned | NO | 事务拥有多少个锁 | ||
trx_lock_structs | bigint unsigned | NO | # | ||
trx_lock_memory_bytes | bigint unsigned | NO | 事务锁住的内存大小(B) | ||
trx_rows_locked | bigint unsigned | NO | 事务锁住的行数 | ||
trx_rows_modified | bigint unsigned | NO | 事务更改的行数 | ||
trx_concurrency_tickets | bigint unsigned | NO | 事务并发票数 | ||
trx_isolation_level | varchar(16) | NO | 事务隔离级别 | ||
trx_unique_checks | int | NO | 是否唯一性检查 | ||
trx_foreign_key_checks | int | NO | 是否外键检查 | ||
trx_last_foreign_key_error | varchar(256) | YES | 最后的外键错误 | ||
trx_adaptive_hash_latched | int | NO | 自适应哈希索引是否被当前事务阻塞 | ||
trx_adaptive_hash_timeout | bigint unsigned | NO | 是否为了自适应hash索引立即放弃查询锁 | ||
trx_is_read_only | int | NO | 只读事务标识 | ||
trx_autocommit_non_locking | int | NO | 无锁自动提交标识 | ||
trx_schedule_weight | bigint unsigned | YES | # |
定位线程
- 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