Skip to content

feat(cnpg): add WAL, checkpoint and monitoring parameters#95

Open
Starefossen wants to merge 3 commits into
mainfrom
feat/cnpg-postgres-tuning
Open

feat(cnpg): add WAL, checkpoint and monitoring parameters#95
Starefossen wants to merge 3 commits into
mainfrom
feat/cnpg-postgres-tuning

Conversation

@Starefossen
Copy link
Copy Markdown
Member

Expand CNPG PostgreSQL tuning based on upstream best practices:

  • WAL: max_wal_size (2% of disk, 1-8GB), wal_compression=zstd,
    wal_buffers (1/32 of shared_buffers)
  • Checkpoints: checkpoint_timeout=10min, bgwriter_lru_maxpages=200
  • Monitoring: track_io_timing=on, pg_stat_statements.track=all
  • HA-only: commit_delay/commit_siblings for group commit
  • Remove shared_preload_libraries (CNPG manages it automatically)

All dynamic values are computed from cluster shape (memory, disk,
highAvailability) — no hardcoded sizes.

Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com

@Starefossen Starefossen requested a review from mortenlj May 19, 2026 12:46
@Starefossen Starefossen marked this pull request as ready for review May 20, 2026 07:48
Copilot AI review requested due to automatic review settings May 20, 2026 07:48
@Starefossen Starefossen force-pushed the feat/cnpg-postgres-tuning branch from f85e7eb to 36d7f4d Compare May 20, 2026 07:48
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Expands CNPG-backed Postgres cluster tuning by deriving additional PostgreSQL configuration parameters (WAL, checkpoints, monitoring, and HA-only group commit) from the cluster’s requested resources and HA setting.

Changes:

  • Compute and set additional CNPG PostgresConfiguration.Parameters (e.g., max_wal_size, wal_buffers, checkpoint_timeout, track_io_timing, HA-only commit_delay/commit_siblings).
  • Refactor parameter generation to accept the full PostgresCluster instead of separate audit/memory inputs.
  • Extend the CNPG basic e2e Chainsaw test to assert creation of monitoring resources.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
tests/e2e/postgres-cnpg-basic/chainsaw-test.yaml Adds assertions for PodMonitor and PrometheusRule resources.
internal/controller/resourcecreator/cnpg.go Adds resource-derived CNPG Postgres parameter tuning (WAL/checkpoints/monitoring/HA group commit).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +79 to +104
- name: Assert PodMonitor created
try:
- assert:
resource:
apiVersion: monitoring.coreos.com/v1
kind: PodMonitor
metadata:
name: mydb
namespace: pg-cnpg-team
labels:
prometheus: tenant
spec:
selector:
matchLabels:
cnpg.io/cluster: mydb
podMetricsEndpoints:
- port: metrics
- name: Assert PrometheusRule created
try:
- assert:
resource:
apiVersion: monitoring.coreos.com/v1
kind: PrometheusRule
metadata:
name: mydb
namespace: pg-cnpg-team
Comment on lines +103 to +104
name: mydb
namespace: pg-cnpg-team
Comment on lines 239 to +259
@@ -248,24 +249,64 @@ func makeCNPGPostgresParameters(audit *data_nais_io_v1.PostgresAudit, memory res
maintenanceWorkMem = maxMaintenanceWorkMemBytes
}

// WAL sizing: ~2% of disk, clamped between 1GB and 8GB
maxWalSize := diskBytes / 50
if maxWalSize < 1*1024*1024*1024 {
maxWalSize = 1 * 1024 * 1024 * 1024
}
if maxWalSize > 8*1024*1024*1024 {
maxWalSize = 8 * 1024 * 1024 * 1024
}
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 20, 2026

Test Results

4 tests   4 ✅  1m 0s ⏱️
4 suites  0 💤
1 files    0 ❌

Results for commit e1387fe.

♻️ This comment has been updated with latest results.

@Starefossen Starefossen force-pushed the feat/cnpg-postgres-tuning branch from 36d7f4d to a8edef3 Compare May 20, 2026 07:55
Starefossen and others added 3 commits May 20, 2026 10:34
Expand CNPG PostgreSQL tuning based on upstream best practices:

- WAL: max_wal_size (2% of disk, 1-8GB), wal_compression=zstd,
  wal_buffers (1/32 of shared_buffers)
- Checkpoints: checkpoint_timeout=10min, bgwriter_lru_maxpages=200
- Monitoring: track_io_timing=on, pg_stat_statements.track=all
- HA-only: commit_delay/commit_siblings for group commit
- Remove shared_preload_libraries (CNPG manages it automatically)

All dynamic values are computed from cluster shape (memory, disk,
highAvailability) — no hardcoded sizes.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add assertions for PodMonitor (with prometheus:tenant label and correct
selector) and PrometheusRule creation in the postgres-cnpg-basic E2E test.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Fix PodMonitor/PrometheusRule E2E assertions: CNPG uses the CR's own
  namespace (not pg-<team>) and names are prefixed with pg-
- Use enforceMinimum2GiDisk() for WAL sizing to align with actual PVC size

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@Starefossen Starefossen force-pushed the feat/cnpg-postgres-tuning branch from bc33969 to e1387fe Compare May 20, 2026 08:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants