From 21931a4aeaed60cafd184771ca9cc9589637c754 Mon Sep 17 00:00:00 2001 From: Amin Vakil Date: Wed, 30 Sep 2026 00:00:53 +0330 Subject: [PATCH 1/2] build(deps): Bump postgres 18 --- .github/dependabot.yml | 2 +- action.yaml | 4 ++-- docker-compose.yml | 5 ++--- install/upgrade-postgres.sh | 27 ++++++++++++++++++++++++++- 4 files changed, 31 insertions(+), 7 deletions(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 85c31065f3a..681a28fcdf9 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -12,7 +12,7 @@ updates: ignore: - dependency-name: postgres versions: - - ">=15" + - ">=19" - dependency-name: valkey/valkey versions: - ">=9" diff --git a/action.yaml b/action.yaml index 437ef7330cb..c574920a235 100644 --- a/action.yaml +++ b/action.yaml @@ -123,9 +123,9 @@ runs: id: restore_cache_sentry uses: BYK/docker-volume-cache-action/restore@0efa5cf5178c9906cb46ed8d1a357df8fd6b1a06 with: - key: db-volumes-sentry-v3-${{ steps.cache_key.outputs.ARCH }}-${{ inputs.compose_profiles }}-${{ steps.cache_key.outputs.SENTRY_MIGRATIONS_MD5 }} + key: db-volumes-sentry-v4-${{ steps.cache_key.outputs.ARCH }}-${{ inputs.compose_profiles }}-${{ steps.cache_key.outputs.SENTRY_MIGRATIONS_MD5 }} restore-keys: | - key: db-volumes-sentry-v3-${{ steps.cache_key.outputs.ARCH }}-${{ inputs.compose_profiles }} + key: db-volumes-sentry-v4-${{ steps.cache_key.outputs.ARCH }}-${{ inputs.compose_profiles }} volumes: | sentry-postgres diff --git a/docker-compose.yml b/docker-compose.yml index 7a87f94516d..7039ed739e9 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -161,8 +161,7 @@ services: command: ["valkey-server", "/usr/local/etc/redis/redis.conf"] postgres: <<: *restart_policy - # Using the same postgres version as Sentry dev for consistency purposes - image: "postgres:14.24-trixie" + image: "postgres:18.6-trixie" healthcheck: <<: *healthcheck_defaults # Using default user "postgres" from sentry/sentry.conf.example.py or value of POSTGRES_USER if provided @@ -172,7 +171,7 @@ services: environment: POSTGRES_HOST_AUTH_METHOD: "trust" volumes: - - "sentry-postgres:/var/lib/postgresql/data" + - "sentry-postgres:/var/lib/postgresql" shm_size: 256m pgbouncer: <<: *restart_policy diff --git a/install/upgrade-postgres.sh b/install/upgrade-postgres.sh index 7c0b00b5963..d2964a92522 100644 --- a/install/upgrade-postgres.sh +++ b/install/upgrade-postgres.sh @@ -1,6 +1,6 @@ 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') +postgres_version=$($CONTAINER_ENGINE run --rm -v sentry-postgres:/db busybox sh -c 'for data in /db /db/18/docker; do if [ -f "$data/PG_VERSION" ]; then cat "$data/PG_VERSION"; break; fi; done') 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 @@ -43,6 +43,31 @@ if [[ -n "$($CONTAINER_ENGINE volume ls -q --filter name=sentry-postgres)" && "$ $dc stop postgres fi +if $CONTAINER_ENGINE volume inspect sentry-postgres-new >/dev/null 2>&1; then + echo "Found sentry-postgres-new from an interrupted PostgreSQL upgrade. Recover the database before removing this volume and rerunning install.sh." + exit 1 +fi + +if [[ "$postgres_version" == "14" ]]; then + if ! $CONTAINER_ENGINE run --rm -v sentry-postgres:/db:ro busybox test -f /db/14-trixie-reindexed; then + echo "Sentry 26.9.0 is a required hard stop. Upgrade to 26.9.0 and complete its PostgreSQL 14 Trixie migration before upgrading to PostgreSQL 18." + exit 1 + fi + + $CONTAINER_ENGINE run --rm \ + -e POSTGRES_INITDB_ARGS=--no-data-checksums \ + -v sentry-postgres:/var/lib/postgresql/14/data \ + -v sentry-postgres-new:/var/lib/postgresql/18/docker \ + tianon/postgres-upgrade:14-to-18 + + $CONTAINER_ENGINE volume rm sentry-postgres + $CONTAINER_ENGINE volume create --name sentry-postgres + $CONTAINER_ENGINE run --rm -v sentry-postgres-new:/from -v sentry-postgres:/to alpine ash -ec \ + "mkdir -p /to/18/docker; cp -av /from/. /to/18/docker; echo 'host all all all trust' >> /to/18/docker/pg_hba.conf" + $CONTAINER_ENGINE volume rm sentry-postgres-new + postgres_version=18 +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') From a06bb4740eb452e29670bc3e257f25cbeca5d2fb Mon Sep 17 00:00:00 2001 From: Amin Vakil Date: Sun, 4 Oct 2026 16:29:21 +0330 Subject: [PATCH 2/2] build(deps): support 14 bookworm to 18 trixie --- install/upgrade-postgres.sh | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/install/upgrade-postgres.sh b/install/upgrade-postgres.sh index d2964a92522..917eb83beb7 100644 --- a/install/upgrade-postgres.sh +++ b/install/upgrade-postgres.sh @@ -49,35 +49,37 @@ if $CONTAINER_ENGINE volume inspect sentry-postgres-new >/dev/null 2>&1; then fi if [[ "$postgres_version" == "14" ]]; then + # Reindex once under PostgreSQL 14 Trixie before upgrading the major version. if ! $CONTAINER_ENGINE run --rm -v sentry-postgres:/db:ro busybox test -f /db/14-trixie-reindexed; then - echo "Sentry 26.9.0 is a required hard stop. Upgrade to 26.9.0 and complete its PostgreSQL 14 Trixie migration before upgrading to PostgreSQL 18." - exit 1 + echo "[1/2] PostgreSQL 14 Bookworm -> 14 Trixie: reindexing for the glibc change, this may take a while..." + $CONTAINER_ENGINE run --rm --user postgres --network none --shm-size=256m \ + -v sentry-postgres:/var/lib/postgresql/data \ + postgres:14.24-trixie bash -ec ' + trap "pg_ctl -m fast -w stop" EXIT + pg_ctl -w start + psql -U postgres -v ON_ERROR_STOP=1 -c "REINDEX DATABASE postgres;" + touch "$PGDATA/14-trixie-reindexed" + ' + echo "[1/2] PostgreSQL 14 Trixie reindex completed and database stopped." + else + echo "[1/2] PostgreSQL 14 Trixie reindex already completed; skipping." fi + echo "[2/2] PostgreSQL 14 Trixie -> 18 Trixie: upgrading..." $CONTAINER_ENGINE run --rm \ -e POSTGRES_INITDB_ARGS=--no-data-checksums \ -v sentry-postgres:/var/lib/postgresql/14/data \ -v sentry-postgres-new:/var/lib/postgresql/18/docker \ tianon/postgres-upgrade:14-to-18 + echo "[2/2] pg_upgrade completed. Replacing the PostgreSQL 14 volume with PostgreSQL 18 data..." $CONTAINER_ENGINE volume rm sentry-postgres $CONTAINER_ENGINE volume create --name sentry-postgres $CONTAINER_ENGINE run --rm -v sentry-postgres-new:/from -v sentry-postgres:/to alpine ash -ec \ "mkdir -p /to/18/docker; cp -av /from/. /to/18/docker; echo 'host all all all trust' >> /to/18/docker/pg_hba.conf" $CONTAINER_ENGINE volume rm sentry-postgres-new postgres_version=18 -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"' + echo "[2/2] PostgreSQL 18 Trixie upgrade completed." fi echo "${_endgroup}"