From 4f97dd3803ee3c14183b50b5536e2f78eec726a5 Mon Sep 17 00:00:00 2001 From: Frederik Erbs Spang Thomsen Date: Mon, 18 Aug 2025 15:07:34 +0200 Subject: [PATCH 01/16] Add patch for pgbouncer --- .../pgbouncer/docker-compose.yml.patch | 33 +++++++++++++++++++ .../pgbouncer/sentry-conf.example.py.patch | 14 ++++++++ 2 files changed, 47 insertions(+) create mode 100644 optional-modifications/patches/pgbouncer/docker-compose.yml.patch create mode 100644 optional-modifications/patches/pgbouncer/sentry-conf.example.py.patch diff --git a/optional-modifications/patches/pgbouncer/docker-compose.yml.patch b/optional-modifications/patches/pgbouncer/docker-compose.yml.patch new file mode 100644 index 00000000000..b79cdadbfbf --- /dev/null +++ b/optional-modifications/patches/pgbouncer/docker-compose.yml.patch @@ -0,0 +1,33 @@ +diff --git a/docker-compose.yml b/docker-compose.yml +index 8873990..d2a8777 100644 +--- a/docker-compose.yml ++++ b/docker-compose.yml +@@ -38,6 +38,8 @@ x-sentry-defaults: &sentry_defaults + <<: *depends_on-healthy + postgres: + <<: *depends_on-healthy ++ pgbouncer: ++ <<: *depends_on-default + memcached: + <<: *depends_on-default + smtp: +@@ -144,6 +146,19 @@ services: + POSTGRES_HOST_AUTH_METHOD: "trust" + volumes: + - "sentry-postgres:/var/lib/postgresql/data" ++ pgbouncer: ++ image: edoburu/pgbouncer ++ environment: ++ - DB_USER=${POSTGRES_USER:-postgres} ++ - DB_PASSWORD=${POSTGRES_PASSWORD:-sentry} ++ - DB_HOST=postgres ++ - POOL_MODE=transaction ++ - ADMIN_USERS=postgres,sentry ++ - MAX_CLIENT_CONN=10000 ++ ports: ++ - "5432:5432" ++ depends_on: ++ - postgres + kafka: + <<: *restart_policy + image: "confluentinc/cp-kafka:7.6.1" diff --git a/optional-modifications/patches/pgbouncer/sentry-conf.example.py.patch b/optional-modifications/patches/pgbouncer/sentry-conf.example.py.patch new file mode 100644 index 00000000000..91bbfcad95b --- /dev/null +++ b/optional-modifications/patches/pgbouncer/sentry-conf.example.py.patch @@ -0,0 +1,14 @@ +diff --git a/sentry/sentry.conf.example.py b/sentry/sentry.conf.example.py +index 826f43a..944dc63 100644 +--- a/sentry/sentry.conf.example.py ++++ b/sentry/sentry.conf.example.py +@@ -48,7 +48,7 @@ DATABASES = { + "NAME": "postgres", + "USER": "postgres", +- "PASSWORD": "", ++ "PASSWORD": "sentry", +- "HOST": "postgres", ++ "HOST": "pgbouncer", + "PORT": "", + } + } From c35ce1abca26ac27929facccb2bd30d7bf55d9de Mon Sep 17 00:00:00 2001 From: Frederik Erbs Spang Thomsen Date: Mon, 18 Aug 2025 15:18:27 +0200 Subject: [PATCH 02/16] pgcat over pgbouncer --- .../patches/{pgbouncer => pgcat}/docker-compose.yml.patch | 6 +++--- .../{pgbouncer => pgcat}/sentry-conf.example.py.patch | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) rename optional-modifications/patches/{pgbouncer => pgcat}/docker-compose.yml.patch (93%) rename optional-modifications/patches/{pgbouncer => pgcat}/sentry-conf.example.py.patch (92%) diff --git a/optional-modifications/patches/pgbouncer/docker-compose.yml.patch b/optional-modifications/patches/pgcat/docker-compose.yml.patch similarity index 93% rename from optional-modifications/patches/pgbouncer/docker-compose.yml.patch rename to optional-modifications/patches/pgcat/docker-compose.yml.patch index b79cdadbfbf..c538ecb56f4 100644 --- a/optional-modifications/patches/pgbouncer/docker-compose.yml.patch +++ b/optional-modifications/patches/pgcat/docker-compose.yml.patch @@ -6,7 +6,7 @@ index 8873990..d2a8777 100644 <<: *depends_on-healthy postgres: <<: *depends_on-healthy -+ pgbouncer: ++ pgcat: + <<: *depends_on-default memcached: <<: *depends_on-default @@ -15,8 +15,8 @@ index 8873990..d2a8777 100644 POSTGRES_HOST_AUTH_METHOD: "trust" volumes: - "sentry-postgres:/var/lib/postgresql/data" -+ pgbouncer: -+ image: edoburu/pgbouncer ++ pgcat: ++ image: "$PGCAT_IMAGE" + environment: + - DB_USER=${POSTGRES_USER:-postgres} + - DB_PASSWORD=${POSTGRES_PASSWORD:-sentry} diff --git a/optional-modifications/patches/pgbouncer/sentry-conf.example.py.patch b/optional-modifications/patches/pgcat/sentry-conf.example.py.patch similarity index 92% rename from optional-modifications/patches/pgbouncer/sentry-conf.example.py.patch rename to optional-modifications/patches/pgcat/sentry-conf.example.py.patch index 91bbfcad95b..782881bba1d 100644 --- a/optional-modifications/patches/pgbouncer/sentry-conf.example.py.patch +++ b/optional-modifications/patches/pgcat/sentry-conf.example.py.patch @@ -8,7 +8,7 @@ index 826f43a..944dc63 100644 - "PASSWORD": "", + "PASSWORD": "sentry", - "HOST": "postgres", -+ "HOST": "pgbouncer", ++ "HOST": "pgcat", "PORT": "", } } From b7e4d3acb0b971ac62625b16e326f056aed13d78 Mon Sep 17 00:00:00 2001 From: Frederik Erbs Spang Thomsen Date: Mon, 18 Aug 2025 15:19:09 +0200 Subject: [PATCH 03/16] Add patch for .env file --- optional-modifications/patches/pgcat/.env.patch | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 optional-modifications/patches/pgcat/.env.patch diff --git a/optional-modifications/patches/pgcat/.env.patch b/optional-modifications/patches/pgcat/.env.patch new file mode 100644 index 00000000000..39c9f983f26 --- /dev/null +++ b/optional-modifications/patches/pgcat/.env.patch @@ -0,0 +1,12 @@ +diff --git a/.env b/.env +index ba8cf62..8bcddfd 100644 +--- a/.env ++++ b/.env +@@ -16,6 +16,7 @@ SYMBOLICATOR_IMAGE=ghcr.io/getsentry/symbolicator:nightly + TASKBROKER_IMAGE=ghcr.io/getsentry/taskbroker:nightly + VROOM_IMAGE=ghcr.io/getsentry/vroom:nightly + UPTIME_CHECKER_IMAGE=ghcr.io/getsentry/uptime-checker:nightly ++PGCAT_IMAGE=ghcr.io/postgresml/pgcat:v1.2.0 + HEALTHCHECK_INTERVAL=30s + HEALTHCHECK_TIMEOUT=1m30s + HEALTHCHECK_RETRIES=10 From fe4583d04bf7705451b071da3c0bfbf9d648dc93 Mon Sep 17 00:00:00 2001 From: Frederik Erbs Spang Thomsen Date: Tue, 19 Aug 2025 19:45:39 +0200 Subject: [PATCH 04/16] Apply patches and add initial pgcat tolm file --- docker-compose.yml | 13 ++++++++ .../patches/pgcat/.env.patch | 12 ------- .../patches/pgcat/docker-compose.yml.patch | 33 ------------------- .../pgcat/sentry-conf.example.py.patch | 14 -------- pgcat.toml | 21 ++++++++++++ sentry/sentry.conf.example.py | 4 +-- 6 files changed, 36 insertions(+), 61 deletions(-) delete mode 100644 optional-modifications/patches/pgcat/.env.patch delete mode 100644 optional-modifications/patches/pgcat/docker-compose.yml.patch delete mode 100644 optional-modifications/patches/pgcat/sentry-conf.example.py.patch create mode 100644 pgcat.toml diff --git a/docker-compose.yml b/docker-compose.yml index 8873990cb3e..22e86b71fd1 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -38,6 +38,8 @@ x-sentry-defaults: &sentry_defaults <<: *depends_on-healthy postgres: <<: *depends_on-healthy + pgcat: + <<: *depends_on-default memcached: <<: *depends_on-default smtp: @@ -144,6 +146,17 @@ services: POSTGRES_HOST_AUTH_METHOD: "trust" volumes: - "sentry-postgres:/var/lib/postgresql/data" + pgcat: + image: "$PGCAT_IMAGE" + ports: + - "5432:5432" + depends_on: + - postgres + volumes: + - type: bind + read_only: true + source: ./pgcat.toml + target: /etc/pgcat/pgcat.toml kafka: <<: *restart_policy image: "confluentinc/cp-kafka:7.6.1" diff --git a/optional-modifications/patches/pgcat/.env.patch b/optional-modifications/patches/pgcat/.env.patch deleted file mode 100644 index 39c9f983f26..00000000000 --- a/optional-modifications/patches/pgcat/.env.patch +++ /dev/null @@ -1,12 +0,0 @@ -diff --git a/.env b/.env -index ba8cf62..8bcddfd 100644 ---- a/.env -+++ b/.env -@@ -16,6 +16,7 @@ SYMBOLICATOR_IMAGE=ghcr.io/getsentry/symbolicator:nightly - TASKBROKER_IMAGE=ghcr.io/getsentry/taskbroker:nightly - VROOM_IMAGE=ghcr.io/getsentry/vroom:nightly - UPTIME_CHECKER_IMAGE=ghcr.io/getsentry/uptime-checker:nightly -+PGCAT_IMAGE=ghcr.io/postgresml/pgcat:v1.2.0 - HEALTHCHECK_INTERVAL=30s - HEALTHCHECK_TIMEOUT=1m30s - HEALTHCHECK_RETRIES=10 diff --git a/optional-modifications/patches/pgcat/docker-compose.yml.patch b/optional-modifications/patches/pgcat/docker-compose.yml.patch deleted file mode 100644 index c538ecb56f4..00000000000 --- a/optional-modifications/patches/pgcat/docker-compose.yml.patch +++ /dev/null @@ -1,33 +0,0 @@ -diff --git a/docker-compose.yml b/docker-compose.yml -index 8873990..d2a8777 100644 ---- a/docker-compose.yml -+++ b/docker-compose.yml -@@ -38,6 +38,8 @@ x-sentry-defaults: &sentry_defaults - <<: *depends_on-healthy - postgres: - <<: *depends_on-healthy -+ pgcat: -+ <<: *depends_on-default - memcached: - <<: *depends_on-default - smtp: -@@ -144,6 +146,19 @@ services: - POSTGRES_HOST_AUTH_METHOD: "trust" - volumes: - - "sentry-postgres:/var/lib/postgresql/data" -+ pgcat: -+ image: "$PGCAT_IMAGE" -+ environment: -+ - DB_USER=${POSTGRES_USER:-postgres} -+ - DB_PASSWORD=${POSTGRES_PASSWORD:-sentry} -+ - DB_HOST=postgres -+ - POOL_MODE=transaction -+ - ADMIN_USERS=postgres,sentry -+ - MAX_CLIENT_CONN=10000 -+ ports: -+ - "5432:5432" -+ depends_on: -+ - postgres - kafka: - <<: *restart_policy - image: "confluentinc/cp-kafka:7.6.1" diff --git a/optional-modifications/patches/pgcat/sentry-conf.example.py.patch b/optional-modifications/patches/pgcat/sentry-conf.example.py.patch deleted file mode 100644 index 782881bba1d..00000000000 --- a/optional-modifications/patches/pgcat/sentry-conf.example.py.patch +++ /dev/null @@ -1,14 +0,0 @@ -diff --git a/sentry/sentry.conf.example.py b/sentry/sentry.conf.example.py -index 826f43a..944dc63 100644 ---- a/sentry/sentry.conf.example.py -+++ b/sentry/sentry.conf.example.py -@@ -48,7 +48,7 @@ DATABASES = { - "NAME": "postgres", - "USER": "postgres", -- "PASSWORD": "", -+ "PASSWORD": "sentry", -- "HOST": "postgres", -+ "HOST": "pgcat", - "PORT": "", - } - } diff --git a/pgcat.toml b/pgcat.toml new file mode 100644 index 00000000000..4af09d0816d --- /dev/null +++ b/pgcat.toml @@ -0,0 +1,21 @@ +# This is an example of the most basic config +# that will mimic what PgBouncer does in transaction mode with one server. + +[general] +host = "0.0.0.0" +port = 6433 +admin_username = "sentry" +admin_password = "sentry" + +[pools.sentry.users.0] +username = "sentry" +password = "sentry" +pool_size = 100 +min_pool_size = 100 +pool_mode = "transaction" + +[pools.sentry.shards.0] +servers = [ + ["postgres", 5432, "primary"] +] +database = "postgres" diff --git a/sentry/sentry.conf.example.py b/sentry/sentry.conf.example.py index 826f43ae2d6..386ef2bb2af 100644 --- a/sentry/sentry.conf.example.py +++ b/sentry/sentry.conf.example.py @@ -47,8 +47,8 @@ def get_internal_network(): "ENGINE": "sentry.db.postgres", "NAME": "postgres", "USER": "postgres", - "PASSWORD": "", - "HOST": "postgres", + "PASSWORD": "sentry", + "HOST": "pgcat", "PORT": "", } } From 0d61d3134d62264ab51cc9ffbedaa6f59f476959 Mon Sep 17 00:00:00 2001 From: Reinaldy Rafli Date: Wed, 20 Aug 2025 07:49:05 +0700 Subject: [PATCH 05/16] feat: hardcode pgcat image --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 22e86b71fd1..432d1972a8c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -147,7 +147,7 @@ services: volumes: - "sentry-postgres:/var/lib/postgresql/data" pgcat: - image: "$PGCAT_IMAGE" + image: "ghcr.io/postgresml/pgcat:v1.2.0" ports: - "5432:5432" depends_on: From 866133ead522c522285028c9d55e248ebc90f1dd Mon Sep 17 00:00:00 2001 From: Frederik Erbs Spang Thomsen Date: Wed, 20 Aug 2025 09:20:57 +0200 Subject: [PATCH 06/16] Fixes from review --- docker-compose.yml | 5 ++--- pgcat.toml | 4 +++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 432d1972a8c..166c846c403 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -148,10 +148,9 @@ services: - "sentry-postgres:/var/lib/postgresql/data" pgcat: image: "ghcr.io/postgresml/pgcat:v1.2.0" - ports: - - "5432:5432" depends_on: - - postgres + postgres: + <<: *depends_on-healthy volumes: - type: bind read_only: true diff --git a/pgcat.toml b/pgcat.toml index 4af09d0816d..346ad325a91 100644 --- a/pgcat.toml +++ b/pgcat.toml @@ -3,14 +3,16 @@ [general] host = "0.0.0.0" -port = 6433 +port = 5432 admin_username = "sentry" admin_password = "sentry" [pools.sentry.users.0] username = "sentry" password = "sentry" +# Should be at most POSTGRES_MAX_CONNECTIONS from .env. pool_size = 100 +# We can always eagerly load connections because pgcat will be the only client to the postgres container. min_pool_size = 100 pool_mode = "transaction" From 4be79b40d3e6dd5b72dde09f9dd299eacc7cb7e3 Mon Sep 17 00:00:00 2001 From: Frederik Erbs Spang Thomsen Date: Wed, 20 Aug 2025 09:24:07 +0200 Subject: [PATCH 07/16] Align usernames defaults --- docker-compose.yml | 4 ++++ pgcat.toml | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 166c846c403..798f73bb470 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -148,6 +148,10 @@ services: - "sentry-postgres:/var/lib/postgresql/data" pgcat: image: "ghcr.io/postgresml/pgcat:v1.2.0" + healthcheck: + <<: *healthcheck_defaults + # Using default user "postgres" from sentry/sentry.conf.example.py or value of POSTGRES_USER if provided + test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-postgres}"] depends_on: postgres: <<: *depends_on-healthy diff --git a/pgcat.toml b/pgcat.toml index 346ad325a91..4ad25e5dc59 100644 --- a/pgcat.toml +++ b/pgcat.toml @@ -4,11 +4,11 @@ [general] host = "0.0.0.0" port = 5432 -admin_username = "sentry" +admin_username = "postgres" admin_password = "sentry" [pools.sentry.users.0] -username = "sentry" +username = "postgres" password = "sentry" # Should be at most POSTGRES_MAX_CONNECTIONS from .env. pool_size = 100 From 7c1dd8979a40f217801a226307f809a1c19c09b7 Mon Sep 17 00:00:00 2001 From: Frederik Erbs Spang Thomsen Date: Wed, 20 Aug 2025 09:31:06 +0200 Subject: [PATCH 08/16] Remove postgres from default depends_on; Covered by pgcat by extension --- docker-compose.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 798f73bb470..7334fd9ab7d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -36,8 +36,6 @@ x-sentry-defaults: &sentry_defaults <<: *depends_on-healthy kafka: <<: *depends_on-healthy - postgres: - <<: *depends_on-healthy pgcat: <<: *depends_on-default memcached: From db1416c29dca84ef9f46c2292483293b550f9cfa Mon Sep 17 00:00:00 2001 From: Frederik Erbs Spang Thomsen Date: Wed, 20 Aug 2025 09:48:45 +0200 Subject: [PATCH 09/16] Set user and password - pgcat maybe doesnt support host auth trust --- docker-compose.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docker-compose.yml b/docker-compose.yml index 7334fd9ab7d..ae6aca0c001 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -142,6 +142,8 @@ services: ["postgres", "-c", "max_connections=${POSTGRES_MAX_CONNECTIONS:-100}"] environment: POSTGRES_HOST_AUTH_METHOD: "trust" + POSTGRES_USER: "postgres" + POSTGRES_PASSWORD: "sentry" volumes: - "sentry-postgres:/var/lib/postgresql/data" pgcat: From f48a9ed537a17b544dabda46d7fd77905e7adebe Mon Sep 17 00:00:00 2001 From: Frederik Erbs Spang Thomsen Date: Wed, 20 Aug 2025 10:13:39 +0200 Subject: [PATCH 10/16] Pool name maybe has to match, for some reason --- pgcat.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pgcat.toml b/pgcat.toml index 4ad25e5dc59..ce96141a690 100644 --- a/pgcat.toml +++ b/pgcat.toml @@ -7,7 +7,7 @@ port = 5432 admin_username = "postgres" admin_password = "sentry" -[pools.sentry.users.0] +[pools.postgres.users.0] username = "postgres" password = "sentry" # Should be at most POSTGRES_MAX_CONNECTIONS from .env. @@ -16,7 +16,7 @@ pool_size = 100 min_pool_size = 100 pool_mode = "transaction" -[pools.sentry.shards.0] +[pools.postgres.shards.0] servers = [ ["postgres", 5432, "primary"] ] From 42ed3c20ec6b626ed0b58ae1e70f29ad1fae1893 Mon Sep 17 00:00:00 2001 From: Frederik Erbs Spang Thomsen Date: Wed, 20 Aug 2025 10:14:31 +0200 Subject: [PATCH 11/16] Use healthcheck from pgcat PR --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index ae6aca0c001..9dd4d9ee31b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -151,7 +151,7 @@ services: healthcheck: <<: *healthcheck_defaults # Using default user "postgres" from sentry/sentry.conf.example.py or value of POSTGRES_USER if provided - test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-postgres}"] + test: ["CMD-SHELL", "PGPASSWORD=\"sentry\" psql -U postgres -p 5432 -h 127.0.0.1 -tA -c \"show version;\" -d postgres >/dev/null"] depends_on: postgres: <<: *depends_on-healthy From 2e0a216cbb1212c13cf336ca25ec1145a72bfce1 Mon Sep 17 00:00:00 2001 From: Frederik Erbs Spang Thomsen Date: Wed, 20 Aug 2025 10:27:39 +0200 Subject: [PATCH 12/16] Reduce pool size, leave some for healthchecks and other clients running --- docker-compose.yml | 2 +- pgcat.toml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 9dd4d9ee31b..449ed7bfb10 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -151,7 +151,7 @@ services: healthcheck: <<: *healthcheck_defaults # Using default user "postgres" from sentry/sentry.conf.example.py or value of POSTGRES_USER if provided - test: ["CMD-SHELL", "PGPASSWORD=\"sentry\" psql -U postgres -p 5432 -h 127.0.0.1 -tA -c \"show version;\" -d postgres >/dev/null"] + test: ["CMD-SHELL", "PGPASSWORD=\"sentry\" psql -U postgres -p 5432 -h 127.0.0.1 -tA -c \"select 1;\" -d postgres >/dev/null"] depends_on: postgres: <<: *depends_on-healthy diff --git a/pgcat.toml b/pgcat.toml index ce96141a690..2dc807ff399 100644 --- a/pgcat.toml +++ b/pgcat.toml @@ -11,9 +11,9 @@ admin_password = "sentry" username = "postgres" password = "sentry" # Should be at most POSTGRES_MAX_CONNECTIONS from .env. -pool_size = 100 +pool_size = 90 # We can always eagerly load connections because pgcat will be the only client to the postgres container. -min_pool_size = 100 +min_pool_size = 90 pool_mode = "transaction" [pools.postgres.shards.0] From 8fb91cdb7335717b6dab5733a866264ff52b95eb Mon Sep 17 00:00:00 2001 From: Frederik Erbs Spang Thomsen Date: Wed, 20 Aug 2025 10:58:58 +0200 Subject: [PATCH 13/16] Start pgcat for bash scripts with postgres --- install/set-up-and-migrate-database.sh | 1 + sentry-admin.sh | 1 + 2 files changed, 2 insertions(+) diff --git a/install/set-up-and-migrate-database.sh b/install/set-up-and-migrate-database.sh index 5ddf324c0b8..d4b834d4de6 100644 --- a/install/set-up-and-migrate-database.sh +++ b/install/set-up-and-migrate-database.sh @@ -3,6 +3,7 @@ echo "${_group}Setting up / migrating database ..." if [[ -z "${SKIP_SENTRY_MIGRATIONS:-}" ]]; then # Fixes https://github.com/getsentry/self-hosted/issues/2758, where a migration fails due to indexing issue start_service_and_wait_ready postgres + start_service_and_wait_ready pgcat os=$($dc exec postgres cat /etc/os-release | grep 'ID=debian') if [[ -z $os ]]; then diff --git a/sentry-admin.sh b/sentry-admin.sh index aeea2b36845..6942991a181 100755 --- a/sentry-admin.sh +++ b/sentry-admin.sh @@ -24,6 +24,7 @@ on the host filesystem. Commands that write files should write them to the '/sen # Actual invocation that runs the command in the container. invocation() { start_service_and_wait_ready postgres + start_service_and_wait_ready pgcat start_service_and_wait_ready redis --wait $dcr --no-deps -v "$VOLUME_MAPPING" -T -e SENTRY_LOG_LEVEL=CRITICAL web "$@" 2>&1 } From 4607aa2aa1edc7b3854bc644bdfe3a0929b3c658 Mon Sep 17 00:00:00 2001 From: Frederik Spang Date: Wed, 20 Aug 2025 12:30:33 +0200 Subject: [PATCH 14/16] Update docker-compose.yml Co-authored-by: Reinaldy Rafli --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 449ed7bfb10..19f0a9196e7 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -37,7 +37,7 @@ x-sentry-defaults: &sentry_defaults kafka: <<: *depends_on-healthy pgcat: - <<: *depends_on-default + <<: *depends_on-healthy memcached: <<: *depends_on-default smtp: From aa4d8ce9348b7ad0bc66f9bd19c8003cfa11428d Mon Sep 17 00:00:00 2001 From: Frederik Erbs Spang Thomsen Date: Thu, 21 Aug 2025 11:49:02 +0200 Subject: [PATCH 15/16] Use pgbouncer --- docker-compose.yml | 20 ++++++++++++-------- install/set-up-and-migrate-database.sh | 2 +- pgcat.toml | 23 ----------------------- sentry-admin.sh | 2 +- sentry/sentry.conf.example.py | 2 +- 5 files changed, 15 insertions(+), 34 deletions(-) delete mode 100644 pgcat.toml diff --git a/docker-compose.yml b/docker-compose.yml index 19f0a9196e7..0e39c1c8a4e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -36,7 +36,7 @@ x-sentry-defaults: &sentry_defaults <<: *depends_on-healthy kafka: <<: *depends_on-healthy - pgcat: + pgbouncer: <<: *depends_on-healthy memcached: <<: *depends_on-default @@ -146,8 +146,8 @@ services: POSTGRES_PASSWORD: "sentry" volumes: - "sentry-postgres:/var/lib/postgresql/data" - pgcat: - image: "ghcr.io/postgresml/pgcat:v1.2.0" + pgbouncer: + image: "edoburu/pgbouncer:v1.24.1-p1" healthcheck: <<: *healthcheck_defaults # Using default user "postgres" from sentry/sentry.conf.example.py or value of POSTGRES_USER if provided @@ -155,11 +155,15 @@ services: depends_on: postgres: <<: *depends_on-healthy - volumes: - - type: bind - read_only: true - source: ./pgcat.toml - target: /etc/pgcat/pgcat.toml + environment: + DB_USER: ${POSTGRES_USER:-postgres} + DB_PASSWORD: sentry + DB_HOST: postgres + DB_NAME: postgres + POOL_MODE: transaction + ADMIN_USERS: postgres,sentry + MAX_CLIENT_CONN: 10000 + kafka: <<: *restart_policy image: "confluentinc/cp-kafka:7.6.1" diff --git a/install/set-up-and-migrate-database.sh b/install/set-up-and-migrate-database.sh index d4b834d4de6..debebd2531d 100644 --- a/install/set-up-and-migrate-database.sh +++ b/install/set-up-and-migrate-database.sh @@ -3,7 +3,7 @@ echo "${_group}Setting up / migrating database ..." if [[ -z "${SKIP_SENTRY_MIGRATIONS:-}" ]]; then # Fixes https://github.com/getsentry/self-hosted/issues/2758, where a migration fails due to indexing issue start_service_and_wait_ready postgres - start_service_and_wait_ready pgcat + start_service_and_wait_ready pgbouncer os=$($dc exec postgres cat /etc/os-release | grep 'ID=debian') if [[ -z $os ]]; then diff --git a/pgcat.toml b/pgcat.toml deleted file mode 100644 index 2dc807ff399..00000000000 --- a/pgcat.toml +++ /dev/null @@ -1,23 +0,0 @@ -# This is an example of the most basic config -# that will mimic what PgBouncer does in transaction mode with one server. - -[general] -host = "0.0.0.0" -port = 5432 -admin_username = "postgres" -admin_password = "sentry" - -[pools.postgres.users.0] -username = "postgres" -password = "sentry" -# Should be at most POSTGRES_MAX_CONNECTIONS from .env. -pool_size = 90 -# We can always eagerly load connections because pgcat will be the only client to the postgres container. -min_pool_size = 90 -pool_mode = "transaction" - -[pools.postgres.shards.0] -servers = [ - ["postgres", 5432, "primary"] -] -database = "postgres" diff --git a/sentry-admin.sh b/sentry-admin.sh index 6942991a181..ef5608488f9 100755 --- a/sentry-admin.sh +++ b/sentry-admin.sh @@ -24,7 +24,7 @@ on the host filesystem. Commands that write files should write them to the '/sen # Actual invocation that runs the command in the container. invocation() { start_service_and_wait_ready postgres - start_service_and_wait_ready pgcat + start_service_and_wait_ready pgbouncer start_service_and_wait_ready redis --wait $dcr --no-deps -v "$VOLUME_MAPPING" -T -e SENTRY_LOG_LEVEL=CRITICAL web "$@" 2>&1 } diff --git a/sentry/sentry.conf.example.py b/sentry/sentry.conf.example.py index 386ef2bb2af..88fb09e4da1 100644 --- a/sentry/sentry.conf.example.py +++ b/sentry/sentry.conf.example.py @@ -48,7 +48,7 @@ def get_internal_network(): "NAME": "postgres", "USER": "postgres", "PASSWORD": "sentry", - "HOST": "pgcat", + "HOST": "pgbouncer", "PORT": "", } } From dd775d156925e8fac55f35ebbb3fad297ba4dd4e Mon Sep 17 00:00:00 2001 From: Frederik Erbs Spang Thomsen Date: Fri, 22 Aug 2025 12:49:12 +0200 Subject: [PATCH 16/16] Revert to TRUST method --- docker-compose.yml | 6 ++---- sentry/sentry.conf.example.py | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 0e39c1c8a4e..77a4a938e48 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -142,8 +142,6 @@ services: ["postgres", "-c", "max_connections=${POSTGRES_MAX_CONNECTIONS:-100}"] environment: POSTGRES_HOST_AUTH_METHOD: "trust" - POSTGRES_USER: "postgres" - POSTGRES_PASSWORD: "sentry" volumes: - "sentry-postgres:/var/lib/postgresql/data" pgbouncer: @@ -151,15 +149,15 @@ services: healthcheck: <<: *healthcheck_defaults # Using default user "postgres" from sentry/sentry.conf.example.py or value of POSTGRES_USER if provided - test: ["CMD-SHELL", "PGPASSWORD=\"sentry\" psql -U postgres -p 5432 -h 127.0.0.1 -tA -c \"select 1;\" -d postgres >/dev/null"] + test: ["CMD-SHELL", "psql -U postgres -p 5432 -h 127.0.0.1 -tA -c \"select 1;\" -d postgres >/dev/null"] depends_on: postgres: <<: *depends_on-healthy environment: DB_USER: ${POSTGRES_USER:-postgres} - DB_PASSWORD: sentry DB_HOST: postgres DB_NAME: postgres + AUTH_TYPE: trust POOL_MODE: transaction ADMIN_USERS: postgres,sentry MAX_CLIENT_CONN: 10000 diff --git a/sentry/sentry.conf.example.py b/sentry/sentry.conf.example.py index 88fb09e4da1..944dc6399b3 100644 --- a/sentry/sentry.conf.example.py +++ b/sentry/sentry.conf.example.py @@ -47,7 +47,7 @@ def get_internal_network(): "ENGINE": "sentry.db.postgres", "NAME": "postgres", "USER": "postgres", - "PASSWORD": "sentry", + "PASSWORD": "", "HOST": "pgbouncer", "PORT": "", }