# How to decrease disk space occupied by /var/lib/mysql?

**URL:** <https://forums.percona.com/t/how-to-decrease-disk-space-occupied-by-var-lib-mysql/7263>\
**Category:** Other MySQL® Questions\
**Created:** [October 25, 2019, 8:09am UTC](https://forums.percona.com/t/how-to-decrease-disk-space-occupied-by-var-lib-mysql/7263 "2019-10-25T08:09:50Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![CESAR\_MURILO\_DA\_SILV](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/cesar_murilo_da_silv/32/1248_2.png) [@CESAR\_MURILO\_DA\_SILV](https://forums.percona.com/u/CESAR_MURILO_DA_SILV)\
**Post date:** [October 25, 2019, 8:09am UTC](https://forums.percona.com/t/how-to-decrease-disk-space-occupied-by-var-lib-mysql/7263/1 "2019-10-25T08:09:50Z")

</div>

In /var/lib/mysql we have:

ibdata1 with 204M;  
folder zabbix with 238G;

The Zabbix system offers the housekeeper feature, which removes old data according to the set times.

I recently activated housekeeper, and in zabbix\_server.log I see thousands of logs being removed. But I don’t see disk space being freed. Why?

The database server is: mysql Ver 15.1 Distrib 10.0.38-MariaDB, for Linux (x86\_64) using readline 5.1;The tables are InnoDB engine.

---

<div class="post-metadata">

**Author:** ![CESAR\_MURILO\_DA\_SILV](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/cesar_murilo_da_silv/32/1248_2.png) [@CESAR\_MURILO\_DA\_SILV](https://forums.percona.com/u/CESAR_MURILO_DA_SILV)\
**Post date:** [November 6, 2019, 2:45pm UTC](https://forums.percona.com/t/how-to-decrease-disk-space-occupied-by-var-lib-mysql/7263/2 "2019-11-06T14:45:00Z")

</div>

How would I optimize with the pt-online-schema-change command?

---

<div class="post-metadata">

**Author:** ![Rick\_James](https://avatars.discourse-cdn.com/v4/letter/r/22d042/32.png) [@Rick\_James](https://forums.percona.com/u/Rick_James)\
**Post date:** [March 22, 2020, 5:46pm UTC](https://forums.percona.com/t/how-to-decrease-disk-space-occupied-by-var-lib-mysql/7263/3 "2020-03-22T17:46:17Z")

</div>

Tablespaces do not give space back to the OS. Deleted rows simply leave free space in the tablespace.

If the tables were generated while innodb\_file\_per\_table was ON, then do SHOW TABLE STATUS to see which ones have more than a few MB of “Data\_free”. For those, do OPTIMIZE TABLE. (Start with the smallest).

If all the tables were built with OFF, you are in a bad situation. The standard fix is to take a full dump, clear the disk (consider upgrading mysql at the same time), and reload everything. This time have innodb\_file\_per\_table=ON before starting.

---

<div class="post-metadata">

**Author:** ![Yunus](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/yunus/32/6430_2.png) [@Yunus](https://forums.percona.com/u/Yunus)\
**Post date:** [April 28, 2022, 3:59am UTC](https://forums.percona.com/t/how-to-decrease-disk-space-occupied-by-var-lib-mysql/7263/4 "2022-04-28T03:59:50Z")

</div>

If you want to optimize using pt-online-schema-change, then you can run NULL Alter to optimize the table.  
alter table tablename engine=INNODB;

---

<div class="post-metadata">

**Author:** ![Chris.c111](https://avatars.discourse-cdn.com/v4/letter/c/c57346/32.png) [@Chris.c111](https://forums.percona.com/u/Chris.c111)\
**Post date:** [July 19, 2023, 6:19pm UTC](https://forums.percona.com/t/how-to-decrease-disk-space-occupied-by-var-lib-mysql/7263/5 "2023-07-19T18:19:19Z")

</div>

I ran into an issue where the Zabbix DB was expanding by around 10gb a month, which ate up my space over time. After digging into the /var/lib/mysql and found an excessive amount of binlog (binary log) files. Checking the usage with “sudo du -h”, I was able to see that the binlogs were taking 200gb. We set up log rotate to resolve and deleted the old files.

---

<div class="post-metadata">

**Author:** ![yunus\_shaikh](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/yunus_shaikh/32/3512_2.png) [@yunus\_shaikh](https://forums.percona.com/u/yunus_shaikh)\
**Post date:** [July 20, 2023, 1:52am UTC](https://forums.percona.com/t/how-to-decrease-disk-space-occupied-by-var-lib-mysql/7263/6 "2023-07-20T01:52:08Z")

</div>

You can setup the variable in mysql “expire\_logs\_days” instead of rotating logs.  
For further discussion, you can create a new thread, as this thread was for separate topic.
