1、performance_schema.metadata_locks 查看元数据锁
展示那些琐:
- 已授予的锁(显示哪些会话拥有哪个当前元数据锁)。
- 已请求但尚未授予的锁(显示哪些会话正在等待哪些元数据锁)。
- 死锁检测器已杀死的锁定请求。
- 超时并且正在等待请求会话的锁定请求被丢弃的锁定请求
开启和禁用:
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';
使用方式:
select * from performance_schema.metadata_locks
OBJECT_TYPE: TABLE 对象类型(GLOBAL, SCHEMA, TABLE, FUNCTION, PROCEDURE, TRIGGER (currently unused), EVENT, COMMIT, USER LEVEL LOCK, TABLESPACE, or LOCKING SERVICE.)
OBJECT_SCHEMA: test
OBJECT_NAME: resource 对象名称
COLUMN_NAME: NULL
OBJECT_INSTANCE_BEGIN: 140368591095200 锁开启时间
LOCK_TYPE: SHARED_READ_ONLY 锁类型(NTENTION_EXCLUSIVE, SHARED, SHARED_HIGH_PRIO, SHARED_READ, SHARED_WRITE, SHARED_UPGRADABLE, SHARED_NO_WRITE, SHARED_NO_READ_WRITE, or EXCLUSIVE)
LOCK_DURATION: TRANSACTION (STATEMENT, TRANSACTION, EXPLICIT)
LOCK_STATUS: GRANTED 锁状态(PENDING, GRANTED, VICTIM, TIMEOUT, KILLED, PRE_ACQUIRE_NOTIFY, or POST_RELEASE_NOTIFY)
SOURCE: sql_parse.cc:6014 源代码和行
OWNER_THREAD_ID: 53
OWNER_EVENT_ID: 235
重点说一下LOCK_TYPE和LOCK_STATUS
LOCK_TYPE | 备注 |
---|---|
INTENTION_EXCLUSIVE | |
SHARED | |
SHARED_HIGH_PRIO | |
SHARED_READ | |
SHARED_WRITE | |
SHARED_UPGRADABLE | |
SHARED_NO_WRITE | |
SHARED_NO_READ_WRITE | |
EXCLUSIVE |
LOCK_STATUS | 是否瞬时状态 | 备注 |
---|---|---|
PENDING | 否 | 请求锁但没有获得锁定 |
GRANTED | 否 | 请求且已获得锁定 |
VICTIM | 是 | 当死锁检测器取消挂起的锁定请求以打破死锁(ER_LOCK_DEADLOCK )时,其行状态从更新PENDING 为VICTIM |
TIMEOUT | 是 | 超时 |
KILLED | 是 | 被kill调 |
PRE_ACQUIRE_NOTIFY | 是 | 表示该元数据锁定subsubsystem的通知感兴趣的存储引擎,而进入锁定获取操作或离开锁释放操作 |
POST_RELEASE_NOTIFY | 是 |
2、performance_schema.data_locks 查看行锁和表锁