# Table optimisation using pt-online-schema-change

**URL:** <https://forums.percona.com/t/table-optimisation-using-pt-online-schema-change/17832>\
**Category:** MySQL & MariaDB\
**Tags:** percona\
**Created:** [October 4, 2022, 10:00am UTC](https://forums.percona.com/t/table-optimisation-using-pt-online-schema-change/17832 "2022-10-04T10:00:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Abhinandan\_Aithal\_c](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/abhinandan_aithal_c/32/6297_2.png) [@Abhinandan\_Aithal\_c](https://forums.percona.com/u/Abhinandan_Aithal_c)\
**Post date:** [October 4, 2022, 10:00am UTC](https://forums.percona.com/t/table-optimisation-using-pt-online-schema-change/17832/1 "2022-10-04T10:00:11Z")

</div>

Hi Experts,  
I am trying to optimize a table on my mysql DB to reclaim disk space from DB to OS. Below is table details:-

```auto
+-----------------+----------------------------------------------+------------+-----------+------------+----------------+------------+
| table_schema | table_name | table_rows | Data (GB) | Index (GB) | Data Free (GB) | frag_ratio |
+-----------------+----------------------------------------------+------------+-----------+------------+----------------+------------+
| current | snapshots | 35507457 | 36.96 | 0.61 | 214.84 | 5.8130 |

```

Looking at the below output i can reclaim 214 GB space. But my MySql data directory has just around 52 GB space left.

So now if i run the pt-online-schema-change tool on the table would it create a temp historic.snapshots table of 36.96 GB, copying 35507457 rows into it? or would the temp table consume Data (GB) + Index (GB) + Data Free (GB) of space on the disk? I dont wont to run out of disk space while optimising and crash my MySql DB.

-Abhi

---

<div class="post-metadata">

**Author:** ![Ivan\_Groenewold](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/ivan_groenewold/32/6299_2.png) [@Ivan\_Groenewold](https://forums.percona.com/u/Ivan_Groenewold)\
**Post date:** [October 4, 2022, 11:51am UTC](https://forums.percona.com/t/table-optimisation-using-pt-online-schema-change/17832/2 "2022-10-04T11:51:36Z")

</div>

Hello, the info above is based on statistics so it is not 100% accurate. I suggest looking at the .ibd file to see the real current disk usage then re-assess.

---

<div class="post-metadata">

**Author:** ![matthewb](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/matthewb/32/34_2.png) [@matthewb](https://forums.percona.com/u/matthewb)\
**Post date:** [October 4, 2022, 2:15pm UTC](https://forums.percona.com/t/table-optimisation-using-pt-online-schema-change/17832/3 "2022-10-04T14:15:06Z")

</div>

> [@Abhinandan\_Aithal\_c](#):
>
> would it create a temp historic.snapshots table of 36.96 GB, copying 35507457 rows into it?

Yes, this is how pt-osc would work. After the rows have been copied into this new table, it will be renamed as the current table, and the old table will be dropped.

---

<div class="post-metadata">

**Author:** ![Abhinandan\_Aithal\_c](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/abhinandan_aithal_c/32/6297_2.png) [@Abhinandan\_Aithal\_c](https://forums.percona.com/u/Abhinandan_Aithal_c)\
**Post date:** [October 12, 2022, 4:19pm UTC](https://forums.percona.com/t/table-optimisation-using-pt-online-schema-change/17832/4 "2022-10-12T16:19:24Z")

</div>

Thanks @matthewb. I was able to successfully optimise the table.

-Abhi
