From 73301da68f0243717424cc3de7ffa6a0655168ce 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 7ab3243c..1a01946a 100755 --- a/gravity.sh +++ b/gravity.sh @@ -837,6 +837,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 @@ -949,6 +967,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