Featured image of post 11.7.9 스키마 조작(DDL) - 활성 트랜잭션 조회

11.7.9 스키마 조작(DDL) - 활성 트랜잭션 조회

Real MySQL 8.0

쿼리가 오랜 시간 실행되고 있는 경우도 문제지만 트랜잭션이 오랜 시간 완료되지 않고 활성 상태로 남아있는 것도 MySQL 서버의 성능에 영향을 미칠 수 있다.

MySQL 서버의 트랜잭션 목록은 information_schema.innodb_trx 테이블을 통해 확인 가능하다.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
SELECT trx_id 
    ,(
        SELECT CONCAT(user, '@', host)
        FROM information_schema.processlist
        WHERE id=trx_mysql_thread_id
    ) AS soucre_info
    ,trx_state
    ,trx_started
    ,now()
    ,(unix_timestamp(now() - unix_timestamp(trx_started))) AS lasting_sec
    ,trx_requested_lock_id
    ,trx_wait_started
    ,trx_mysql_thread_id
    ,trx_tables_in_use
    ,trx_tables_in_use
    ,trx_tables_locked
FROM information_schema.innodb_trx
WHERE (unix_timestamp(now()) - unix_timestamp(trx_started)) > 5 \G   

어떤 레코드를 잠그고 있는지는 performance_schema.locks 테이블을 참조하면 된다.

1
SELECT * FROM performance_schema.data_locks \G