--- title: "Pi-hole Disk Optimization" description: "Resolved critical disk space issue on primary Pi-hole by reducing query log retention to 7 days, pruning Docker resources, and removing old gravity backups." type: runbook domain: networking tags: [pihole, disk-space, docker, optimization, maintenance] --- # Pi-hole Disk Optimization - 2026-02-06 ## Problem Primary Pi-hole (npm-pihole at 10.10.0.16) had critical disk space issues: - **Root filesystem**: 91% full (27GB used of 31GB) - **Pi-hole data**: 3.6GB total - `pihole-FTL.db`: 2.8GB (query log database) - `gravity.db`: 460MB (blocklist database) - `gravity.db.v5.backup`: 114MB (old v5 backup) - **Query retention**: 91 days (default) - **Total queries stored**: 26.4 million ## Actions Taken ### 1. Removed Old Backup Database ```bash rm /home/cal/container-data/pihole/etc-pihole/gravity.db.v5.backup ``` **Space freed**: 114MB ### 2. Cleaned Up Docker Resources ```bash docker system prune -af --volumes ``` **Space freed**: 4.3GB - Removed unused images (old Pi-hole versions, Jellyfin, Foundry, etc.) - Removed stopped containers - Removed unused networks ### 3. Reduced Query Log Retention ```bash echo "database.maxDBdays=7.0" >> /etc/pihole/pihole-FTL.conf docker compose restart ``` **Configuration**: Changed from 91 days to 7 days **Future savings**: Database will automatically maintain ~7 days of logs instead of 91 ## Results | Metric | Before | After | Improvement | |--------|--------|-------|-------------| | Disk Usage | 91% (27GB/31GB) | 73% (22GB/31GB) | -18% | | Free Space | 2.8GB | 8.2GB | +5.4GB | | Total Freed | - | 4.3GB | - | ## Ongoing Maintenance ### Automatic Cleanup Pi-hole will now automatically: - Delete queries older than 7 days - Maintain FTL database size around ~300-500MB (instead of 2.8GB) - Keep the most recent week of query logs for troubleshooting ### Manual Cleanup (if needed) ```bash # Flush Pi-hole logs docker exec pihole pihole -f # Check disk usage df -h / du -sh /home/cal/container-data/pihole/etc-pihole/* # Clean unused Docker resources docker system prune -af --volumes # Check query count docker exec pihole pihole-FTL sqlite3 /etc/pihole/pihole-FTL.db 'SELECT COUNT(*) FROM queries;' ``` ### Monitoring Recommendations **Set up disk space alerts** when usage exceeds 85%: ```bash # Add to cron (daily check) 0 8 * * * df -h / | awk '$5+0 > 85 {print "Warning: Disk usage at " $5 " on npm-pihole"}' | mail -s "Disk Alert" admin@example.com ``` **Check Pi-hole database size monthly**: ```bash du -h /home/cal/container-data/pihole/etc-pihole/pihole-FTL.db ``` ## Configuration File `/etc/pihole/pihole-FTL.conf`: ```conf database.maxDBdays=7.0 # Keep queries for 7 days only ``` ## Prevention Tips 1. **Regular Docker cleanup**: Run `docker system prune` monthly 2. **Monitor disk usage**: Check `df -h` weekly 3. **Review query retention**: 7 days is sufficient for most troubleshooting 4. **Consider disabling query logging** if not needed: ```bash pihole logging off ``` 5. **Archive old logs** before major upgrades (like v5→v6) ## Space Budget Estimates With 7-day retention: - **Pi-hole FTL database**: ~300-500MB (vs 2.8GB before) - **Gravity database**: ~460MB (36 blocklists) - **Docker images**: ~2-3GB (active containers only) - **System overhead**: ~20GB - **Recommended free space**: 5GB+ for headroom **Current allocation is healthy** at 73% with 8.2GB free.