Clean H2 database

Fareed Qureshia year ago

Hi,
I am just using traccar for forwarding data to my own database which is on mysql and traccar is running on default database H2. Default H2 databse is now too heavy and I need to clean it, currently it is 370GB and I need some script to clean it. Normally I have to stop traccar and reinstall it to clean this database.
I have also set below option in configuration file

<entry key='database.positionsHistoryDays'>1</entry>
Track-tracea year ago

What is the reason you do not use Mysql for traccar server. Its recommended to do so.

Anton Tananaeva year ago

Config parameter database.positionsHistoryDays has been removed a long time ago, so it won't work if you're using a recent version of Traccar.

Fareed Qureshia year ago

I have around 2000 vehicles and moving data to mysql database throung forward.url, if I use mysql for traccar also then there is a chance that it can get overloaded.
Need someone expert opinion in this matter. Can I use mysql for both or if I remain on H2 then how to clean it.

jaya year ago

use mysql DB and search on this forum how to delete history. see below script
how can i use this code:

cat > /etc/cron.daily/traccar-clear-database << EOF
#!/bin/bash
result=""
while [[ "$result" != *" 0 rows affected"* ]]; do
  result=$(mysql -u root -proot traccar -vve "DELETE FROM tc_positions WHERE fixTime < DATE(DATE_ADD(NOW(), INTERVAL -7 DAY)) AND id NOT IN (SELECT positionId FROM tc_devices WHERE positionid IS NOT NULL) LIMIT 10000")
  sleep 1
done
result=""
while [[ "$result" != *" 0 rows affected"* ]]; do
  result=$(mysql -u root -proot traccar -vve "DELETE FROM tc_events WHERE eventTime < DATE(DATE_ADD(NOW(), INTERVAL -7 DAY)) LIMIT 10000")
  sleep 1
done
EOF
chmod +x /etc/cron.daily/traccar-clear-database