Skip to content

Commit

Permalink
Do not reindex concurrently on PG < v16
Browse files Browse the repository at this point in the history
  • Loading branch information
andyundso committed Dec 9, 2024
1 parent 6f61729 commit 5b968ce
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 18 deletions.
4 changes: 2 additions & 2 deletions Dockerfile.alpine
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile.bookworm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ $ docker run --name pgauto -it \
<NAME_OF_THE_PGAUTOUPGRADE_IMAGE>
```

### 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:
Expand All @@ -89,6 +89,9 @@ $ docker run --name pgauto -it \
<NAME_OF_THE_PGAUTOUPGRADE_IMAGE>
```

> [!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
Expand Down
19 changes: 6 additions & 13 deletions pgautoupgrade-postupgrade.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 5b968ce

Please sign in to comment.