Database Research & Development

  • Home
  • NoSQL
    • NoSQL
    • Cassandra
  • Databases
    • Database Theory
    • Database Designing
    • SQL Server Coding Standards
    • SQL Server
    • PostgreSQL
    • MySQL
    • Greenplum
    • Linux
  • Interviews
    • SQL Server Interviews
    • MySQL Interviews
    • SQL Puzzles
  • DBA Scripts
    • SQL Server DBA Scripts
    • PostgreSQL DBA Scripts
    • MySQL DBA Scripts
    • Greenplum DBA Scripts
  • Home
  • Blog Archives !
  • (: Laugh@dbrnd :)
  • Contact Me !
sqlserverinterviews
Home 2016 February MySQL: Script to identify the locks and blocking transactions

MySQL: Script to identify the locks and blocking transactions

This article is half-done without your Comment! *** Please share your thoughts via Comment ***

In the series of DBA Scripts, I am sharing a script to find locks and blocking transaction of the MySQL Server.

The table locks and blocking transaction are a very common thing in any database system.
As a Database Administrator, this is our responsibility to find all locked and blocked transactions of MySQL Server.

Below is a script (work for MySQL 5.5 and above versions) :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
SELECT
pl.id
,pl.user
,pl.state
,it.trx_id
,it.trx_mysql_thread_id
,it.trx_query AS query
,it.trx_id AS blocking_trx_id
,it.trx_mysql_thread_id AS blocking_thread
,it.trx_query AS blocking_query
FROM information_schema.processlist AS pl
INNER JOIN information_schema.innodb_trx AS it
ON pl.id = it.trx_mysql_thread_id
INNER JOIN information_schema.innodb_lock_waits AS ilw
ON it.trx_id = ilw.requesting_trx_id
AND it.trx_id = ilw.blocking_trx_id

Feb 22, 2016Anvesh Patel
MySQL: Script to find Last AUTO_INCREMENT value for a TableSQL Server: TSQL Script to find Count the number of Occurrences of a String
Comments: 5
  1. vivek
    February 23, 2016 at 3:39 am

    Hi ,
    Do know how to use debugger in PL/SQL developer tool and what permission are required ?

    • Anvesh Patel
      Anvesh Patel
      February 23, 2016 at 6:45 pm

      If you are talking about Oracle, I need to check.
      For MySQL, you can visit this articles:
      http://dev.mysql.com/doc/refman/5.5/en/server-system-variables.html#sysvar_max_allowed_packet
      http://stackoverflow.com/questions/273437/how-do-you-debug-mysql-stored-procedures

  2. vayu nandan
    October 10, 2017 at 11:25 am

    YOUR SCRIPT IS WRONG . WE NEED TO USE information_schema.innodb_trx TABLE TWICE TO JOIN ON ilw.requesting_trx_id AND ilw.blocking_trx_id TO GET BLOCKED AND BLOCKING TRANSACTION DETAILS SEPERATELY

    • Anvesh Patel
      Anvesh Patel
      October 10, 2017 at 8:36 pm

      thanks for update, i will check this.

  3. Doug Mewhort
    November 20, 2019 at 9:42 pm

    I think the query should be:
    SELECT pl.id,pl.user,pl.state
    ,it.trx_id,it.trx_mysql_thread_id,it.trx_query AS blocked_query
    ,it2.trx_id AS blocking_trx_id,it2.trx_mysql_thread_id AS blocking_thread,it2.trx_query AS blocking_query
    FROM information_schema.processlist AS pl
    INNER JOIN information_schema.innodb_trx AS it ON pl.id = it.trx_mysql_thread_id
    INNER JOIN information_schema.innodb_trx AS it2 ON pl.id = it2.trx_mysql_thread_id
    INNER JOIN information_schema.innodb_lock_waits AS ilw ON it.trx_id=ilw.requesting_trx_id AND it2.trx_id = ilw.blocking_trx_id;

Anvesh Patel
Anvesh Patel

Database Engineer

February 22, 2016 MySQL, MySQL DBA ScriptAnvesh Patel, block, database, database research and development, dbrnd, information_schema.innodb_trx, INFORMATION_SCHEMA.PROCESSLIST, lock, MySQL, MySQL Command, MySQL Database Administrator, MySQL Database Designing, MySQL Database Programming, MySQL Error, MySQL Performance Tunning, MySQL Query, MySQL Tips and Tricks
About Me!

I'm Anvesh Patel, a Database Engineer certified by Oracle and IBM. I'm working as a Database Architect, Database Optimizer, Database Administrator, Database Developer. Providing the best articles and solutions for different problems in the best manner through my blogs is my passion. I have more than six years of experience with various RDBMS products like MSSQL Server, PostgreSQL, MySQL, Greenplum and currently learning and doing research on BIGData and NoSQL technology. -- Hyderabad, India.

About DBRND !

dbrnd

This is a personal blog (www.dbrnd.com).

Any views or opinions represented in this blog are personal and belong solely to the blog owner and do not represent those of people, institutions or organizations that the owner may or may not be associated with in professional or personal capacity, unless explicitly stated.

Feel free to challenge me, disagree with me, or tell me I’m completely nuts in the comments section of each blog entry, but I reserve the right to delete any comment for any reason whatsoever (abusive, profane, rude, or anonymous comments) - so keep it polite.

The content of this website is protected by copyright. No portion of this website may be copied or replicated in any form without the written consent of the website owner.

Recent Comments !
  • Anvesh Patel { Sure will do... } – May 27, 12:43 PM
  • Anvesh Patel { Great... } – May 27, 12:41 PM
  • Anvesh Patel { Great... } – May 27, 12:39 PM
  • Anvesh Patel { Great... } – May 27, 12:36 PM
  • Anvesh Patel { Great... } – May 27, 12:28 PM
  • Anvesh Patel { Great... } – May 27, 12:27 PM
  • Anvesh Patel { Great... } – May 27, 12:16 PM
  • Older »
Follow Me !
  • facebook
  • linkedin
  • twitter
  • youtube
  • google
  • flickr
© 2015 – 2019 All rights reserved. Database Research & Development (dbrnd.com)
Posting....