A quest for the full InnoDB status

When running InnoDB you are able to dig into the engine internals, look at
various gauges and counters, see past deadlocks and the list of all open
transactions. This is in your reach with one simple command -


SHOW ENGINE INNODB STATUS

. On most occasions it works beautifully. The problems appear when you have a
large spike in number of connections to MySQL, which often happens when several
transactions kill the database performance resulting in very long execution
times for even simplest queries, or a huge deadlock.

In such rare cases


SHOW ENGINE INNODB STATUS

often fails to provide the necessary information. The reason is that its
output is limited to 64000 bytes, so a long list of transactions or a large
deadlock dump may easily exhaust the limit. MySQL in such situation truncates
the output so it fits the required size and obviously this is not good since you
may lose some valuable information from your sight.

With large deadlocks you can actually deal by
intentionally creating a new tiny deadlock which will replace the previous one
in the output thus reducing the space occupied by that section of InnoDB
status. Baron once wrote an article on how to do this.

There is not such easy way for the long transaction list, but fortunately
there are some alternatives to the limited MySQL command output.

First one is that you can have
innodb-status-file option set in your my.cnf. This will
make InnoDB to write the full status output into


innodb_status.<PID>

file located in MySQL data directory. Unfortunately this is a startup time
parameter, so unless you set it early, it will not be available in an emergency
situation.

Other possibility is to create a special InnoDB table called
innodb_monitor


CREATE TABLE innodb_monitor(a INT) ENGINE=innodb;

Creating it causes the full status to be
periodically printed into MySQL error log. You can later disable logging by
simply dropping the table. The problem I faced many times is that people do not
configure their error log at all, so the messages disappear into nothingness. So
what then?

I discovered that InnoDB will still create the status file on disk even if
you do not specify innodb-status-file option. The file is actually used for
every


SHOW ENGINE INNODB STATUS

call, so whenever someone runs the command,
InnoDB writes the output to that file first and then the stored information is
read back to user. To make things more difficult, MySQL keeps the file deleted,
so it is not possible access it with a simple catfilename or any other command through the file system. However
on many systems such as Linux or Solaris, but possibly also others, there is a
relatively simple way to access deleted but not-yet-closed files (file is
physically removed only after it is no longer open by any process).

First be sure to run


SHOW ENGINE INNODB STATUS

at least once. Then see what MySQL process ID is:


garfield ~ # ps ax | grep [m]ysqld
11886 ? Ssl 0:01 /usr/sbin/mysqld --defaults-file=/etc/mysql/my.cnf

In my case the process ID is 11886, so I will
be using it in the examples, but you should of course use whatever
PS returned to you.

Now you can use /proc to see all the file descriptors that are being
kept open by the process. So go to /proc/<PID> and list all the files
that were deleted.


garfield ~ # cd /proc/11886/fd
garfield fd # ls -l | grep deleted
lrwx------ 1 root root 64 Oct 31 18:26 12 -> /tmp/iblnLBhO (deleted)
lrwx------ 1 root root 64 Oct 31 18:26 5 -> /tmp/ibuQBSgo (deleted)
lrwx------ 1 root root 64 Oct 31 18:26 6 -> /tmp/ibLVtBuZ (deleted)
lrwx------ 1 root root 64 Oct 31 18:26 7 -> /tmp/ibsMzkIA (deleted)
lrwx------ 1 root root 64 Oct 31 18:26 8 -> /tmp/ibj08Rkc (deleted)

The entries are presented as symbolic links from file descriptor number to a
real path as in


12 -> /tmp/iblnLBhO

One of these entries is what you are looking
for, it’s often (always?) the file with the lowest file descriptor number, so in
my case it should be 5. But of course you can try reading a few first bytes
from every such file to discover where InnoDB status is. You can also help
yourself with lsof

tool available for many platforms:


garfield fd # lsof -c mysqld | grep deleted
mysqld 11886 mysql 5u REG 253,10 130932 12 /tmp/ibuQBSgo (deleted)
mysqld 11886 mysql 6u REG 253,10 0 13 /tmp/ibLVtBuZ (deleted)
mysqld 11886 mysql 7u REG 253,10 0 14 /tmp/ibsMzkIA (deleted)
mysqld 11886 mysql 8u REG 253,10 0 15 /tmp/ibj08Rkc (deleted)
mysqld 11886 mysql 12u REG 253,10 0 16 /tmp/iblnLBhO (deleted)

The 4th column contains file descriptor
numbers and in the 7th column there are the file sizes. This makes it obvious
that InnoDB status has to be under file descriptor 5 since it’s the only
non-zero length file.

