awips2/deltaScripts/17.1.1/DR5794/openfire-postgresql-9.5.3-upgrade/rebuild_stats.sh
2022-05-05 12:34:50 -05:00

21 lines
644 B
Bash
Executable file

#!/bin/bash
# After pg_upgrade from 9.3.x to 9.5.x, statistics are lost.
# Once the new 9.5.x cluster is running, run this script to regenerate
# the statistics.
VACUUMDB=/awips2/postgresql/bin/vacuumdb
PSQL=/awips2/psql/bin/psql
DATABASES=$(${PSQL} --db openfire -U awips -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 awips --analyze-in-stages ${DBNAME}
else
${VACUUMDB} --username awips --analyze-in-stages ${DBNAME}
fi
done