[MySQL] Table lock 조회 쿼리

2024. 2. 15. 21:20·Database/MySQL
728x90
반응형

[MySQL] Table lock 조회 쿼리

SHOW OPEN TABLES WHERE In_use > 0;


# MySQL 8.0
SELECT
  r.trx_id waiting_trx_id,
  r.trx_mysql_thread_id waiting_thread,
  r.trx_query waiting_query,
  b.trx_id blocking_trx_id,
  b.trx_mysql_thread_id blocking_thread,
  b.trx_query blocking_query
FROM       performance_schema.data_lock_waits w
INNER JOIN information_schema.innodb_trx b
  ON b.trx_id = w.blocking_engine_transaction_id
INNER JOIN information_schema.innodb_trx r
  ON r.trx_id = w.requesting_engine_transaction_id;
  

# MySQL 5.7
SELECT
  r.trx_id waiting_trx_id,
  r.trx_mysql_thread_id waiting_thread,
  r.trx_query waiting_query,
  b.trx_id blocking_trx_id,
  b.trx_mysql_thread_id blocking_thread,
  b.trx_query blocking_query
FROM       information_schema.innodb_lock_waits w
INNER JOIN information_schema.innodb_trx b
  ON b.trx_id = w.blocking_trx_id
INNER JOIN information_schema.innodb_trx r
  ON r.trx_id = w.requesting_trx_id;

 

Ref

https://dev.mysql.com/doc/refman/8.0/en/show-open-tables.html

 

MySQL :: MySQL 8.0 Reference Manual :: 15.7.7.24 SHOW OPEN TABLES Statement

15.7.7.24 SHOW OPEN TABLES Statement SHOW OPEN TABLES [{FROM | IN} db_name] [LIKE 'pattern' | WHERE expr] SHOW OPEN TABLES lists the non-TEMPORARY tables that are currently open in the table cache. See Section 10.4.3.1, “How MySQL Opens and Closes Tabl

dev.mysql.com

https://dev.mysql.com/doc/refman/8.0/en/innodb-information-schema-examples.html

 

MySQL :: MySQL 8.0 Reference Manual :: 17.15.2.1 Using InnoDB Transaction and Locking Information

17.15.2.1 Using InnoDB Transaction and Locking Information Identifying Blocking Transactions It is sometimes helpful to identify which transaction blocks another. The tables that contain information about InnoDB transactions and data locks enable you to d

dev.mysql.com

 

728x90
반응형
저작자표시 비영리 (새창열림)
'Database/MySQL' 카테고리의 다른 글
  • [MySQL] GROUP BY Optimization
  • [MySQL] ORDER BY Optimization
  • [MySQL] Show Index
  • [MySQL] binlog to SQL(텍스트) 변환
상쾌한기분
상쾌한기분
    반응형
    250x250
  • 상쾌한기분
    상쾌한기분
    상쾌한기분
  • 전체
    오늘
    어제
    • 분류 전체보기 (253)
      • Python (44)
        • Python (26)
        • Django (6)
        • Flask (4)
        • Open Source (6)
      • Kotlin & Java (5)
        • Spring (2)
        • 프로젝트 (1)
      • Go (11)
      • Database (24)
        • MySQL (21)
        • Redis (3)
      • Infrastructure (29)
        • CDC (4)
        • Kafka (5)
        • Prometheus (2)
        • Fluentd (11)
        • Docker (1)
        • Airflow (2)
        • VPN (2)
      • IT (118)
        • AI (9)
        • Langchain (8)
        • Web (18)
        • Git (8)
        • 리팩토링 (9)
        • Micro Service Architecture (8)
        • Clean Code (16)
        • Design Pattern (0)
        • 수학 (1)
        • 알고리즘 (14)
      • 책책책 책을 읽읍시다 (1)
      • OS (14)
        • Centos (10)
        • Ubuntu (3)
        • Mac (1)
      • Search Engine (2)
        • ElasticSearch (1)
        • Lucene Solr (1)
      • PHP (2)
        • Laravel (1)
        • Codeigniter (1)
  • 블로그 메뉴

    • Github 방문
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    CDC
    MYSQL
    Langchain
    오블완
    go
    파이썬
    Kafka
    performance
    git
    http
    docker
    fluentd
    Golang
    ollama
    prompt
    Redis
    티스토리챌린지
    LLM
    python
    백준
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.3
상쾌한기분
[MySQL] Table lock 조회 쿼리
상단으로

티스토리툴바