Files
cozystack/packages/apps/postgres/tests/shared_buffers_test.yaml
Yan Bondarenko 9c0085c358 fix(postgres): cap shared_buffers at the memory request
CloudNativePG rejects clusters whose shared_buffers exceeds the memory
request. Memory overcommit can put that request below both a quarter of
the limit and the 16MB floor.

Assisted-by: LLM
Signed-off-by: Yan Bondarenko <202671653+yankawai@users.noreply.github.com>
2026-10-08 22:39:05 +03:00

251 lines
6.3 KiB
YAML

suite: shared_buffers default follows the memory limit and request
# PostgreSQL's built-in shared_buffers default is 128MB regardless of the
# container. Below a 512Mi memory limit the chart defaults it to a quarter of
# the limit with a 16MB floor, capped at the memory request. From 512Mi up
# nothing is rendered, so those instances keep the PostgreSQL default.
templates:
- templates/db.yaml
release:
name: pg-test
namespace: tenant-test
set:
_cluster:
scheduling: {}
tests:
- it: "the default preset (t1.micro, 256Mi) gets 64MB"
documentSelector:
path: kind
value: Cluster
asserts:
- equal:
path: spec.postgresql.parameters.shared_buffers
value: "64MB"
- it: "t1.nano (128Mi) gets 32MB"
set:
resourcesPreset: t1.nano
documentSelector:
path: kind
value: Cluster
asserts:
- equal:
path: spec.postgresql.parameters.shared_buffers
value: "32MB"
- it: "a resources override that sets only cpu keeps the preset memory limit and its 32MB"
set:
resourcesPreset: t1.nano
resources:
cpu: 500m
documentSelector:
path: kind
value: Cluster
asserts:
- equal:
path: spec.resources.limits.memory
value: 128Mi
- equal:
path: spec.postgresql.parameters.shared_buffers
value: "32MB"
- it: "explicit resources with 500Mi memory, just under the threshold, get 125MB"
set:
resources:
cpu: 500m
memory: 500Mi
documentSelector:
path: kind
value: Cluster
asserts:
- equal:
path: spec.postgresql.parameters.shared_buffers
value: "125MB"
- it: "a 32Mi limit is floored at 16MB"
set:
resources:
cpu: 250m
memory: 32Mi
documentSelector:
path: kind
value: Cluster
asserts:
- equal:
path: spec.postgresql.parameters.shared_buffers
value: "16MB"
- it: "t1.small (512Mi) renders no shared_buffers, as before"
set:
resourcesPreset: t1.small
documentSelector:
path: kind
value: Cluster
asserts:
- notExists:
path: spec.postgresql.parameters.shared_buffers
- it: "t1.large (2Gi) renders no shared_buffers, as before"
set:
resourcesPreset: t1.large
documentSelector:
path: kind
value: Cluster
asserts:
- notExists:
path: spec.postgresql.parameters.shared_buffers
- it: "an explicit shared_buffers wins over the default on a small preset"
set:
resourcesPreset: t1.nano
postgresql:
parameters:
shared_buffers: "24MB"
documentSelector:
path: kind
value: Cluster
asserts:
- equal:
path: spec.postgresql.parameters.shared_buffers
value: "24MB"
- it: "an explicit shared_buffers is still rendered on a large preset"
set:
resourcesPreset: t1.large
postgresql:
parameters:
shared_buffers: "1GB"
documentSelector:
path: kind
value: Cluster
asserts:
- equal:
path: spec.postgresql.parameters.shared_buffers
value: "1GB"
- it: "other default parameters are still rendered"
set:
resourcesPreset: t1.nano
documentSelector:
path: kind
value: Cluster
asserts:
- equal:
path: spec.postgresql.parameters.max_connections
value: "100"
- equal:
path: spec.postgresql.parameters.max_wal_senders
value: "30"
- it: "the default preset caps shared_buffers below a fractional memory request"
set:
_cluster:
memory-allocation-ratio: "5"
documentSelector:
path: kind
value: Cluster
asserts:
- equal:
path: spec.resources.requests.memory
value: "53687091"
- equal:
path: spec.postgresql.parameters.shared_buffers
value: "51MB"
- it: "t1.nano caps shared_buffers at the memory request with overcommit"
set:
resourcesPreset: t1.nano
_cluster:
memory-allocation-ratio: "5"
documentSelector:
path: kind
value: Cluster
asserts:
- equal:
path: spec.resources.requests.memory
value: "26843545"
- equal:
path: spec.postgresql.parameters.shared_buffers
value: "25MB"
- it: "a request equal to a quarter of the limit keeps the quarter"
set:
resourcesPreset: t1.nano
_cluster:
memory-allocation-ratio: "4"
documentSelector:
path: kind
value: Cluster
asserts:
- equal:
path: spec.resources.requests.memory
value: "33554432"
- equal:
path: spec.postgresql.parameters.shared_buffers
value: "32MB"
- it: "a memory request below 16Mi takes precedence over the floor"
set:
resources:
memory: 60Mi
_cluster:
memory-allocation-ratio: "4"
documentSelector:
path: kind
value: Cluster
asserts:
- equal:
path: spec.resources.requests.memory
value: "15728640"
- equal:
path: spec.postgresql.parameters.shared_buffers
value: "15MB"
- it: "an explicit memory limit uses its rendered request for the cap"
set:
resources:
memory: 500Mi
_cluster:
memory-allocation-ratio: "5"
documentSelector:
path: kind
value: Cluster
asserts:
- equal:
path: spec.resources.requests.memory
value: "104857600"
- equal:
path: spec.postgresql.parameters.shared_buffers
value: "100MB"
- it: "an explicit shared_buffers still wins when memory is overcommitted"
set:
_cluster:
memory-allocation-ratio: "5"
postgresql:
parameters:
shared_buffers: "40MB"
documentSelector:
path: kind
value: Cluster
asserts:
- equal:
path: spec.postgresql.parameters.shared_buffers
value: "40MB"
- it: "512Mi still renders no default when memory is overcommitted"
set:
resourcesPreset: t1.small
_cluster:
memory-allocation-ratio: "5"
documentSelector:
path: kind
value: Cluster
asserts:
- notExists:
path: spec.postgresql.parameters.shared_buffers