-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Upgrade Postgres to 14 #2074
Upgrade Postgres to 14 #2074
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Requesting changes for Docker Container registry change.
# If this is Postgres 9.6 data, start upgrading it to 14.0 in a new volume | ||
docker run --rm \ | ||
-v sentry-postgres:/var/lib/postgresql/9.6/data \ | ||
-v sentry-postgres-new:/var/lib/postgresql/14/data \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this create the sentry-postgres-new
volume automatically?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, and we've done this in the past
install/upgrade-postgres.sh
Outdated
# Finally, remove the new old volume as we are all in sentry-postgres now | ||
docker volume rm sentry-postgres-new |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider making this optional in interactive mode in case there are issues with the migration.
echo "${_group}Ensuring proper PostgreSQL version ..." | ||
|
||
if [[ -n "$(docker volume ls -q --filter name=sentry-postgres)" && "$(docker run --rm -v sentry-postgres:/db busybox cat /db/PG_VERSION 2>/dev/null)" == "9.6" ]]; then | ||
docker volume rm sentry-postgres-new || true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just saw the re-indexing thing below. You may wanna add an escape hatch here with a warning that this may take a while.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like introducing an additional prompt asking for the user to continue with a warning since for people who have automated upgrade scripts it will cause those to start hanging (us and our daily upgrades 😅). It feels like adding an additional install option like we do for minimize-downtime
and skip-commit-check
also isn't super applicable here since this is a one time thing too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant it for the interactive cases that we know about. I think we had a flag to indicate non-interactive installs. But you are right, it should be fine.
$dc up -d postgres | ||
|
||
# Wait for postgres | ||
RETRIES=5 | ||
until docker exec sentry-self-hosted-postgres-1 psql -U postgres -c "select 1" >/dev/null 2>&1 || [ $RETRIES -eq 0 ]; do | ||
echo "Waiting for postgres server, $((RETRIES--)) remaining attempts..." | ||
sleep 1 | ||
done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should have a proper healthcheck defined for Postgres (if not we should add that now) and then should be able to do $dc up -w postgres
instead which implies detached mode.
Note that this is a compose v2-only feature (and I may argue that we should drop support for v1 at this point?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like docker compose v1 will no longer be supported in June 2023 🤔. Would rather not drop support for v1 here in this PR and wait a bit longer to do that
We currently use pg_isready
for a healthcheck which seems sufficient enough for a healthcheck for Postgres
aa1b50b
to
2a0fe96
Compare
Am I reading this right that it basically duplicates the database to a new volume? Doesn't this require double-ish disk space for the duration? This seems like a non-trivial thing to not mention if so 😅 |
You're right @stayallive. I'll add this to the release notes as this should be made more clear |
Oh snap. Yeah, this is going to make the upgrade... a challenge on a few deployments. Glad I caught this before kicking it off 😬 |
Just an FYI, I am manually running this script line by line and am running into some issues I want to document for other readers. I started when this was still called Also I am running the migration on one of my modest ~200GB deployments and it takes quite a hot minute to run this migration causing multi-hour donwtime (currently projecting 3-4 hours). The upgrade copies the data over to a new volume but copying the data back to the old volume name also takes a long time and reindex is also not that quick. Most of this is a docker limitation (not being able to rename the container) but was a bit unexpected going into this. This is all not an issue that needs to be fixed (althought the container names might be fixable by running this through docker-compose instead) but I feel like the warning should be a little harder since this will cause long downtimes and undefined behaviour if you do not have double disk space available for the temp postgres volumes on larger deployments. |
I think if you run
Although it is not practical to rename a volume consistently through docker commands, there are some hacks available to you: moby/moby#31154 (comment)
You may try the experimental |
I've put up a PR to resolve the inconsistencies between docker volume names by using Just tested it locally and it seems to work for me. Unfortunately this won't go in until the next release but hopefully that will make the upgrade process more smooth. Thanks for bringing these issues up 🙏 |
This bumps the default version of Postgres in self-hosted to 14
#1610
This needs to go in before the sentry PR to change the default version of postgres due to CI failures in sentry
getsentry/sentry#46999