diff --git a/docker-compose.yml b/docker-compose.yml index 8d86a21bc80..595944707b6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -161,7 +161,7 @@ services: postgres: <<: *restart_policy # Using the same postgres version as Sentry dev for consistency purposes - image: "postgres:14.24-bookworm" + image: "postgres:14.24-trixie" healthcheck: <<: *healthcheck_defaults # Using default user "postgres" from sentry/sentry.conf.example.py or value of POSTGRES_USER if provided diff --git a/install.sh b/install.sh index 3b4d9b50011..9bbe33f10b0 100755 --- a/install.sh +++ b/install.sh @@ -38,9 +38,9 @@ source install/ensure-relay-credentials.sh source install/generate-secret-key.sh source install/build-docker-images.sh source install/migrate-seaweedfs-kek.sh +source install/upgrade-postgres.sh source install/bootstrap-s3-nodestore.sh source install/bootstrap-snuba.sh -source install/upgrade-postgres.sh source install/ensure-correct-permissions-profiles-dir.sh source install/bootstrap-s3-profiles.sh source install/set-up-and-migrate-database.sh diff --git a/install/upgrade-postgres.sh b/install/upgrade-postgres.sh index 6785ae879ea..7c0b00b5963 100644 --- a/install/upgrade-postgres.sh +++ b/install/upgrade-postgres.sh @@ -1,5 +1,7 @@ echo "${_group}Ensuring proper PostgreSQL version ..." +postgres_version=$($CONTAINER_ENGINE run --rm -v sentry-postgres:/db busybox sh -c 'if [ -f /db/PG_VERSION ]; then cat /db/PG_VERSION; fi') + if [[ -n "$($CONTAINER_ENGINE volume ls -q --filter name=sentry-postgres)" && "$($CONTAINER_ENGINE run --rm -v sentry-postgres:/db busybox cat /db/PG_VERSION 2>/dev/null)" == "9.6" ]]; then $CONTAINER_ENGINE volume rm sentry-postgres-new || true # If this is Postgres 9.6 data, start upgrading it to 14.0 in a new volume @@ -41,4 +43,16 @@ if [[ -n "$($CONTAINER_ENGINE volume ls -q --filter name=sentry-postgres)" && "$ $dc stop postgres fi +# Reindex existing PostgreSQL 14 data once for the glibc 2.36 (Bookworm) -> 2.41 (Trixie) change. +if [[ "$postgres_version" == "14" || -z "$postgres_version" ]]; then + needs_reindex=$($CONTAINER_ENGINE run --rm -v sentry-postgres:/db busybox sh -c 'if [ -f /db/PG_VERSION ] && [ ! -f /db/14-trixie-reindexed ]; then echo yes; fi') + + start_service_and_wait_ready postgres + if [[ "$needs_reindex" == "yes" ]]; then + echo "Re-indexing due to glibc change, this may take a while..." + $dc exec postgres psql -U postgres -v ON_ERROR_STOP=1 -c "REINDEX DATABASE postgres;" + fi + $dc exec postgres sh -c 'touch "$PGDATA/14-trixie-reindexed"' +fi + echo "${_endgroup}"