From b9861cd2b02975fcdf69e772c54f541942af8069 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Mon, 1 Jan 2024 08:42:31 +0100 Subject: [PATCH] Optimize the database by running ANALYZE after gravity finished Signed-off-by: DL6ER --- gravity.sh | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/gravity.sh b/gravity.sh index f51103ff..6d101696 100755 --- a/gravity.sh +++ b/gravity.sh @@ -790,6 +790,24 @@ database_recovery() { echo "" } +gravity_optimize() { + # The ANALYZE command gathers statistics about tables and indices and stores + # the collected information in internal tables of the database where the + # query optimizer can access the information and use it to help make better + # query planning choices + local str="Optimizing database" + echo -ne " ${INFO} ${str}..." + output=$( { pihole-FTL sqlite3 -ni "${gravityTEMPfile}" "PRAGMA analysis_limit=0; ANALYZE" 2>&1; } 2>&1 ) + status="$?" + + if [[ "${status}" -ne 0 ]]; then + echo -e "\\n ${CROSS} Unable to optimize database ${gravityTEMPfile}\\n ${output}" + gravity_Cleanup "error" + else + echo -e "${OVER} ${TICK} ${str}" + fi +} + helpFunc() { echo "Usage: pihole -g Update domains from blocklists specified in adlists.list @@ -899,6 +917,9 @@ gravity_build_tree # numbers quickly from the tree instead of having to scan the whole database) gravity_ShowCount +# Optimize the database +gravity_optimize + # Migrate rest of the data from old to new database # IMPORTANT: Swapping the databases must be the last step before the cleanup if ! gravity_swap_databases; then