So while you are still in /proc/<PID> directory, you can try
looking into that file:


garfield fd # cat 5
=====================================
081031 17:57:08 INNODB MONITOR OUTPUT
=====================================
Per second averages calculated from the last 33 seconds
----------
SEMAPHORES
----------
... snip ...

Keep in mind the file will only be refreshed when you run


SHOW ENGINE INNODB STATUS

command.

参考:http://www.mysqlperformanceblog.com/2008/10/31/full-innodb-status/

A quest for the full InnoDB status,码迷,mamicode.com

时间: 2024-10-02 11:48:56

A quest for the full InnoDB status的相关文章

mysql之show engine innodb status解读(转)

add by zhj: 我第一次知道这个命令是线上服务出了问题,然后同事用这个命令去查看死锁.但用这个命令看死锁有一定的局限性,它只能看到最后一次死锁, 而且只能看到死锁环中的两个事务所执行的最后一条语句(即被死锁卡住的那条语句),看不到整个死锁环,也看到不整个事务的语句.但是即使这亲,对我 们来说也非常有用,因为一般来说,数据库同时存在多个死锁环的可能性比较小,而且有了死锁环中的事务的最后一条语句,我们找到整个死锁环不是太难. "show engine innodb status"这

mysql-5.7 show engine innodb status 详解

一.show engine innodb status 简介: show engine innodb status 是mysql提供的一个用于查看innodb引擎时间信息的工具,就目前来说有两处比较 常用的地方一.死锁分析 二.innodb内存使用情况 二.通过show engine innodb status 查看内存使用情况: ---------------------- BUFFER POOL AND MEMORY ---------------------- Total large me

show engine innodb status\G

mysql> show engine innodb status\G *************************** 1. row ***************************  Type: InnoDB  Name: Status: =====================================131226 17:12:38 INNODB MONITOR OUTPUT=====================================Per second a

show engine innodb status

TRANSACTIONS------------Trx id counter 2003909(当前事务号)Purge done for trx's n:o < 2003905 (清理线程完成到了哪个点)undo n:o < 0 state: running but idle 如果上述两个差距很大,可能有大量的没有清理的事务. show engine innodb status,布布扣,bubuko.com

mysql之show engine innodb status解读

注:以下内容为根据<高性能mysql第三版>和<mysql技术内幕innodb存储引擎>的innodb status部分的个人理解,如果有错误,还望指正!! innodb存储引擎在show engine innodb status(老版本对应的是show innodb status)输出中,显示除了大量的内部信息,它输出就是一个单独的字符串,没有行和列,内容分为很多小段,每一段对应innodb存储引擎不同部分的信息,其中有一些信息对于innodb开发者来说非常有用,但是,许多信息,

Using SHOW PROCESSLIST and mysqladmin debug Output in Conjunction with SHOW INNODB STATUS

When InnoDB appears hung, I know the natural reaction is to check SHOW ENGINE INNODB STATUS. In fact, it’s the first thing I check when InnoDB tables are involved. However, I just want to iterate how valuable SHOW FULL PROCESSLIST and/or mysqladmin d

(Sqlyog或Navicat不友好处)SHOW ENGINE INNODB STATUS 结果为空或结果为=====================================

因为最近在学习innodb引擎,所以就在自己的sqlyog上执行上述命令: SHOW ENGINE INNODB STATUS 结果显示如下: 换了个客户端navicat,执行如下: 最后登录到服务器上,用mysql自带的client执行了一下,是ok的. 很是奇怪,然后用了mysql自带的workbench试了下, 这我就感觉,是不是没显示完,把鼠标放到上图的...那,悬停了一会,竟然可以看到内容了. 再倒推回来一想,上面的两个客户端,应该也是内容回来了,只是没显示出来吧? 再试试sylyog

0719show engine innodb status解读

转自 http://www.cnblogs.com/zengkefu/p/5678100.html 注:以下内容为根据<高性能mysql第三版>和<mysql技术内幕innodb存储引擎>的innodb status部分的个人理解,如果有错误,还望指正!! innodb存储引擎在show engine innodb status(老版本对应的是show innodb status)输出中,显示除了大量的内部信息,它输出就是一个单独的字符串,没有行和列,内容分为很多小段,每一段对应i

SHOW INNODB STATUS 语法已变更

SHOW INNODB STATUS 语法已变更 http://dev.mysql.com/doc/refman/5.0/en/show-innodb-status.html 13.7.5.19 SHOW INNODB STATUS Syntax SHOW INNODB STATUS In MySQL 5.0, this is a deprecated synonym for SHOW ENGINE INNODB STATUS. See Section 13.7.5.12, “SHOW ENGI