MySQL5.7 InnoDB Standard Monitor and Lock Monitor Output

導讀:如下輸出信息爲MySQL5.7 InnoDB Standard Monitor and Lock Monitor Output,只是一點我的簡單理解。若有不對之處,歡迎拍磚html

 

 

官方介紹:node

The Lock Monitor is the same as the Standard Monitor except that it includes additional lock information. Enabling either monitor for periodic output turns on the same output stream, but the stream includes extra information if the Lock Monitor is enabled. For example, if you enable the Standard Monitor and Lock Monitor, that turns on a single output stream. The stream includes extra lock information until you disable the Lock Monitor.mysql

Standard Monitor output is limited to 1MB when produced using the SHOW ENGINE INNODB STATUS statement. This limit does not apply to output written to the server's error output.sql

Example Standard Monitor output:數據庫

 

root@localhost [(none)]>show engine innodb status\G

*************************** 1. row ***************************

【第一部分:聲明輸出信息】

  Type: InnoDB

  Name:

Status:

=====================================

##顯示的是當前時間

2016-12-26 10:41:12 0x7fde953c9700 INNODB MONITOR OUTPUT

=====================================

##距上次復位時常

Per second averages calculated from the last 1 seconds  

-----------------

【第二部分:從innodb1.0.x開始,能夠查看master thread的狀態信息】

##backgroup 線程

BACKGROUND THREAD

-----------------

srv_master_thread loops: 12032 srv_active, 0 srv_shutdown, 10080118 srv_idle

srv_master_thread log flush and writes: 10092150

----------

【第三部分:若是有性能上的瓶頸,能夠使用這些信息來找出瓶頸】

SEMAPHORES

----------

OS WAIT ARRAY INFO: reservation count 604456

OS WAIT ARRAY INFO: signal count 553707

RW-shared spins 0, rounds 1054096, OS waits 501522

RW-excl spins 0, rounds 1391796, OS waits 36382

RW-sx spins 13501, rounds 242119, OS waits 2963

Spin rounds per wait: 1054096.00 RW-shared, 1391796.00 RW-excl, 17.93 RW-sx

------------------------

【第四部分:下面這種錯誤,通常不會發生,除非服務器上有外鍵錯誤。如下信息的輸出對於查找外鍵錯誤很是有幫助】

LATEST FOREIGN KEY ERROR

------------------------

2014-10-16 18:35:18 0x7fc2a95c1700 Transaction:

TRANSACTION 1814, ACTIVE 0 sec inserting

mysql tables in use 1, locked 1

4 lock struct(s), heap size 1136, 3 row lock(s), undo log entries 3

MySQL thread id 2, OS thread handle 140474041767680, query id 74 localhost

root update

INSERT INTO child VALUES

    (NULL, 1)

    , (NULL, 2)

    , (NULL, 3)

    , (NULL, 4)

    , (NULL, 5)

    , (NULL, 6)

Foreign key constraint fails for table `mysql`.`child`:

##下面部分顯示發生錯誤時,innodb正嘗試修改的準確數據

  CONSTRAINT `child_ibfk_1` FOREIGN KEY (`parent_id`) REFERENCES `parent`

  (`id`) ON DELETE CASCADE ON UPDATE CASCADE

Trying to add in child table, in index par_ind tuple:

DATA TUPLE: 2 fields;

 0: len 4; hex 80000003; asc     ;;

 1: len 4; hex 80000003; asc     ;;



But in parent table `mysql`.`parent`, in index PRIMARY,

the closest match we can find is record:

PHYSICAL RECORD: n_fields 3; compact format; info bits 0

 0: len 4; hex 80000004; asc     ;;

 1: len 6; hex 00000000070a; asc       ;;

 2: len 7; hex aa0000011d0134; asc       4;;



------------------------

【第五部分:死鎖】

LATEST DETECTED DEADLOCK

------------------------

2014-10-16 18:36:30 0x7fc2a95c1700

*** (1) TRANSACTION:

TRANSACTION 1824, ACTIVE 9 sec starting index read

mysql tables in use 1, locked 1

LOCK WAIT 2 lock struct(s), heap size 1136, 1 row lock(s)

MySQL thread id 3, OS thread handle 140474041501440, query id 80 localhost

root updating

##這個事務涉及的SQL

DELETE FROM t WHERE i = 1

##下面顯示當死鎖發生時,第一個事務正在等待的鎖信息。下面這行表示第一個事務正在等待鎖被授予

