MySQL Memory--MySQL参数设置不合理导致内存溢出问题
问题描述
MySQL某服务器上仅部署1个MySQL实例,MySQL版本为Percona Server 5.6.39-83.1(wsrep_26.25),MySQL参数innodb_buffer_pool_size配置为32GB,该实例上911个用户数据库共计110217张表:
SELECT count(1) as table_count
FROM information_schema.`TABLES` AS T1
WHERE T1.`TABLE_SCHEMA` NOT IN(
'performance_schema','mysql',
'information_schema','sys');
+-------------+
| table_count |
+-------------+
| 110217 |
+-------------+
1 row in set (0.41 sec)
该服务器已使用内存长期稳定在87.4GB左右,在2022-07-19 15:30左右调整MySQL参数,后发现该服务器已使用内存快速上涨,在2022-07-20 21:30左右调整回原来配置,服务器已使用内存恢复稳定。
2022-07-19 15:30前参数配置为:
SET GLOBAL table_open_cache=400000;
SET GLOBAL table_definition_cache=400000;
2022-07-19 15:30到2022-07-20 21:30之间参数配置为:
SET GLOBAL table_open_cache=60000;
SET GLOBAL table_definition_cache=60000;
查看最新MySQL统计值:
show global status like '%open%';
+----------------------------+--------------+
| Variable_name | Value |
+----------------------------+--------------+
| Innodb_num_open_files | 10000 |
| Open_files | 15 |
| Open_table_definitions | 110217 |
| Open_tables | 117236 |
| Opened_files | 3418426285 |
| Opened_table_definitions | 3217017361 |
| Opened_tables | 4198128713 |
| Table_open_cache_hits | 129484609787 |
| Table_open_cache_misses | 4198127812 |
| Table_open_cache_overflows | 4197957086 |
+----------------------------+--------------+
虽然该实例上很多表已经被业务弃用,但监控服务dba_dubai_agent和安全团队的巡检程序都会周期性扫描整个实例上所有用户表,当参数table_open_cache和table_definition_cache被配置为6万时,远低于实例所有表数量11万,导致大量表被重复不断"打开"和“关闭“,同时导致内存大量溢出。