From 32933f2627e54f46fd8b32835a276347cf70fcba Mon Sep 17 00:00:00 2001 From: Alexandre <44178713+alexbelgium@users.noreply.github.com> Date: Tue, 24 Jun 2025 13:31:07 +0200 Subject: [PATCH] Tentative code to check for reindex https://github.com/alexbelgium/hassio-addons/issues/1924#issuecomment-2999851090 --- postgres_15/rootfs/etc/cont-init.d/99-run.sh | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/postgres_15/rootfs/etc/cont-init.d/99-run.sh b/postgres_15/rootfs/etc/cont-init.d/99-run.sh index 7d0681641..c55ff89ac 100755 --- a/postgres_15/rootfs/etc/cont-init.d/99-run.sh +++ b/postgres_15/rootfs/etc/cont-init.d/99-run.sh @@ -350,6 +350,18 @@ upgrade_postgres_if_needed() { fi } +check_for_reindex() { + local log_tail + log_tail=$(timeout 15 cat /proc/1/fd/1 | tail -n 5) + + if echo "$log_tail" | grep -q "please use REINDEX to rebuild the index"; then + bashio::log.warning "REINDEX needed, starting now" + for db in $(get_user_databases); do + psql -h "$DB_HOSTNAME" -p "$DB_PORT" -U "$DB_USERNAME" -d "$db" -v ON_ERROR_STOP=1 -c "REINDEX DATABASE $db;" + done + fi +} + main() { bashio::log.info "Checking for required PostgreSQL cluster upgrade before server start..." if [ -f /config/database/PG_VERSION ]; then @@ -377,7 +389,7 @@ main() { upgrade_extension_if_needed "vectors" upgrade_extension_if_needed "vchord" - show_db_extensions + check_for_reindex & show_db_extensions if [ "$RESTART_NEEDED" = true ]; then bashio::log.warning "A critical update (Postgres or extension) occurred. Will trigger Immich add-on restart after DB comes back up."