Skip to content

Commit

Permalink
Do not reindex concurrently on PG < v16 (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
andyundso authored Dec 10, 2024
1 parent 6f61729 commit 0c38e35
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
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 [[ "$PGTARGET" -le 15 ]]; 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 0c38e35

Please sign in to comment.