awips2/deltaScripts/19.3.5/DR8307/postgresql-9.6.20-upgrade/rebuild_stats.sh

25 lines
716 B
Bash
Raw Normal View History

2022-05-05 12:34:50 -05:00
#!/bin/bash
# After a successful pg_upgrade, statistics are lost.
# Once the new cluster is running, run this script to regenerate the
# statistics.
#
# Author: tgurney
here="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "${here}/settings.sh" || exit 1
databases=$("${psql}" --db $default_db -U $db_admin_user -Atc "
select datname
from pg_database
where datistemplate = false
and datname not in ('awips', 'postgres');
")
for dbname in ${databases}; do
if [[ "$(id -u)" -eq 0 ]]; then
sudo -u awips "${vacuumdb}" --username $db_admin_user --analyze-in-stages ${dbname}
else
"${vacuumdb}" --username $db_admin_user --analyze-in-stages ${dbname}
fi
done