Skip to content

Commit

Permalink
Start moving reindexing stuff around and added some notes
Browse files Browse the repository at this point in the history
  • Loading branch information
justinclift committed Oct 1, 2024
1 parent 51fe3ce commit d94ca79
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 29 deletions.
2 changes: 1 addition & 1 deletion Dockerfile.alpine
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ARG PGTARGET=16
ARG PGTARGET=17

### Things we need in all build containers
FROM alpine:3.20 AS base-build
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.bookworm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ARG PGTARGET=16
ARG PGTARGET=17

### Things we need in all build containers
FROM debian:bookworm AS base-build
Expand Down
69 changes: 42 additions & 27 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -572,33 +572,6 @@ _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 "${PGDATA}" 2>/dev/null | 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 "${PGDATA}" "${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 All @@ -620,6 +593,48 @@ _main() {
echo "'One shot' automatic upgrade was requested, so exiting now rather than starting the PostgreSQL server"
echo "*****************************************************************************************************"
else

# Launch background shell script to perform tasks that need doing when the main database process is running
# This includes stuff like: vacuum analyze and database reindexing
# * vacuumdb --all --analyze-in-stages
# * We should probably use VACUUM ANALYZE ONLY_DATABASE_STATS
# * Should we turn off `INDEX_CLEANUP` when running this? Or maybe turn it off when reindexing has been requested
# by the user?

# Automatically reindex the databases (if requested)
SCRIPT_OPTIONS=""
if [ "${PGAUTO_REINDEX}" = "yes" ]; then
SCRIPT_OPTIONS="reindex"
# Move the below reindexing code into the background running shell script
# 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 "${PGDATA}" 2>/dev/null | 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 "${PGDATA}" "${DATABASE}"
#
# echo "-------------------------------"
# echo "Finished reindex of ${DATABASE}"
# echo "-------------------------------"
# done
#
# echo "-------------------------------"
# echo "End of reindexing the databases"
# echo "-------------------------------"
fi

# Launch script that does the background post-upgrade tasks
#TIMESTAMP_NOW=$(date +'%Y.%m.%d-%H.%M')
#bash /opt/pgautoupgrade-reindex.sh "${SCRIPT_OPTIONS}" >"${PGDATA}/${TIMESTAMP_NOW}-pgautoupgrade.log" 2>&1 &

exec "$@"
fi
fi
Expand Down

0 comments on commit d94ca79

Please sign in to comment.