Unable to reclaim the disk space

Himanshu 6 years ago

Dear Sir
I have a traccar local server setup with 1 year data of 200 devices in MYSQL database. Since database size is increasing and don't require old data, I execute below mysql query on command prompt to delete the data as suggested in a different thread of this forum:

delete from tc_positions where servertime < DATE(NOW() - INTERVAL 90 day);
delete from tc_statistics where capturetime < DATE(NOW() - INTERVAL 90 day);
delete from tc_events where servertime < DATE(NOW() - INTERVAL 90 day);

After executing above command, the number of records in database is reduced but the disk size is remain same. Then I tried OPTIMIZE table tc_positions; but got below message:

| Table            | Op       | Msg_type | Msg_text                                                          |
+------------------+----------+----------+-------------------------------------------------------------------+
| vts.tc_positions | optimize | note     | Table does not support optimize, doing recreate + analyze instead |
| vts.tc_positions | optimize | error    | Invalid default value for 'devicetime'                            |
| vts.tc_positions | optimize | status   | Operation failed                                                  |
+------------------+----------+----------+-------------------------------------------------------------------+
3 rows in set, 2 warnings (0.00 sec)

After that I found a suggestion on StackOverflow to resolve similar issue so I execute this command ALTER table tc_positions ENGINE=InnoDB; and got below message:

ERROR 1067 (42000): Invalid default value for 'devicetime'

Now I have no clue of resolving this issue. Can you guide me what is best way to delete old record in traccar and how can I reclaim the disk size.

Anton Tananaev 6 years ago

Disable NO_ZERO_DATE for your MySQL session.

Himanshu 6 years ago

Dear Anton
I have set the NO_ZERO_DATE in MYSQL. After that I run the query DELETE FROM tc_positions WHERE fixtime < '2019-12-01 00:00:00'; to delete the record older that 1/12/2019. After that I run the query optimize table tc_positions;
The Phpmyadmin is showing database file size and number of record is still same as older. I don't have much disk space left.
What could be the reason for this issue.

Anton Tananaev 6 years ago

It won't change file size. Number of records should be smaller though, if you deleted something.

Himanshu 6 years ago

Dear Sir
So how can I reclaim the disk space. Please guide. What could be the best way to keep the database size in control other it will keep on increasing.

Anton Tananaev 6 years ago

As long as you removed the old data, you should be fine. MySQL will reuse the space.