From 807cfbcefeaf17eb5af426c2124dac4e6f6647e2 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Thu, 1 Oct 2026 22:18:38 +0200 Subject: [PATCH] fix(postgres): raise max_locks_per_transaction to 256 GitLab's migration on its dedicated postgres sidecar failed with "ERROR: out of shared memory" and the hint to raise max_locks_per_transaction. The default of 64 locks per transaction cannot cover a schema that locks thousands of tables and indexes in one transaction: a reproduction on postgres:18 failed at table 7453 with the default and held 20000 tables at 256. The value sits next to the other postgres tuning constants in group_vars/all/17_resource.yml and reaches both the central svc-db-postgres command and the per-app sidecar. The sidecar's new command keeps the image entrypoint and only adds the flag. The shared lock table grows to about 256 x max_connections entries, roughly 30 MB at the 400-connection cap. Ported from 7690d2ca6d on feature/store-i18n, which kept the constant in the resource lookup that main no longer has. Co-Authored-By: Claude Opus 5.5 (1M context) --- group_vars/all/17_resource.yml | 1 + roles/svc-db-postgres/templates/compose.yml.j2 | 2 ++ roles/sys-svc-rdbms/templates/services/postgres.yml.j2 | 4 ++++ 3 files changed, 7 insertions(+) diff --git a/group_vars/all/17_resource.yml b/group_vars/all/17_resource.yml index f8a5c48d11..281b5eff75 100644 --- a/group_vars/all/17_resource.yml +++ b/group_vars/all/17_resource.yml @@ -53,6 +53,7 @@ POSTGRES_WORK_MEM_MB: "{{ [ ( (POSTGRES_TOTAL_RAM_MB | int) // ( [ (POSTGRES_MAX POSTGRES_WORK_MEM: "{{ POSTGRES_WORK_MEM_MB ~ 'MB' }}" POSTGRES_MAINTENANCE_WORK_MEM_MB: "{{ [ (((POSTGRES_TOTAL_RAM_MB | int) * 5) // 100), 64 ] | max }}" POSTGRES_MAINTENANCE_WORK_MEM: "{{ POSTGRES_MAINTENANCE_WORK_MEM_MB ~ 'MB' }}" +POSTGRES_MAX_LOCKS_PER_TRANSACTION: 256 POSTGRES_DELAY: 2 TIMEOUT_FACTOR: 1 diff --git a/roles/svc-db-postgres/templates/compose.yml.j2 b/roles/svc-db-postgres/templates/compose.yml.j2 index 5b0170dfda..3136594e5a 100644 --- a/roles/svc-db-postgres/templates/compose.yml.j2 +++ b/roles/svc-db-postgres/templates/compose.yml.j2 @@ -16,6 +16,8 @@ - "work_mem={{ POSTGRES_WORK_MEM }}" - "-c" - "maintenance_work_mem={{ POSTGRES_MAINTENANCE_WORK_MEM }}" + - "-c" + - "max_locks_per_transaction={{ POSTGRES_MAX_LOCKS_PER_TRANSACTION }}" {% include 'roles/sys-svc-container/templates/base.yml.j2' %} {{ lookup('container_healthcheck', service_name) | indent(4) }} diff --git a/roles/sys-svc-rdbms/templates/services/postgres.yml.j2 b/roles/sys-svc-rdbms/templates/services/postgres.yml.j2 index 8336da1ace..41d69882a2 100644 --- a/roles/sys-svc-rdbms/templates/services/postgres.yml.j2 +++ b/roles/sys-svc-rdbms/templates/services/postgres.yml.j2 @@ -15,6 +15,10 @@ {% else %} {{ lookup('container_image', 'svc-db-postgres', 'postgres', image=lookup('database', application_id, 'image'), version=lookup('database', application_id, 'version')) }} {% endif %} + command: + - "postgres" + - "-c" + - "max_locks_per_transaction={{ POSTGRES_MAX_LOCKS_PER_TRANSACTION }}" env_file: - {{ lookup('database', application_id, 'env') }} {{ lookup('compose_restart') }}