From 5b968ce8efb43063d64e1610346ce7becc6ae56f Mon Sep 17 00:00:00 2001 From: Andy Pfister Date: Mon, 9 Dec 2024 15:32:58 +0100 Subject: [PATCH] Do not reindex concurrently on PG < v16 --- Dockerfile.alpine | 4 ++-- Dockerfile.bookworm | 4 ++-- README.md | 5 ++++- pgautoupgrade-postupgrade.sh | 19 ++++++------------- 4 files changed, 14 insertions(+), 18 deletions(-) diff --git a/Dockerfile.alpine b/Dockerfile.alpine index dd9321c..ac7ca95 100644 --- a/Dockerfile.alpine +++ b/Dockerfile.alpine @@ -168,9 +168,9 @@ RUN if [ "${PGTARGET}" -eq 14 ]; then rm -rf /usr/local-pg14 /usr/local-pg15 /us RUN if [ "${PGTARGET}" -eq 15 ]; then rm -rf /usr/local-pg15 /usr/local-pg16; fi RUN if [ "${PGTARGET}" -eq 16 ]; then rm -rf /usr/local-pg16; fi -# Install locale +# Install locale and bc command for comparisons RUN apk update && \ - apk add --update icu-data-full musl musl-utils musl-locales tzdata && \ + apk add --update bc icu-data-full musl musl-utils musl-locales tzdata && \ apk cache clean ## FIXME: Only useful while developing this Dockerfile diff --git a/Dockerfile.bookworm b/Dockerfile.bookworm index 842f9cd..64c0f72 100644 --- a/Dockerfile.bookworm +++ b/Dockerfile.bookworm @@ -166,9 +166,9 @@ RUN if [ "${PGTARGET}" -eq 14 ]; then rm -rf /usr/local-pg14 /usr/local-pg15 /us RUN if [ "${PGTARGET}" -eq 15 ]; then rm -rf /usr/local-pg15 /usr/local-pg16; fi RUN if [ "${PGTARGET}" -eq 16 ]; then rm -rf /usr/local-pg16; fi -# Install locale +# Install locale and bc command for comparisons RUN apt update && \ - apt install -y icu-devtools locales tzdata && \ + apt install -y bc icu-devtools locales tzdata && \ apt clean # Pass the PG build target through to the running image diff --git a/README.md b/README.md index 0f84c09..6294c42 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,7 @@ $ docker run --name pgauto -it \ ``` -### Skip reindexing +### Reindexing By default, all databases are reindexed after the migration, which can take some time if they are large. To skip reindexing, set the environment variable `PGAUTO_REINDEX` to `no`, for example: @@ -89,6 +89,9 @@ $ docker run --name pgauto -it \ ``` +> [!WARNING] +> PG v15 and below do not support reindexing system tables in a database concurrently. This means, when we run start the indexing operation, database locks are placed which do not allow for any modifications as long as the task is running. We recommend using PG v16 or v17 where this is not an issue. + # For Developers ## Building the image diff --git a/pgautoupgrade-postupgrade.sh b/pgautoupgrade-postupgrade.sh index 3315dfa..5b7d546 100755 --- a/pgautoupgrade-postupgrade.sh +++ b/pgautoupgrade-postupgrade.sh @@ -58,19 +58,12 @@ if [ "x${PGAUTO_REINDEX}" != "xno" ]; then echo "------------------------" echo "Reindexing the databases" echo "------------------------" - - # For each database, reindex it - for DATABASE in ${DB_LIST}; do - echo "-------------------------------" - echo "Starting reindex of ${DATABASE}" - echo "-------------------------------" - - echo 'REINDEX DATABASE CONCURRENTLY' | psql --username="${POSTGRES_USER}" -t --csv "${DATABASE}" - - echo "-------------------------------" - echo "Finished reindex of ${DATABASE}" - echo "-------------------------------" - done + + if [[ $(echo "15 <= $PGTARGET" | bc) -eq 0 ]]; then + reindexdb --all --username="${POSTGRES_USER}" + else + reindexdb --all --concurrently --username="${POSTGRES_USER}" + fi echo "-------------------------------" echo "End of reindexing the databases"