Skip to content

Commit

Permalink
Fix pre-start when upgrading long-lived Directors
Browse files Browse the repository at this point in the history
When running `bosh create-env` on a long-running BOSH Director, the
postgres pre-start script will fail if there's an old postgres-9.4 data
directory.

This commit fixes that by recognizing if the DB has already been updated
to postgres-10, and clears out the obsolete data directory to free up
space (typically that directory is ~2 years old).

Fixes, `/var/vcap/sys/log/postgres/pre-start.stdout.log`:
```
kernel.shmmax = 67108864
Please use a previous bosh release version (271.x or lower) to migrate data from postgres-9.4 to postgres-10.
```

[#181800235](https://www.pivotaltracker.com/story/show/181800235)

Signed-off-by: Brian Cunnie <[email protected]>
  • Loading branch information
jpalermo authored and cunnie committed Jun 28, 2022
1 parent 58f1422 commit c6e1e84
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions jobs/postgres/templates/pre-start.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,22 @@ PERSISTENT_DISK_DIR=/var/vcap/store

STORE_DIR=${PERSISTENT_DISK_DIR}/postgres-13
STORE_DIR_OLD=${PERSISTENT_DISK_DIR}/postgres-10
STORE_DIR_OBSOLETE=${PERSISTENT_DISK_DIR}/postgres-9.4

USER='<%= p("postgres.user") %>'

sysctl -w "kernel.shmmax=67108864"

if [[ -d /var/vcap/store/postgres-9.4 ]]; then
echo "Please use a previous bosh release version (271.x or lower) to migrate data from postgres-9.4 to postgres-10."
exit 1
if [ -d $STORE_DIR_OBSOLETE ]; then
# uh-oh, we have years-old BOSH Director
if [ ! -d $STORE_DIR_OLD ] && [ ! -d $STORE_DIR ]; then
# we never upgraded this BOSH Director from PostgreSQL 9.4 to 10
echo "Please use a previous bosh release version (271.x or lower) to migrate data from postgres-9.4 to postgres-10."
exit 1
fi
# delete the obsolete 9.4 directory to free up space
echo "Deleting obsolete $STORE_DIR_OBSOLETE directory."
rm -rf "${STORE_DIR_OBSOLETE}"
fi

# We cannot kill the following conditional
Expand Down

0 comments on commit c6e1e84

Please sign in to comment.