*** (1) WAITING FOR THIS LOCK TO BE GRANTED:

RECORD LOCKS space id 35 page no 3 n bits 72 index GEN_CLUST_INDEX of table

`mysql`.`t` trx id 1824 lock_mode X waiting

##顯示record lock的heap no的位置

Record lock, heap no 2 PHYSICAL RECORD: n_fields 4; compact format; info

bits 0

 0: len 6; hex 000000000200; asc       ;;

 1: len 6; hex 00000000071f; asc       ;;

 2: len 7; hex b80000012b0110; asc     +  ;;

 3: len 4; hex 80000001; asc     ;;



*** (2) TRANSACTION:

TRANSACTION 1825, ACTIVE 29 sec starting index read

mysql tables in use 1, locked 1

4 lock struct(s), heap size 1136, 3 row lock(s)

MySQL thread id 2, OS thread handle 140474041767680, query id 81 localhost

root updating

DELETE FROM t WHERE i = 1

##這顯示的是事務2持有的鎖信息,從下面兩行來看,這個鎖就是事務1等待的鎖

*** (2) HOLDS THE LOCK(S):

RECORD LOCKS space id 35 page no 3 n bits 72 index GEN_CLUST_INDEX of table

`mysql`.`t` trx id 1825 lock mode S

Record lock, heap no 1 PHYSICAL RECORD: n_fields 1; compact format; info

bits 0

 0: len 8; hex 73757072656d756d; asc supremum;;



Record lock, heap no 2 PHYSICAL RECORD: n_fields 4; compact format; info bits 0

 0: len 6; hex 000000000200; asc       ;;

 1: len 6; hex 00000000071f; asc       ;;

 2: len 7; hex b80000012b0110; asc     +  ;;

 3: len 4; hex 80000001; asc     ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:

RECORD LOCKS space id 35 page no 3 n bits 72 index GEN_CLUST_INDEX of table

`mysql`.`t` trx id 1825 lock_mode X waiting

Record lock, heap no 2 PHYSICAL RECORD: n_fields 4; compact format; info

bits 0

 0: len 6; hex 000000000200; asc       ;;

 1: len 6; hex 00000000071f; asc       ;;

 2: len 7; hex b80000012b0110; asc     +  ;;

 3: len 4; hex 80000001; asc     ;;

*** WE ROLL BACK TRANSACTION (1)

------------

【第六部分:innodb的事務信息】

TRANSACTIONS

------------

Trx id counter 1950

##前面這個是innodb清除MVCC所用的事務ID,將這個值和當前事務ID進行比較,就能夠知道有多少老版本的數據未被清除。這個數字多大才能夠安全的取值沒有硬性和速成的規定,若是數據沒作過任何更新,那麼一個巨大的數字也不意味着有未清除的數據,由於實際上全部事務在數據庫裏查看的都是同一個版本的數據(此時只是事務ID在增長,而數據沒有變動),另外一方面,若是有不少行被更新,那每一行就會有一個或多個版本留在內存裏,減小此類開銷的最好辦法就是確保事務已完成就當即提交,不要讓它長時間地處於打開狀態,由於一個打開的事務即便不作任何操做,也會影響到innodb清理舊版本的行數據。

Purge done for trx's n:o < 1933 undo n:o < 0 state: running but idle

##歷史記錄的長度,即位於innodb數據文件的撤銷空間裏的頁面的數目,若是事務執行了更新並提交,這個數字就會增長,而當清理進程移除舊版本數據時,它就會減小,清理進程也會更新Purge done for.....這行中的數值。

History list length 23

##事務列表

LIST OF TRANSACTIONS FOR EACH SESSION:

---TRANSACTION 421949033065200, not started

0 lock struct(s), heap size 1136, 0 row lock(s)

---TRANSACTION 421949033064280, not started

0 lock struct(s), heap size 1136, 0 row lock(s)

---TRANSACTION 1949, ACTIVE 0 sec inserting

mysql tables in use 1, locked 1

##該事務用到的表數和涉及表鎖的表數,Innodb通常不會鎖定表,但對有些語句會鎖定,若是mysql服務器在高於innodb層之上將表鎖定,這裏也是可以顯示出來的,若是事務已經鎖定了幾行數據,這裏將會有一行信息顯示出鎖定結構的數目

8 lock struct(s), heap size 1136, 1850 row lock(s), undo log entries 17415

