利用performance_schema進行故障診斷(mysql金字塔法則讀書筆記)
找出 OWNER_THREAD_ID為內部執行緒id,可以查詢threads表找出對應會話id:
select * from performance_schema.threads where THREAD_ID in (31,30)\G;
*************************** 1. row ***************************
OBJECT_TYPE: GLOBAL
OBJECT_SCHEMA: NULL
OBJECT_NAME: NULL
OBJECT_INSTANCE_BEGIN: 140514110025712
LOCK_TYPE: SHARED
LOCK_DURATION: EXPLICIT
LOCK_STATUS: GRANTED
SOURCE: lock.cc:1110
OWNER_THREAD_ID: 31 持有鎖的內部執行緒id為31
OWNER_EVENT_ID: 43
*************************** 2. row ***************************
OBJECT_TYPE: COMMIT
OBJECT_SCHEMA: NULL
OBJECT_NAME: NULL
OBJECT_INSTANCE_BEGIN: 140514110303360
LOCK_TYPE: SHARED
LOCK_DURATION: EXPLICIT
LOCK_STATUS: GRANTED
SOURCE: lock.cc:1194
OWNER_THREAD_ID: 31 持有鎖的內部執行緒id為31
OWNER_EVENT_ID: 97
*************************** 3. row ***************************
OBJECT_TYPE: GLOBAL
OBJECT_SCHEMA: NULL
OBJECT_NAME: NULL
OBJECT_INSTANCE_BEGIN: 140514110036384
LOCK_TYPE: INTENTION_EXCLUSIVE n意向排他鎖
LOCK_DURATION: STATEMENT
LOCK_STATUS: PENDING 狀態為pending,表示正在等待被授權
SOURCE: sql_base.cc:3190
OWNER_THREAD_ID: 30 被阻塞
OWNER_EVENT_ID: 2507
3 rows in set (0.04 sec)
找出誰持有MDL鎖:
select * from performance_schema.threads where THREAD_ID =30\G;
找出誰持有行級鎖:
mysql8
select * from performance_schema.data_locks\G;
mysql 5.7
select * from sys.innodb_lock_waits\G;
查詢最近的topsql語句:
select thread_id,event_name,source,sys.format_time(timer_wait),sys.format_time(lock_time),sql_text,current_schema,message_text,rows_affected,rows_sent,rows_examined from performance_schema.events_statements_history where current_schema!='performance_schema' order by timer_wait desc limit 10\G;
統計後sql:
select schema_name,digest_text,COUNT_STAR,sys.format_time(sum_timer_wait) as sum_time,sys.format_time(min_timer_wait) as min_time,
sys.format_time(avg_timer_wait) as avg_time,sys.format_time(max_timer_wait) as max_time,sys.format_time(sum_lock_time) as sum_lock_time,sum_rows_affected,sum_rows_sent,sum_rows_examined from performance_schema.events_statements_summary_by_digest where schema_name is not null order by count_star desc limit 10\G;
檢視最近執行失敗的sql語句:
select thread_id,event_name,source,sys.format_time(timer_wait) as exec_time, sys.format_time(lock_time) as lock_time,sql_text,current_schema,message_text,rows_affected,rows_sent,rows_examined ,mysql_errno from performance_schema.events_statements_history where mysql_errno=1064\G;
select thread_id,event_name,source,sys.format_time(timer_wait) as exec_time, sys.format_time(lock_time) as lock_time,sql_text,current_schema,message_text,rows_affected,rows_sent,rows_examined ,mysql_errno ,errors from performance_schema.events_statements_history where errors>0\G;
select schema_name,digest_text,
COUNT_STAR
,sys.format_time(sum_timer_wait) as sum_time,sys.format_time(min_timer_wait) as min_time,sys.format_time(avg_timer_wait) as avg_time,sys.format_time(max_timer_wait) as max_time,sys.format_time(sum_lock_time) as sum_lock_time,sum_errors,first_seen,last_seen from performance_schema.events_statements_summary_by_digest where sum_errors!=0\G;
檢視sql語句執行階段和進度資訊:
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29863023/viewspace-2665462/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 利用 Java dump 進行 JVM 故障診斷JavaJVM
- mysql讀書筆記MySql筆記
- mysql複製故障診斷與排除MySql
- 《決斷力》讀書筆記筆記
- Oracle故障診斷Oracle
- 利用errorstack事件進行錯誤跟蹤和診斷Error事件
- swift語法-讀書筆記Swift筆記
- 夢斷程式碼讀書筆記(一)筆記
- 《夢斷程式碼》讀書筆記(二)筆記
- 光纖故障診斷和故障排查
- mysql鎖機制 讀書筆記MySql筆記
- Mysql索引讀書筆記(待續)MySql索引筆記
- 《深入淺出MySQL》讀書筆記MySql筆記
- (原)庫存批量規則=讀書筆記筆記
- ASM磁碟故障診斷(二)ASM
- ASM磁碟故障診斷(一)ASM
- 故障診斷學習工具
- RAC故障診斷指令碼指令碼
- MySQL使用event等待事件進行資料庫效能診斷MySql事件資料庫
- 故障分析 | Kubernetes 故障診斷流程
- 【記錄】Linux 系統故障診斷與排除Linux
- MySQL故障診斷常用方法手冊(含指令碼、案例)MySql指令碼
- 《Mysql必知必會》讀書筆記MySql筆記
- 9 Oracle Data Guard 故障診斷Oracle
- DB2故障診斷工具DB2
- 讀書筆記...筆記
- 讀書筆記筆記
- 《讀書與做人》讀書筆記筆記
- 免費網站seo診斷:從哪些維度進行診斷呢?網站
- MySQL 讀書筆記 (一) 體系結構MySql筆記
- 讀書筆記:排序的執行器筆記排序
- 部落格連結—Oracle故障診斷Oracle
- 表驅動法 -《程式碼大全》讀書筆記筆記
- Cucumber讀書筆記筆記
- 散文讀書筆記筆記
- HTTP 讀書筆記HTTP筆記
- CoreJava讀書筆記-------Java筆記
- flask讀書筆記Flask筆記