Mysql의 InnoDB는 MVCC ( Multi Version Concurrency Control )을 사용하며, 이는 이전 버전으 데이터와 rollback을 지원하기 위해서 변경된 row의 이전 데이터를 commit/rollback이 완료될 때까지 보관하고 있어서 한다. rollback을 위해서 이러한 데이터는 undo log에 저장이 되며, linked list 형태로 관리되기 때문에 History List 이며, 이 list가 길어지는 혹은 증가하고 있다는 것은 undo 데이터가 많아지고 있으며 transaction이 여전히 commit/rollback 되지 않고 있다는 것을 의미한다. undo데이터가 삭제되는 순간은 undo데이터가 더이상 필요 없어지는 순간이며, 이 것이 삭제 되지 않는 것은 어떤  transaction에서 이 데이터가 계속 필요하다고 혹은 참고하고 있다고 판단되기 때문이다. 

 

History List Length, undo로그가 증가되는 원인은 다음과 같다.

 

- read나 write에 long transaction : 

 

mysql의 default isolation model은 REPEATED_READ이므로 다른 transaction이 해당 row를 변경하고 commit했더라고 그 transaction이전부터 select를하고 지금도 하고 있다면 undo는 보관을 하고 변경되기 이전의 데이터를 select에서 repeat read했을 때에도 제공해야한다. ( 참고로 대부분의 사람들이 착각하는데 select 등의 read는 transaction이 없는 걸로 오해하는데, select도 tranaction과 항상 같이 고민해야하며, transaction의 범위 내에 있다고 생각해야한다. ) 하여 read에 long transaction도 HLL을 증가시킬수 있다.

 

- heavy write

 

많이 기록하는 경우에는 당연히 HLL이 발생할낟.

 

- commit을 하지 않은 user session

 

이 경우는 흔지 않지만, 찾기가 어려우며, DB에 문제를 줄 수 있다. 예들 들어 auto-commit false로 데이터를 한건 넣고 기다린다고 하면, 

commit이 아직 안되었기 때문에 HLL이 purge되지 않고 이후의 HLL에 기록되는 transaction도 purge 되지 않는다. user sessino이기 때문에 timeout이 적용안되서 rollback이 되지않으면서, idle하고 그 이후에 DB에 영향을 주기 않고 있기 때문에 각종 monitoring 지표에서 찾아내기가 어렵다. 해당 user session을 종료하기 전까지는 HLL은 계속 증가한다. 만약 HLL이 계속 증가하면 언젠가는 DB shutdown 혹은 restart상황으로 갈수 있다.

 

조치

 

long running transaction을 찾아서 commit 혹은 rollback 해야한다.

SELECT a.trx_id, 
      a.trx_state, 
      a.trx_started, 
      TIMESTAMPDIFF(SECOND,a.trx_started, now()) as "Seconds Transaction Has Been Open", 
      a.trx_rows_modified, 
      b.USER, 
      b.host, 
      b.db, 
      b.command, 
      b.time, 
      b.state 
FROM  information_schema.innodb_trx a, 
      information_schema.processlist b 
WHERE a.trx_mysql_thread_id=b.id
  AND TIMESTAMPDIFF(SECOND,a.trx_started, now()) > 10 
ORDER BY trx_started

 

 

 

 

 

https://docs.aws.amazon.com/ko_kr/AmazonRDS/latest/AuroraUserGuide/proactive-insights.history-list.html

 

InnoDB 기록 목록 길이가 크게 늘어남 - Amazon Aurora

이 페이지에 작업이 필요하다는 점을 알려 주셔서 감사합니다. 실망시켜 드려 죄송합니다. 잠깐 시간을 내어 설명서를 향상시킬 수 있는 방법에 대해 말씀해 주십시오.

docs.aws.amazon.com

 

https://lefred.be/content/a-graph-a-day-keeps-the-doctor-away-mysql-history-list-length/

 

A graph a day, keeps the doctor away ! – MySQL History List Length

This is the second article of the series dedicated to MySQL trending. As I wrote before, understanding your workload and seeing the evolution of it over time can help anticipating problems and work…

lefred.be

 

https://www.percona.com/blog/chasing-a-hung-transaction-in-mysql-innodb-history-length-strikes-back/

 

Chasing a Hung MySQL Transaction: InnoDB History Length Strikes Back

In this blog post, I’ll review how a hung MySQL transaction can cause the InnoDB history length to grow and negatively affect MySQL performance.

