Clean Database - delete records older than x days

Forum about Domotiga Open Source Home Automation for Linux.

Moderator: RDNZL

Post Reply
Pik
Starting Member
Starting Member
Posts: 33
Joined: Sun Apr 13, 2014 2:14 pm

Clean Database - delete records older than x days

Post by Pik »

Hello,

I implemented a OWL device to check power.
Working well; I use database saving values and in my web interface, I use highcharts to plot the history (highcharts.com).
Now, I have too many records in my database and I'd like to clean it for records older than x days.

The idea is to launch an event (midnight ?) to clean database every day.

Until now, I didn't found the method... do you have any idea ?

Kind regards.
emvee
Starting Member
Starting Member
Posts: 24
Joined: Sat Jan 18, 2014 1:42 pm

Re: Clean Database - delete records older than x days

Post by emvee »

Must be doable by logging in to the database:

Code: Select all

$ mysql -u domouser -p --database=domotiga
mysql> show tables;
mysql> select * from device_values_log;
Are in the output from this last command the values you want to delete?
If so, you can use a command like:

Code: Select all

delete from Table where dateadd(month, 2, lastchanged< getdate()
Pik
Starting Member
Starting Member
Posts: 33
Joined: Sun Apr 13, 2014 2:14 pm

Re: Clean Database - delete records older than x days

Post by Pik »

Hello,

OK, I'll try this method.. I'll give you feedback as soon as I check...

Thanks & best regards
Post Reply

Return to “DomotiGa Forum”