Files
computer-playbook/roles/sys-svc-rdbms/templates/services/postgres.yml.j2
kevinveenbirkenbachandClaude Opus 5.5 807cfbcefe 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) <noreply@anthropic.com>
2026-10-01 22:19:10 +02:00

45 lines
1.9 KiB
Django/Jinja

{# This template needs to be included in compose.yml, which depend on a postgres database #}
{% if lookup('database', application_id, 'local') %}
{% set _extensions = lookup('service_extensions', 'postgres').get(application_id, []) %}
{% set _libraries = lookup('postgres_libraries', _extensions) %}
{{ lookup('database', application_id, 'host') }}:
{{ lookup('container_deploy', replicas=1) | indent(4) }}
{{ lookup('compose_only', 'container_name', ((application_id | get_entity_name) ~ '-database')) }}
{% if _libraries | length > 0 %}
{{ lookup('container_image', 'svc-db-postgres', 'postgres', image=(application_id | get_entity_name ~ '-database'), version=lookup('database', application_id, 'version')) }}
{{ lookup('compose_only', 'pull_policy', 'never') }}
build:
context: {{ lookup('database', application_id, 'build_dir') }}
dockerfile: Dockerfile
{% 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') }}
healthcheck:
test: ["CMD-SHELL", "pg_isready -h 127.0.0.1 -U {{ lookup('database', application_id, 'username') }}"]
interval: 2m
timeout: 5s
retries: 6
start_period: 10m
start_interval: 5s
volumes:
- type: volume
source: database
target: /var/lib/postgresql
{% if _extensions | length > 0 %}
- type: bind
source: {{ lookup('database', application_id, 'initdb_dir') }}
target: /docker-entrypoint-initdb.d
read_only: true
{% endif %}
networks: # nocheck: networks-literal local sidecar inside consumer stack, default-only attachment
- default
{% endif %}
{{ "\n" }}