释放innodb空间

记一次MySQL运维

[root@b2btest ~]# free -h
             total       used       free     shared    buffers     cached
Mem:          125G       124G       780M        13M        28K       238M
-/+ buffers/cache:       124G       1.0G
Swap:          30G       7.5G        22G

内存空间不足,swap占用过快。首先查找占用进程。

top - 11:35:12 up 343 days, 14:36,  4 users,  load average: 2.67, 2.04, 1.97
Tasks: 573 total,   1 running, 572 sleeping,   0 stopped,   0 zombie
%Cpu(s): 10.2 us,  0.6 sy,  0.0 ni, 89.2 id,  0.0 wa,  0.0 hi,  0.1 si,  0.0 st
KiB Mem:  13178910+total, 13094849+used,   840604 free,       28 buffers
KiB Swap: 31743996 total,  7844364 used, 23899632 free.   244900 cached Mem

   PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND                                                    
110214 mysql     20   0  0.130t 0.117t   6940 S 129.1 95.3  58010:03 mysqld  

这是台mysql专用服务器,系统资源全部被MySQL占用,要释放内存,就业从MySQL解决;

mysql> show engines;
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
| Engine             | Support | Comment                                                        | Transactions | XA   | Savepoints |
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
| InnoDB             | DEFAULT | Supports transactions, row-level locking, and foreign keys     | YES          | YES  | YES    

默认存储引擎为innodb,

mysql> show engine innodb status;
截取以下段落
----------------------
BUFFER POOL AND MEMORY
----------------------
Total large memory allocated 120937512960
Dictionary memory allocated 33079802
Buffer pool size   7208520
Free buffers       8193
Database pages     7199249
Old database pages 2657374

找到原因。开始处理

mysql>  show variables like "%innodb_buffer_pool%";

截取以下参数
+-------------------------------------+----------------+
| Variable_name                       | Value          |
+-------------------------------------+----------------+
| innodb_buffer_pool_chunk_size       | 134217728      |
| innodb_buffer_pool_instances        | 8              |
| innodb_buffer_pool_size             | 118111600640   |
+-------------------------------------+----------------+
10 rows in set (0.00 sec)

mysql> select 118111600640-134217728*8*50;
计划释放50倍的数据块
+-----------------------------+
| 118111600640-134217728*8*50 |
+-----------------------------+
|                 64424509440 |
+-----------------------------+
1 row in set (0.00 sec)


mysql>  SET GLOBAL innodb_buffer_pool_size=64424509440;
Query OK, 0 rows affected (0.00 sec)
将112G的内存降低至60G

之后查看下系统内存。free -h。确认下修改是否生效

猜你喜欢

转载自www.cnblogs.com/shc336/p/10070081.html