Our app has some long-running operations that are wrapped in a transaction, within such transaction it performs dozens of fast queries.
Recently we encountered a problem with one of such transactions – it updated a lot of resources and therefore acquired LOCKs on them, which prevents other update operations to be performed on these resources until that long-running transaction finishes.
Question:
How can we find that transaction’s process ID and kill it if we need to?
I wanted to find it via SHOW PROCESSLIST
output (maybe just find a command that is executing long, for example) but this seems problematic: as I understand that started transaction will have in the Sleep
state and it will not have any other details, and given we have a pool of persistent connections to DB (which also have Sleep
state and show long execution time) I am not sure how I can find that specific connection that I want to kill.
This is for the future reference, the transaction we had a problem with already finished.
Hope it makes sense.
2
Answers
You can get currently running transaction details from
information_schema.innodb_trx
table:The useful columns for the purpose of the question above are:
trx_mysql_thread_id
- this is the process ID that you can pass toKILL {process id};
command to kill the transaction.trx_started
- shows the datetime of when the transaction was started, useful to determine which transaction is the one I am looking for.Also, it might be useful to JOIN
information_schema.processlist
table to get the current execution time of each transaction (for convenience of determining which is the longest transaction running):You can grab more columns that you'll find useful there.
Try the below statement please: