Skip to content

Commit

Permalink
Initial code (untested) for automatically reindexing the databases
Browse files Browse the repository at this point in the history
  • Loading branch information
justinclift committed Sep 30, 2024
1 parent fb7ad07 commit c709d2b
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ _main() {
echo "Running pg_upgrade command, from $(pwd)"
echo "---------------------------------------"
bin_path=$(get_bin_path)
${bin_path}/pg_upgrade --username="${POSTGRES_USER}" --link -d "${OLD}" -D "${NEW}" -b "${OLDPATH}/bin" -B "${bin_path}" --socketdir="/var/run/postgresql"
"${bin_path}/pg_upgrade" --username="${POSTGRES_USER}" --link -d "${OLD}" -D "${NEW}" -b "${OLDPATH}/bin" -B "${bin_path}" --socketdir="/var/run/postgresql"
echo "--------------------------------------"
echo "Running pg_upgrade command is complete"
echo "--------------------------------------"
Expand Down Expand Up @@ -572,6 +572,33 @@ _main() {
echo "Removing left over database files is complete"
echo "---------------------------------------------"

# Automatically reindex the databases (if requested)
if [ "${PGAUTO_REINDEX}" = "yes" ]; then
echo "------------------------"
echo "Reindexing the databases"
echo "------------------------"

# Get the list of databases in the database cluster
DB_LIST=$(echo 'SELECT datname FROM pg_catalog.pg_database WHERE datistemplate IS FALSE' | postgres --single -D /var/lib/postgresql/data 2>bar | grep datname | grep -v backend | cut -d '"' -f 2)

# For each database, reindex it
for DATABASE in ${DB_LIST}; do
echo "-------------------------------"
echo "Starting reindex of ${DATABASE}"
echo "-------------------------------"

echo 'REINDEX DATABASE' | postgres --single -D /var/lib/postgresql/data "${DATABASE}"

echo "-------------------------------"
echo "Finished reindex of ${DATABASE}"
echo "-------------------------------"
done

echo "-------------------------------"
echo "End of reindexing the databases"
echo "-------------------------------"
fi

echo "**********************************************************"
echo "Automatic upgrade process finished with no errors reported"
echo "**********************************************************"
Expand Down

0 comments on commit c709d2b

Please sign in to comment.