Table size not decreasing after deleting large amount of data in MySQL

Xu12 days ago

Hi Traccar team,

I am using MySQL with Traccar, and I recently deleted a large amount of data from one of my tables. However, I noticed that the physical size of the table did not decrease after the deletion.

Here are the details of the table(tc_positions):

  • Table size: 32.3 GiB
  • Row count: 165,432,147
  • Downtime is not acceptable for this operation

I am looking for guidance on the best strategy to reclaim disk space or optimize the table without causing downtime.

Specifically:

  1. Can I safely use OPTIMIZE TABLE or ALTER TABLE in this scenario?

Note:

  1. We have already implemented clearing database mentioned in https://www.traccar.org/clear-history/

Any advice or guidance would be greatly appreciated!

Thank you.

Anton Tananaev12 days ago

It is absolutely expected that the file size doesn't decrease when you delete the data. Why do you need to decrease it?

Xu12 days ago

otherwise the physical storage will increase linearly ?

Anton Tananaev12 days ago

Why would it increase? If you removed data, that space will be reused.

Walter Spada7 days ago

Copy database, delete table, recreate table, point traccar to new database, delete old database.
Down time = seconds.

Anton Tananaev7 days ago

If you just nuke the whole positions table there's an easier way - use TRUNCATE.

Xu7 days ago

@Walter Spada, our table is like 33.5 Gib. don't think its down time is seconds.

Xu7 days ago

@Anton Tananaev, can't do that, we keep latest 2 months data.