Database maintenance
Maintenance and Monitoring
Pi-hole uses an SQLite database (gravity.db) to store DNS query logs, blocklists, and other essential data. Regular maintenance helps ensure optimal performance and efficient disk space usage. Here are the key maintenance tasks:
Basic Maintenance
1. Flush Query Logs
To clear long-term query logs when they consume too much space:
pihole -f
2. Update Blocklists
To refresh your protection by updating blocklists:
pihole -g
3. Rebuild Gravity Database
If you notice slow queries or errors, rebuild the database:
pihole -g -r
4. Backup Settings
Create a backup of your Pi-hole configuration:
pihole -a -t
Advanced Maintenance
5. Manual Database Reset
If the database becomes corrupted, you can clear it with these commands:
sudo service pihole-FTL stop
sudo rm /etc/pihole/pihole-FTL.db
sudo service pihole-FTL start
6. Database Optimization
Reclaim unused space in the database:
sqlite3 /etc/pihole/pihole-FTL.db "VACUUM;"
7. Database Health Check
Verify database integrity if you suspect corruption:
sqlite3 /etc/pihole/pihole-FTL.db "PRAGMA integrity_check;"
Regular maintenance will help keep your Pi-hole installation running efficiently and prevent performance issues. Consider scheduling these tasks at regular intervals based on your usage patterns.
Something here not working for you? Ask in the community — other makers and the Little Bird team read it.