keep only last device position in tc_positions

Synergy Dave3 years ago

Hello,
I'm using traccar with forward url, so all data is saved in an external db, and I'm using the api to send gprs commands to connected devices.
I think I need to have the last known position in the traccar database (mySQL) to be able to execute gprs commands via api, is this assumption correct?

If correct, is it possible to tell traccar to keep only the last position in tc_positions for each devices?

Motivation: I'm having 40M positions inserted daily into tc_positions and I was trying to keep only 1 day of history, tried the clear procedure but it's very slow (takes hours).

Thank you

Anton Tananaev3 years ago

You can have a script that removes all positions except the ones that are referenced from the devices table.

Synergy Dave3 years ago

Thanks,
something like

delete from tc_positions where id not in (select positionid from tc_devices);

I run this query with limit 1000 where tc_positions contains 69700493 records but it was very very slow to a point I interrupted its execution.
Thanks

Anton Tananaev3 years ago

It's going to be slow when you have a lot of data, but eventually it should run quickly. Just make sure you run it frequently.