Error when running recorder.purge service

When I run recorder.purge service with keep_days parameters set I get following error.

Feb 05 00:32:35 raspberrypi hass[17876]: 2018-02-05 00:32:35 ERROR (Recorder) 
[homeassistant.components.recorder.purge] Error vacuuming SQLite: (sqlite3.OperationalError) 
cannot VACUUM from within a transaction [SQL: 'VACUUM'] (Background on this error at:

Anyone had the same? Any hints for a fix?
I search for some solutions and found this but have no idea how to apply it?

Note: I am on 0.62.1
I found this Recorder.purge service call not working, which seems to be close to my problem, but apparently that got fixed in 0.62 … maybe I am missing something?


Hi Martin

I had the exact same problem and after much looking around I think I have the solution. The issue is Python 3.6.0 and SQLite not working well together. The issue has been resolved in a point-version of Python. I upgraded to Python 3.6.4 - the latest stable version and now it seems like the purge is working.

If you are code inclined this is how you update Python

tar xf Python-3.6.4.tar.xz
cd Python-3.6.4
sudo make install

I did this and it just worked - no need to do it specifically within the virtual env.

Check your Python version like this:

python3 --version

Hope this helps


Thanks Tim,
I did an upgrade and run purge service, but the size of db is still 3.5GB (i.e. no change compared to before purge service was run), no info on what happened in logs either:

2018-02-17 10:10:49 INFO (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: domain=recorder, service=purge, service_data=keep_days=100, service_call_id=1968149520-9>
2018-02-17 10:13:41 INFO (Recorder) [homeassistant.components.recorder.purge] Vacuuming SQLite to free space

Unless it takes a lot of time to purge db …

UPDATE after 2 hours:

Actually, something is happening as the db shrinked from 3.5GB down to 2GB … happy days. Thanks @Tim_W