利用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/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 利用errorstack事件進行錯誤跟蹤和診斷Error事件
- 故障分析 | Kubernetes 故障診斷流程
- swift語法-讀書筆記Swift筆記
- 光纖故障診斷和故障排查
- 《夢斷程式碼》讀書筆記(二)筆記
- 夢斷程式碼讀書筆記(一)筆記
- Mysql索引讀書筆記(待續)MySql索引筆記
- mysql鎖機制 讀書筆記MySql筆記
- MySQL故障診斷常用方法手冊(含指令碼、案例)MySql指令碼
- MySQL使用event等待事件進行資料庫效能診斷MySql事件資料庫
- 9 Oracle Data Guard 故障診斷Oracle
- 《Mysql必知必會》讀書筆記MySql筆記
- 免費網站seo診斷:從哪些維度進行診斷呢?網站
- MySQL 讀書筆記 (一) 體系結構MySql筆記
- 讀書筆記筆記
- 《讀書與做人》讀書筆記筆記
- 用10046進行診斷一例
- MySQL 8.0 Reference Manual(讀書筆記68節--Deadlocks)MySql筆記
- MySQL 8.0 Reference Manual(讀書筆記90節--Replication)MySql筆記
- 一次SGA與Swap故障診斷
- webpackDemo讀書筆記Web筆記
- Vue讀書筆記Vue筆記
- 散文讀書筆記筆記
- Cucumber讀書筆記筆記
- HTTP 讀書筆記HTTP筆記
- postgres 讀書筆記筆記
- 讀書筆記2筆記
- 讀書筆記3筆記
- [swift進階]的讀書筆記寫完啦~Swift筆記
- 軟體開發的22條法則 ——《程式設計師修煉之道》讀書筆記程式設計師筆記
- 產品讀書《金字塔原理》
- Adaptive AUTOSAR 學習筆記 14 - 車輛診斷APT筆記
- MySQL 8.0 Reference Manual(讀書筆記63節--InnoDB Locking)MySql筆記
- MySQL 8.0 Reference Manual(讀書筆記64節--InnoDBTransaction Model)MySql筆記
- MySQL 8.0 Reference Manual(讀書筆記65節--InnoDBLocks Set)MySql筆記BloC
- MySQL 8.0 Reference Manual(讀書筆記45節--Optimization Overview)MySql筆記View
- MySQL 8.0 Reference Manual(讀書筆記94節--Replication(5))MySql筆記
- MySQL 8.0 Reference Manual(讀書筆記93節--Semisynchronous Replication)MySql筆記