The Pi-hole is deleting hourly if I'm not mistaken. However, to reduce stress on your SD card, they are merely markes as discarded with will be overwritten with new queries. Saves one cycle of writing (no zero overwriting during deletion). I would worry more about the log files. Disable logging if you don't need it.
sqlite> DELETE FROM queries WHERE timestamp <= strftime('%s', datetime('now', '-30 day'));
Error: cannot modify queries because it is a view
But this seems to work:
sqlite> DELETE FROM query_storage WHERE timestamp <= strftime('%s', datetime('now', '-30 day'));
EDIT: I didn't have enough space to run either the DELETE or the VACUUM SQL commands. Lots of time wasted, though.
So I wound up tossing the old database and starting new. I changed pihole-FTL.conf to add MAXDBDAYS=180. Hopefully, that will prevent the database from growing so large next time (it was 11G, btw). The following log entry after restarting seems to confirm that:
[2023-08-12 22:15:02.734 2784M] MAXDBDAYS: max age for stored queries is 180 days