How to fix the vnstat database error

The program vnstat is a very handy network statistics program, that allows you to keep of the bandwidth consumed by all your on-line activities. Unfortunately, it can sometimes respond with the following message:

root@udon:~# vnstat -m
Error: Database load failed even when using backup. Aborting.

Oh shoot, its internal database is dead? How to solve this? Well, the problem is that the following solution completely removes the database, which means you lose all the statistics goodness of this little program... Ah well... :-(

Here is the magic formula:

root@udon:~# rm -v /var/lib/vnstat/eth0
removed `/var/lib/vnstat/eth0'

root@udon:~# vnstat -u -i eth0
Error: Unable to read database "/var/lib/vnstat/eth0".
Info: -> A new database has been created.

Of course, following this, vnstat will complain it does not have a lot of data. For instance:

root@udon:~# vnstat -d
 eth0: Not enough data available yet.

For those who are interested, here is the line in my crontab that updates vnstat:

root@udon:~# crontab -l | grep -i vnstat
# run vnstat update every 5 minutes if installed
00,05,10,15,20,25,30,35,40,45,50,55 * * * * /usr/bin/vnstat -u > /dev/null 2>&1

Hope this helps!

See Also: