开发者

Debuggin long running MySQL Active transactions with lock structs and undo log entries

开发者 https://www.devze.com 2023-01-20 06:00 出处:网络
I occasionally run into a problem with my application which results开发者_StackOverflow中文版 in a what I guess is an unfinished transaction that is not committed nor rolled back. I first notice the p

I occasionally run into a problem with my application which results开发者_StackOverflow中文版 in a what I guess is an unfinished transaction that is not committed nor rolled back. I first notice the problem the next time my application tries to start a transaction to the database.

My question is how to find out what queries have been executed within the transaction but not yet committed, what tables are affected, etc...? Basically helping me to track down what causes the problem.

I have the binary log enabled but according to documentation, a transaction is only written to the binary log when committed.

The innodb undo log is supposed to be written a idbfile contained in the same directory as the binlogs, and it is, but I can't say I've found any way of parsing it for this purpose.

SHOW PROCESSLIST shows my session with status SLEEP

SHOW INNODB STATUS:

...
...
---TRANSACTION 0 10661864, ACTIVE 4401 sec, process no, 4831, OS thread id 3023358896
3 lock struct(s), heap size 320, undo log entries 40
MySQL thread id 2, query id 2419 localhost masteruser
Trx read view will not see trx with id >= 0 10661865, sees < 0 10661865
...
...

!PS I have the same question on ServerFault but I guess this question is somewhere in between when it comes to classification, + I find that site having a much lower activity than StackOverflow so the chances of getting an answer feels higher here, hope this ok.

/Kristofer


You can find all the information you are looking for in the information schema. There are three tables (only if your using innodb plugin. Reference : http://dev.mysql.com/doc/innodb-plugin/1.0/en/innodb-plugin-installation.html)

INNODB_TRX
INNODB_LOCKS
INNODB_LOCK_WAITS

This table will give you picture of what transaction is running within your database, queries within the transaction, including what transaction is blocking what other transaction, resources it is holding lock.

Reference : http://dev.mysql.com/doc/innodb-plugin/1.0/en/innodb-information-schema-transactions.html


You should start by enabling the general and slow query logs. You may want to apply microslowpatch to see slow queries that are completed within 1 second.

0

精彩评论

暂无评论...
验证码 换一张
取 消