Skip to content

Commit

Permalink
Option to skip reindexing
Browse files Browse the repository at this point in the history
  • Loading branch information
waldner authored and justinclift committed Oct 24, 2024
1 parent 3a3c609 commit 2649352
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 22 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,19 @@ $ docker run --name pgauto -it \
<NAME_OF_THE_PGAUTOUPGRADE_IMAGE>
```

### Skip 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:

```
$ docker run --name pgauto -it \
--mount type=bind,source=/path/to/your/database/directory,target=/var/lib/postgresql/data \
-e POSTGRES_PASSWORD=password \
-e PGAUTO_REINDEX=no \
<NAME_OF_THE_PGAUTOUPGRADE_IMAGE>
```

# For Developers

## Building the image
Expand Down
46 changes: 24 additions & 22 deletions pgautoupgrade-postupgrade.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,27 +53,29 @@ echo "-------------------------------------"
echo "Finished updating query planner stats"
echo "-------------------------------------"

# Reindex the databases
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

echo "-------------------------------"
echo "End of reindexing the databases"
echo "-------------------------------"
if [ "x${PGAUTO_REINDEX}" != "xno" ]; then
# Reindex the databases
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

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

# If "one shot" mode was requested, then shut down PostgreSQL
if [ "x${PGAUTO_ONESHOT}" = "xyes" ]; then
Expand All @@ -88,4 +90,4 @@ else
fi

# Run a sync before exiting, just to ensure everything is flushed to disk before docker terminates the process
sync
sync

0 comments on commit 2649352

Please sign in to comment.