www.percona.com

https://dev.mysql.com/doc/refman/8.0/en/innodb-multi-versioning.html

 

MySQL :: MySQL 8.0 Reference Manual :: 15.3 InnoDB Multi-Versioning

15.3 InnoDB Multi-Versioning InnoDB is a multi-version storage engine. It keeps information about old versions of changed rows to support transactional features such as concurrency and rollback. This information is stored in undo tablespaces in a data str

dev.mysql.com

https://www.percona.com/blog/mysql-performance-implications-of-innodb-isolation-modes/

 

MySQL performance implications of InnoDB isolation modes

Peter Zaitsev explains InnoDB Transaction Isolation Modes, their relationship with MVCC, and how they impact MySQL performance.

www.percona.com

 

'개발관련 > Mysql' 카테고리의 다른 글

AWS Mysql Query Log : slow_query_log : DB 부하 Query 추출  (0) 2023.08.03
Mysql user access  (0) 2021.02.02

Mysql에 slow query log 를 남기게 되면 long_query_time 보다 지정 해놓은 시간 이상 소요되면  slow_query_log_file에 해당 query ( DML/DDL 모두 ) 남기게 된다.

이를 응용하여 long_query_time = 0 으로 지정해 놓으면 모든 쿼리가 파일로 저장되게 된다.

다만, 모든 쿼리가 파일로 저장되게 되므로 DB의 DDL/DML의 performance에 영향을 주게 되고 해당 파일을 써야하므로 io도 증가한다.

 

AWS aurora는 해당 파일을 parameter group에서 관리하므로 해당 option을 변경 후 DB Restart를 하면 적용된다.

 

적용전 

 

 

적용 후

 

 

slow low는 couwatch로 전송가능하다.

 

RDS > Modify > Additional Configuration > 

 

 

 

적용 후 RDS 상태 :

 

 

 

RDS Event

 

 

'개발관련 > Mysql' 카테고리의 다른 글

Aurora Mysql History List Length Increase  (0) 2023.08.21
Mysql user access  (0) 2021.02.02
형태소 parse for ElasticSearch https://esbook.kimjmin.net/06-text-analysis/6.7-stemming/6.7.2-nori    
형태소 parse for Mysql https://ariswear.tistory.com/25
https://grip.news/archives/1538

 

https://hoing.io/archives/16854

 

MySQL FullText Search 전문검색 기능 (2) - N-gram - MeCab (은전한닢)

 

hoing.io

 

'Real Mysql 8.0 > 02. 설정' 카테고리의 다른 글

Mysql8 시스템 변수  (0) 2022.02.08
Mysql 시스템 변수  (0) 2022.02.08
Mysql 8.0 in AWS Aurora  (0) 2022.02.08
Mysql convert  (0) 2022.02.08
Mysql convert  (0) 2022.02.08
mysql version  
8.0 MySQL Server 8.0 was announced in April 2018
5.7 The general availability of MySQL 5.7 was announced in October 2015
5.6 The general availability of MySQL 5.6 was announced in February 2013
5.5 generally available as of December 2010
5.1 production release 27 November 2008
   

 

 

https://en.wikipedia.org/wiki/MySQL

 

'Real Mysql 8.0 > 02. 설정' 카테고리의 다른 글

Mysql convert  (0) 2022.02.08
Mysql version check  (0) 2022.02.08
Mysql start / stop  (0) 2022.01.28
Mysql installation 설치 자료  (0) 2022.01.28
Mysql community vs enterprise  (0) 2022.01.28

Case

 

int(11) unsigned - > bigint(20)으로 변경하면 generateId가 먹히지를 않음.

 

연관에러

 

mysql duplicate entry '0' for key 'primary'

 

database returned no natively generated identity

 

해결방안 1 - 실패

 

ALTER TABLE wms.measurement_skus ADD PRIMARY KEY (id);
ALTER TABLE wms.measurement_skus DROP PRIMARY KEY;

ALTER TABLE wms.measurement_skus AUTO_INCREMENT = 40000;

이렇게 각각 해줘도 안먹힘.

 

 

해결방안 2 - 성공

 

ALTER TABLE wms.measurement_skus
  CHANGE COLUMN `id` `id` BIGINT(29) NOT NULL AUTO_INCREMENT,
  DROP PRIMARY KEY,
  ADD PRIMARY KEY (`id`);

+ Recent posts