1 Mysql5.6
1.1 相關參數
MySQL 5.6增加了參數innodb_undo_directory、innodb_undo_logs和innodb_undo_tablespaces這3個參數,可以把undo log從ibdata1移出來單獨存放。
默認參數:
mysql> show variables like '%undo%';+-------------------------+-------+| Variable_name | Value |+-------------------------+-------+| innodb_undo_directory | . || innodb_undo_logs | 128 || innodb_undo_tablespaces | 0 |+-------------------------+-------+
實例初始化是修改innodb_undo_tablespaces:
mysql_install_db ...... --innodb_undo_tablespaces$ ls...undo001 undo002 undo003
1.2 使用
初始化實例之前,我們只需要設置innodb_undo_tablespaces參數(建議大于等于3)即可將undo log設置到單獨的undo表空間中。如果需要將undo log放到更快的設備上時,可以設置innodb_undo_directory參數,但是一般我們不這么做,因為現在SSD非常普及。innodb_undo_logs可以默認為128不變。
undo log可以存儲于ibdata之外。但這個特性依然雞肋:
1.3 大事務測試
mysql> create table test.tbl( id int primary key auto_increment, name varchar(200));Query OK, 0 rows affected (0.03 sec)mysql> start transaction;Query OK, 0 rows affected (0.00 sec)mysql> insert into test.tbl(name) values(repeat('1',00));Query OK, 1 row affected (0.00 sec)mysql> insert into test.tbl(name) select name from test.tbl;Query OK, 1 row affected (0.00 sec)Records: 1 Duplicates: 0 Warnings: 0...mysql> insert into test.tbl(name) select name from test.tbl;Query OK, 2097152 rows affected (24.84 sec)Records: 2097152 Duplicates: 0 Warnings: 0mysql> commit;Query OK, 0 rows affected (7.90 sec)
觀察undolog已經開始膨脹了!事務commit后空間也沒有回收。
$ du -sh undo*10M undo00169M undo00210M undo003
2 Mysql5.7
5.7引入了在線truncate undo tablespace
2.1 相關參數
必要條件:
啟動參數:
2.2 清理過程
2.3 性能建議
truncate表空間時避免影響性能的最簡單方法是增加撤消表空間的數量
2.4 大事務測試
配置8個undo表空間,innodb_purge_rseg_truncate_frequency=10
mysqld --initialize ... --innodb_undo_tablespaces=8
開始測試
mysql> show global variables like '%undo%';+--------------------------+------------+| Variable_name | Value |+--------------------------+------------+| innodb_max_undo_log_size | 1073741824 || innodb_undo_directory | ./ || innodb_undo_log_truncate | ON || innodb_undo_logs | 128 || innodb_undo_tablespaces | 8 |+--------------------------+------------+mysql> select @@innodb_purge_rseg_truncate_frequency;+----------------------------------------+| @@innodb_purge_rseg_truncate_frequency |+----------------------------------------+| 10 |+----------------------------------------+select @@innodb_max_undo_log_size;+----------------------------+| @@innodb_max_undo_log_size |+----------------------------+| 10485760 |+----------------------------+mysql> create table test.tbl( id int primary key auto_increment, name varchar(200));Query OK, 0 rows affected (0.03 sec)mysql> start transaction;Query OK, 0 rows affected (0.00 sec)mysql> insert into test.tbl(name) values(repeat('1',00));Query OK, 1 row affected (0.00 sec)mysql> insert into test.tbl(name) select name from test.tbl;Query OK, 1 row affected (0.00 sec)Records: 1 Duplicates: 0 Warnings: 0...mysql> insert into test.tbl(name) select name from test.tbl;Query OK, 2097152 rows affected (24.84 sec)Records: 2097152 Duplicates: 0 Warnings: 0mysql> commit;Query OK, 0 rows affected (7.90 sec)
undo表空間情況,膨脹到100MB+后成功回收
$ du -sh undo*
10M undo001
10M undo002
10M undo003
10M undo004
10M undo005
10M undo006
125M undo007
10M undo008$ du -sh undo*
10M undo001
10M undo002
10M undo003
10M undo004
10M undo005
10M undo006
10M undo007
10M undo008
3 Reference
https://dev.mysql.com/doc/ref...
總結
以上就是這篇文章的全部內容了,希望本文的內容對大家的學習或者工作具有一定的參考學習價值,謝謝大家對武林網的支持。
新聞熱點
疑難解答