Skip to content

Commit

Permalink
Use docker compose exec to account for differences in container names…
Browse files Browse the repository at this point in the history
… for Postgres upgrade (#2096)

* use docker compose exec instead of docker exec

* use our $dc shortcut instead of docker compose
  • Loading branch information
hubertdeng123 authored Apr 19, 2023
1 parent e8dfa5f commit ea26ee5
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions install/upgrade-postgres.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@ if [[ -n "$(docker volume ls -q --filter name=sentry-postgres)" && "$(docker run

# 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
until $dc exec postgres 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

# VOLUME_NAME is the same as container name
# Reindex all databases and their system catalogs which are not templates
DBS=$(docker exec sentry-self-hosted-postgres-1 psql -qAt -U postgres -c "SELECT datname FROM pg_database WHERE datistemplate = false;")
DBS=$($dc exec postgres psql -qAt -U postgres -c "SELECT datname FROM pg_database WHERE datistemplate = false;")
for db in ${DBS}; do
echo "Re-indexing database: ${db}"
docker exec sentry-self-hosted-postgres-1 psql -qAt -U postgres -d ${db} -c "reindex system ${db}"
docker exec sentry-self-hosted-postgres-1 psql -qAt -U postgres -d ${db} -c "reindex database ${db};"
$dc exec postgres psql -qAt -U postgres -d ${db} -c "reindex system ${db}"
$dc exec postgres psql -qAt -U postgres -d ${db} -c "reindex database ${db};"
done

$dc stop postgres
Expand Down

0 comments on commit ea26ee5

Please sign in to comment.