##下面這行顯示事務線程信息,MySQL thread id <數字>部分和用show full processlist;命令看到的id列相同。緊隨其後的是一個內部查詢id和一些鏈接信息,這些信息一樣與show full processlist中的輸出相同。

MySQL thread id 4, OS thread handle 140474041235200, query id 176 localhost

root update

##下面顯示的是事務的完整語句

INSERT INTO `salaries` VALUES (55723,39746,'1997-02-25','1998-02-25'),

(55723,40758,'1998-02-25','1999-02-25'),(55723,44559,'1999-02-25','2000-02-25'),

(55723,44081,'2000-02-25','2001-02-24'),(55723,44112,'2001-02-24','2001-08-16'),

(55724,46461,'1996-12-06','1997-12-06'),(55724,48916,'1997-12-06','1998-12-06'),

(55724,51269,'1998-12-06','1999-12-06'),(55724,51932,'1999-12-06','2000-12-05'),

(55724,52617,'2000-12-05','2001-12-05'),(55724,56658,'2001-12-05','9999-01-01'),

(55725,40000,'1993-01-30','1994-01-30'),(55725,41472,'1994-01-30','1995-01-30'),

(55725,45293,'1995-01-30','1996-01-30'),(55725,473

--------

【第七部分:下面顯示的是I/O輔助線程的狀態,還有性能計數器的狀態】

FILE I/O

--------

## #insert buffer thread

I/O thread 0 state: waiting for completed aio requests (insert buffer thread)

## log thread

I/O thread 1 state: waiting for completed aio requests (log thread)

##如下爲默認的4個read thread

I/O thread 2 state: waiting for completed aio requests (read thread)

I/O thread 3 state: waiting for completed aio requests (read thread)

I/O thread 4 state: waiting for completed aio requests (read thread)

I/O thread 5 state: waiting for completed aio requests (read thread)

##如下爲默認的4個write thread

I/O thread 6 state: waiting for completed aio requests (write thread)

I/O thread 7 state: waiting for completed aio requests (write thread)

I/O thread 8 state: waiting for completed aio requests (write thread)

I/O thread 9 state: waiting for completed aio requests (write thread)

##讀線程和寫線程掛起操做的數目等,aio的意思是異步I/O

Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,

##insert buffer thread掛起的fsync()操做數目等

ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0

## log thread掛起的fsync()操做數目等

Pending flushes (fsync) log: 0; buffer pool: 0

##這行顯示了讀,寫和fsync()調用執行的數目,在你的機器環境負載下這些絕對值可能會有所不一樣,所以更重要的是監控它們過去一段時間內是如何改變的。

224 OS file reads, 5770 OS file writes, 803 OS fsyncs

0.00 reads/s, 0 avg bytes/read, 264.84 writes/s, 23.05 fsyncs/s

-------------------------------------

【第八部分:這部分顯示了insert buffer和adaptive hash index兩個部分的結構的狀態】

INSERT BUFFER AND ADAPTIVE HASH INDEX

-------------------------------------

Ibuf: size 1, free list len 0, seg size 2, 0 merges

merged operations:

 insert 0, delete mark 0, delete 0

discarded operations:

 insert 0, delete mark 0, delete 0

Hash table size 4425293, node heap has 444 buffer(s)

68015.25 hash searches/s, 106259.24 non-hash searches/s

---

【第九部分:這部分顯示innodb事務日誌子系統的統計】

LOG

---

Log sequence number 165913808

Log flushed up to   164814979

Pages flushed up to 141544038

Last checkpoint at  130503656

##這行顯示了當前掛起的日誌讀寫操做,能夠將這行的值與第7部分FILE I/O對應的值作比較,以瞭解你的I/O有多少是因爲日誌系統引發的。

0 pending log flushes, 0 pending chkp writes

##這行顯示了日誌操做的統計和每秒日誌I/O數

258 log i/o's done, 6.65 log i/o's/second

----------------------

【第九部分:這部分顯示了關於innodb緩衝池及其如何使用內存的統計】

BUFFER POOL AND MEMORY

----------------------

##這兩行顯示了由innodb分配的總內存,以及字典分配內存

Total large memory allocated 2198863872

Dictionary memory allocated 776332

##從這行開始的下面4行顯示緩衝池度量值,以頁爲單位,度量值有總的緩衝池大小,空閒頁數,分配用來存儲數據庫頁的頁數,以及髒數據庫頁數。

Buffer pool size   131072

##這行顯示緩衝池空閒頁數

Free buffers       124908

##這行顯示了分配用來存儲數據庫頁的頁數,即,表示LRU列表中頁的數量,包含young sublist和old sublist

Database pages     5720

##這行顯示了LRU中的old sublist部分頁的數量

Old database pages 2071

Modified db pages  910

##這行顯示了掛起讀的數量

Pending reads 0

Pending writes: LRU 0, flush list 0, single page 0

##這行顯示了LRU列表中頁移動到LRU首部的次數,由於該服務器在運行階段改變沒有達到innodb_old_blocks_time閥值的值,所以not young爲0

Pages made young 4, not young 0

##表示每秒young和non-youngs這兩類操做的次數

0.10 youngs/s, 0.00 non-youngs/s

Pages read 197, created 5523, written 5060

##這行顯示了對應上面一行的每秒read,create,write的頁數

0.00 reads/s, 190.89 creates/s, 244.94 writes/s

Buffer pool hit rate 1000 / 1000, young-making rate 0 / 1000 not 0 / 1000

##這行顯示了頁面預讀,隨機預讀的每秒頁數

Pages read ahead 0.00/s, evicted without access 0.00/s, Random read

ahead 0.00/s

##innodb1.0.x開始支持壓縮頁的功能,將原來16K的頁壓縮爲1K,2K,4K,8K,而因爲頁的大小發生了變化,LRU列表也有了些改變,對於非16K的頁,是經過unzip_LRU列表進行管理的,能夠看到unzip_LRU len爲0表示沒有使用壓縮頁.

LRU len: 5720, unzip_LRU len: 0
I/O sum[0]:cur[0], unzip sum[0]:cur[0]
----------------------

【第十部分:.若是innodb buffer pool使用參數innodb_buffer_pool_instances=num設置了大於1個緩衝池實例,那麼就會按照這個參數把innodb_buffer_pool_size=xxx平分爲num份。每份的信息顯示相似以下】

INDIVIDUAL BUFFER POOL INFO

----------------------

---BUFFER POOL 0

Buffer pool size   65536

Free buffers       62412

Database pages     2899

Old database pages 1050

Modified db pages  449

Pending reads 0

Pending writes: LRU 0, flush list 0, single page 0

Pages made young 3, not young 0

0.05 youngs/s, 0.00 non-youngs/s

Pages read 107, created 2792, written 2586

0.00 reads/s, 92.65 creates/s, 122.89 writes/s

Buffer pool hit rate 1000 / 1000, young-making rate 0 / 1000 not 0 / 1000

Pages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead

0.00/s

LRU len: 2899, unzip_LRU len: 0

I/O sum[0]:cur[0], unzip sum[0]:cur[0]

---BUFFER POOL 1

Buffer pool size   65536

Free buffers       62496

Database pages     2821

Old database pages 1021

Modified db pages  461

Pending reads 0

Pending writes: LRU 0, flush list 0, single page 0

Pages made young 1, not young 0

0.05 youngs/s, 0.00 non-youngs/s

Pages read 90, created 2731, written 2474

0.00 reads/s, 98.25 creates/s, 122.04 writes/s

Buffer pool hit rate 1000 / 1000, young-making rate 0 / 1000 not 0 / 1000

Pages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead

0.00/s

LRU len: 2821, unzip_LRU len: 0

I/O sum[0]:cur[0], unzip sum[0]:cur[0]

--------------

【第十一部分:這部分顯示了innodb其餘信息】

ROW OPERATIONS

--------------

0 queries inside InnoDB, 0 queries in queue

##這行顯示了有多少打開的innodb讀視圖,讀視圖是包含事務開始點的數據庫內容的MVCC快照,你能夠看看某特定事務在第6部分TRANSACTIONS是否有讀視圖

0 read views open inside InnoDB

##這行顯示了內核的主線程狀態

Process ID=35909, Main thread ID=140471692396288, state: sleeping

##這行顯示了多少行被插入,更新和刪除,讀取

Number of rows inserted 1526363, updated 0, deleted 3, read 11

##這行顯示了對應上面一行的每秒平均值,若是想查看innodb有多少工做量在進行,那麼這兩行是很好的參考值

52671.72 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s

----------------------------

##要注意了,若是看不到這行輸出,多是有大量事務或者是有一個大的死鎖截斷了輸出信息

END OF INNODB MONITOR OUTPUT

============================

爲了方便你們交流,本人開通了微信公衆號,和QQ羣291519319。喜歡技術的一塊兒來交流吧安全

相關文章
相關標籤/搜索