Files
cozystack/packages/apps/postgres
Aleksei Sviridkin 590e388b94 fix(postgres): rebuild indexes on C.UTF-8 when the Debian release changes (#5478)
## What this PR does

Refs #5459 (item 1: `C.UTF-8` is not repaired and nobody is warned).

After the move to the `-standard-trixie` operand images, an index on a
`COLLATE "C.UTF-8"` column, or any text index in a database created with
`LC_COLLATE 'C.UTF-8'`, is silently corrupt: Debian bullseye's patched
`C.UTF-8` and the glibc 2.35+ `C.UTF-8` order characters differently,
but PostgreSQL records no collation version for `C.*` locales, so the
collation repair in the init Job never selected those indexes. On
PostgreSQL 15+ there was not even a warning. Lookups through such an
index miss rows, and a unique index on it stops seeing duplicates.

One commit. The repair pass now treats libc `C.<codeset>` collations,
and a libc `C.<codeset>` database default, as versioned by the Debian
release of the server's build (the `pgdgNN` suffix of `server_version`).
Their indexes then go through the existing resumable rebuild path (OID
mark, in-place handling for exclusion constraints, `_ccnew` leftovers,
unique-duplicate failure reporting), which this PR leaves unchanged.
Because PostgreSQL stores nothing to compare with, the release each
database was last repaired for is stored in a new per-database setting,
`cozystack.collation_release`, next to the existing
`cozystack.collation_repair`:

- a database without the setting gets the release of the server the pass
first sees it on. The pass looks before it waits for the rollout, so the
old release is persisted even if that run fails, and a retry that runs
after the primary restarted still rebuilds;
- if the server already runs the new glibc when the pass first sees the
database, a libc collation whose recorded version differs from the
server's (`en_US.utf8` 2.31 vs 2.41, present in every database created
from these images) marks it as not repaired for any release;
- otherwise (a new cluster, a database added later) the current release
is recorded and nothing is rebuilt;
- the setting is updated to the current release only when the database
is repaired without failures.

The PG<15 warning `database ... uses the locale C.UTF-8, for which this
PostgreSQL major records no collation version ...` no longer fires for
`C.*` locales, since those are now repaired. The range-partition warning
says for a `C.*` key that it is reported only once, instead of claiming
that a collation version was left as recorded.

The e2e postgres suite now also sets another release on its database,
creates a unique `C.utf8` column, and checks that the upgrade rebuilds
that index, that amcheck passes on it, and that the setting ends at the
server's release.

The change stays inside the `== refresh collation versions` SQL prelude
and its final block. It does not touch the rollout wait, the per-index
rebuild session or the extension section, which other open fixes for
#5459 change.

### What it cannot see

A cluster where a pass without this change already ran on the new glibc
(v1.7.2-rc.1, or `main` since #5405) has already refreshed its libc
collation versions, so no trace of the move is left. This pass then
records the current release for it and does not rebuild its `C.*`
indexes. Rebuild those by hand with `REINDEX INDEX CONCURRENTLY` (or
`REINDEX DATABASE`), as the release note says.

### Coordination with #5472

#5472, now merged, told operators in the `allowCollationChange`
description to rebuild indexes on `C.UTF-8` by hand. This PR merges
second, so it drops that sentence from `values.yaml`, `types.go`, the
README, the schema and the cozyrd: the init Job now rebuilds those
indexes itself.

### Testing

Docker, no Kubernetes: data written on
`ghcr.io/cloudnative-pg/postgresql:17.7` / `13.22` (bullseye, glibc
2.31, `pgdg11`), then the same data directory started on
`17.12-standard-trixie` / `13.22-standard-trixie` (glibc 2.41,
`pgdg13`). The repair section was rendered with `helm template`,
extracted from the init-script Secret, and run from a container of the
trixie image with the env the Job sets (`PGHOST`, `PGUSER`,
`JOB_DEADLINE`). Data: 200,000 distinct keys mixing ASCII punctuation,
`é`, U+FFFD, U+FFFF, U+1D400 and U+1F600. Tables: a `UNIQUE` column
`COLLATE "C.UTF-8"`, an `en_US.utf8` column, a plain `C` column, and a
`cutf8db` database with `LC_COLLATE 'C.UTF-8'`.

| Scenario | Result |
| --- | --- |
| Pass from `main`, PG17 and PG13 | rebuilds only the `en_US.utf8`
index; `t_c_k_key`: `item order invariant violated`, 178,162 of 200,000
keys not found; `cutf8db.t_d_k`: 179,426 not found |
| This PR, Job starts on bullseye, server then restarts on trixie (PG17,
PG13) | `pgdg11` recorded while waiting; `C.UTF-8` column index,
`C.UTF-8` database default index and `en_US.utf8` index rebuilt; amcheck
ok, 0 misses; plain `C` index keeps its OID |
| This PR, first run times out waiting for the rollout, retry after the
restart (libc versions refreshed by hand in between so only the
persisted release can trigger) | retry rebuilds both `C.*` indexes;
amcheck ok, 0 misses |
| This PR, server already on trixie at first run | detected through the
stale libc collation versions; both `C.*` indexes rebuilt |
| Second and third run | nothing rebuilt, setting stays `pgdg13` |
| New cluster created on trixie | nothing rebuilt, `pgdg13` recorded |
| Range partitions on `C.UTF-8` and on `en_US.utf8` | partition indexes
rebuilt once; the `C.*` partition warned once; later runs rebuild
nothing |

`helm unittest packages/apps/postgres`: 31 suites, 247 tests passed.

Dev cluster (cozystack v1.7.0):

- Setup: an app installed from the v1.7.1 chart (`postgresql:17.7`,
bullseye, 2 instances). In `appdb`, a `UNIQUE` column `COLLATE
"C.UTF-8"` with 50,000 keys built from ASCII letters and punctuation,
`é`, U+FFFD, U+1D400 and U+1F600.
- `helm upgrade` to this branch passed on the first attempt. The init
Job logged `rebuilding index public.t_c_k_key in database appdb: its
collation changed version`.
- Afterwards:
  - the Cluster runs `17.12-standard-trixie`;
  - the index OID changed (16424 → 16507);
- `bt_index_check(t_c_k_key, true)` is clean on the primary, on the
replica and through `-ro`, with 0 lookup misses;
  - `cozystack.collation_release` is `pgdg13`.
- A second upgrade rebuilt nothing.

The extended chainsaw e2e step has not run yet, so CI will be its first
run.

Docker, with the rendered repair pass run against
`17.12-standard-trixie` and `UNIQUE` columns `COLLATE "C.utf8"`:

- A database with no recorded release and a stale libc collation
(`CREATE COLLATION ... (provider = libc, locale = 'en_US.utf8', version
= '0')`): the index is rebuilt and `pgdg13` is recorded.
- A database whose only stale piece is its libc default collation
(`datcollversion` changed): the index is rebuilt, and `pgdg13` is
recorded.
- A fresh database: nothing is rebuilt, and `pgdg13` is recorded.
- A second run rebuilds nothing.

The e2e suite now also covers a database with no recorded release, the
state every existing cluster starts from. That database holds a stale
`en_US.utf8` libc collation and a `UNIQUE` column on `C.utf8`, and the
test asserts the new index OID, `bt_index_check`, and the recorded
release. A libc collation on locale `C` with an explicit version cannot
serve as the probe: `ALTER COLLATION ... REFRESH VERSION` refuses to
move it to the NULL version of a `C` locale.

### Downstream repositories

- [ ] No downstream repository is affected by this change
- [ ] [cozystack/website](https://github.com/cozystack/website) -
follow-up:
- [ ]
[cozystack/terraform-provider-cozystack](https://github.com/cozystack/terraform-provider-cozystack)
- follow-up:
- [ ]
[cozystack/ansible-cozystack](https://github.com/cozystack/ansible-cozystack)
- follow-up:
- [ ] [cozystack/ccp](https://github.com/cozystack/ccp) - follow-up:
- [ ] [cozystack/talm](https://github.com/cozystack/talm) - follow-up:
- [ ] [cozystack/cozyhr](https://github.com/cozystack/cozyhr) -
follow-up:
- [ ] [cozystack/cozy-proxy](https://github.com/cozystack/cozy-proxy) -
follow-up:
- [ ]
[cozystack/cozystack-telemetry-server](https://github.com/cozystack/cozystack-telemetry-server)
- follow-up:
- [ ]
[cozystack/external-apps-example](https://github.com/cozystack/external-apps-example)
- follow-up:
- [ ] [cozystack/examples](https://github.com/cozystack/examples) -
follow-up:
- [ ] [cozystack/community](https://github.com/cozystack/community) -
follow-up:

The diff touches only
`packages/apps/postgres/templates/init-script.yaml` and the postgres e2e
test. No values, schema, README, API or CRD change, so none of the
generated reference docs move. Boxes are left empty for a maintainer to
decide: the website may describe the trixie move and its collation
repair in upgrade notes, and if it lists which collations get repaired,
`C.UTF-8` should be added there. I did not check that.

### Release note

```release-note
[postgres] The init Job now also rebuilds indexes on libc `C.UTF-8` (and other `C.<codeset>`) collations, and on databases whose default collation is such a locale, when the server moves to an image built on another Debian release. PostgreSQL records no version for these collations, so before this fix such indexes stayed corrupt after the move to the standard-trixie images, with no warning. The Debian release each database was repaired for is kept in the `cozystack.collation_release` database setting. A cluster that already ran the previous repair on a trixie image (v1.7.2-rc.1 or a `main` build since the move) is not recognised: rebuild its indexes on `C.*` collations by hand with `REINDEX`.
```

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **Bug Fixes**
* PostgreSQL collation repair now detects changes affecting
`C.<codeset>` collations across PostgreSQL build releases, including
cases where PostgreSQL does not record collation versions. Affected
indexes are identified and rebuilt during repair.
* Partition-related warnings clarify when collation changes can or
cannot be detected. After repair, the process records the PostgreSQL
release to help identify when a later repair may be needed.
* **Documentation**
* Updated `allowCollationChange` guidance to explain that the
initialization process rebuilds indexes for `C.UTF-8` and other `C.*`
locales, removing the instruction to rebuild those indexes manually.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

(cherry picked from commit 0f84f1c8dc)
Signed-off-by: Andrey Kolkov <androndo@gmail.com>
2026-12-01 12:54:21 +07:00
..
2024-08-12 14:47:11 +02:00
2025-09-24 12:32:37 +02:00

Managed PostgreSQL Service

PostgreSQL is currently the leading choice among relational databases, known for its robust features and performance. The Managed PostgreSQL Service takes advantage of platform-side implementation to provide a self-healing replicated cluster. This cluster is efficiently managed using the highly acclaimed CloudNativePG operator, which has gained popularity within the community.

Deployment Details

This managed service is controlled by the CloudNativePG operator, ensuring efficient management and seamless operation.

Operations

PostgreSQL backups have two layers, and the recommended setup uses both together rather than picking one:

Layer What it does Configured via
Archive plumbing (chart, legacy) Renders spec.plugins (referencing a barman-cloud ObjectStore) on the cnpg.io Cluster from helm-install onwards. CNPG runs the barman-cloud plugin as a WAL-archiver sidecar, every WAL switch ships to object storage, and any backup driver gets a complete WAL chain to start replay from. Renders only when backup.enabled=true, useSystemBucket=false, destinationPath is non-empty, AND inline-or-external creds are supplied. Skipped in the platform useSystemBucket=true mode — the CNPG backup driver SSA-applies the ObjectStore and patches spec.plugins onto the live Cluster at first BackupJob time; until that first BackupJob fires, plugin WAL archiving is not active and WAL accumulates on the PVC. Fire an ad-hoc BackupJob immediately after enabling the flag on existing releases. Legacy: backup.enabled=true plus backup.destinationPath, backup.endpointURL, and either backup.s3AccessKey+backup.s3SecretKey or backup.s3CredentialsSecret. Platform: backup.enabled=true plus backup.useSystemBucket=true — no S3 fields.
Backup orchestration (recommended) Drives ad-hoc and scheduled backups, retention, and restores from backups.cozystack.io resources that can span multiple Postgres apps in a tenant. The driver SSA-applies its own barman-cloud ObjectStore and patches spec.plugins with ForceOwnership (so compression / target settings flow from the strategy template, while the live Cluster's serverName — its WAL-archive S3 prefix — is always preserved); chart-managed values cover the same destination so there is no tug-of-war on the live Cluster. strategy.backups.cozystack.io/CNPG + BackupClass + Plan (recurring) or BackupJob (ad-hoc), restores via RestoreJob
Legacy chart-emitted scheduled backup The chart can also emit a cnpg.io/ScheduledBackup directly. Superseded by the BackupClass + Plan path, kept around for clusters that did not migrate. Off by default - rendered only when both backup.enabled and backup.schedule are non-empty. With backup.schedule="" plugin WAL archiving still runs; only the chart-emitted scheduled backup is silent. backup.enabled=true plus backup.schedule (five-field cron such as "0 2 * * *", or six fields with leading seconds)

The canonical setup depends on whether the cluster ships the platform cozy-default BackupClass.

Platform-managed flow (recommended for new clusters) — opt in via backup.useSystemBucket: true and reference cozy-default from BackupJob/Plan/RestoreJob. The chart leaves S3 coordinates blank; the CNPG driver SSA-applies a barman-cloud ObjectStore and patches spec.plugins from the platform-managed bucket coordinates at first BackupJob time.

spec:
  backup:
    enabled: true
    useSystemBucket: true        # platform projects cozy-backups-creds + driver SSA-applies ObjectStore + patches spec.plugins

Legacy chart-managed flow — for clusters that pre-date the platform BackupClass or use a tuned non-default bucket. Provide all S3 coordinates inline (or via s3CredentialsSecret.name); spec.plugins and the barman-cloud ObjectStore render from helm-install onwards.

spec:
  backup:
    enabled: true                # archive WAL to object storage
    destinationPath: s3://my-bucket/pg-src/
    endpointURL: https://seaweedfs-s3.tenant-foo:8333
    s3CredentialsSecret:
      name: pg-src-cnpg-backup-creds
    endpointCA:
      name: pg-src-cnpg-backup-ca
    # backup.schedule intentionally left empty - the BackupClass / Plan
    # below drives recurring backups, no chart-emitted ScheduledBackup
    # should compete with that schedule.

paired with a strategy.backups.cozystack.io/CNPG + BackupClass + Plan in the same tenant. The end-to-end e2e fixture under examples/backups/postgres/ is the canonical reference (05-postgres-src.yaml shows the chart side, 10-cnpg-strategy.yaml and 15-backupclass.yaml show the orchestration side, 25-backupjob-adhoc.yaml and 40-restorejob-to-copy.yaml show ad-hoc backup and restore).

Why both layers and not one? WAL archiving is handled by the barman-cloud plugin's WAL-archiver sidecar - CNPG can attach or detach the plugin at runtime, but any WAL that closed before the plugin began archiving is gone for good. A backup taken from such a cluster is missing the WAL its begin_wal points at, and recovery later fails with WAL not found. Letting the chart wire the plugin from helm-install removes the race.

How to enable backups (preferred: BackupClass + Plan)

End-to-end manifests live under examples/backups/postgres/. Briefly, the moving parts are:

  1. A strategy.backups.cozystack.io/CNPG describing the destination bucket and templating the barman-cloud ObjectStore (including a Secret reference to S3 credentials - the credentials never appear on the Postgres CR .spec; see Security note below).
  2. A backups.cozystack.io/BackupClass that names the strategy and is selected by an applicationRef matching the Postgres app's Kind/Name.
  3. A backups.cozystack.io/Plan (recurring) or BackupJob (ad-hoc) that references the BackupClass. The controller materialises a Backup artifact when the cnpg.io Backup completes; restores then reference that Backup via RestoreJob.

Both in-place restores (overwrite the source app's data) and to-copy restores (restore into a separate target Postgres app in the same namespace) are supported via the RestoreJob.spec.targetApplicationRef field.

Security: With the BackupClass path, S3 credentials live in a tenant-readable Secret referenced from the strategy template. The CNPG driver forwards that Secret reference into the Postgres app's spec.backup.s3CredentialsSecret on restore, so access keys never land in the Postgres CR .spec, etcd object store, or kubectl get -o yaml output. Prefer this over the chart-managed path whenever possible.

How to enable chart-managed scheduled backups (legacy)

The chart can also emit a cnpg.io/ScheduledBackup directly, without a BackupClass. Superseded by the BackupClass + Plan path above and kept around for clusters that did not migrate. It does not run by default - backup.schedule defaults to an empty string, which gates the chart's ScheduledBackup template off. To turn it on, set a standard five-field cron such as 0 2 * * * for every day at 02:00, or the CloudNativePG six-field form with a leading seconds field such as 0 0 2 * * * for the same time. The chart prepends a 0 seconds field to a five-field value, because CloudNativePG reads the first field as seconds and would otherwise run 0 2 * * * every hour.

On upgrade, an existing backup.schedule: "0 2 * * *" changes from hourly at minute 2 to daily at 02:00. To keep the previous hourly schedule, set backup.schedule: "0 2 * * * *" before upgrading.

## @param backup.enabled Enable plugin WAL archiving + render the chart-managed ScheduledBackup
## @param backup.schedule Cron schedule, five fields or six with leading seconds. Empty means no chart-managed ScheduledBackup
## @param backup.retentionPolicy Retention policy
## @param backup.destinationPath Path to store the backup (i.e. s3://bucket/path/to/folder)
## @param backup.endpointURL S3 Endpoint used to upload data to the cloud
## @param backup.s3AccessKey Access key for S3, used for authentication
## @param backup.s3SecretKey Secret key for S3, used for authentication
backup:
  enabled: true
  retentionPolicy: 30d
  destinationPath: s3://bucket/path/to/folder/
  endpointURL: http://minio-gateway-service:9000
  schedule: "0 2 * * *"  # opt in - empty (the default) means no chart-managed schedule
  s3AccessKey: oobaiRus9pah8PhohL1ThaeTa4UVa7gu
  s3SecretKey: ju3eum4dekeich9ahM1te8waeGai0oog

How to recover a backup (preferred: RestoreJob)

For BackupClass-managed backups, create a backups.cozystack.io/RestoreJob that references the desired Backup. See examples/backups/postgres/35-restorejob-in-place.yaml and examples/backups/postgres/40-restorejob-to-copy.yaml. On a to-copy restore the controller replaces the target app's spec.databases and spec.users with the source-spec snapshot persisted in Backup.status.underlyingResources, so the chart's post-install init-job does not drop the recovered roles or databases.

e2e coverage: the same-namespace to-copy restore (Steps 0-7) leaves the source running and is the deterministic end-to-end signal; it stays a manual / dev-cluster reference flow, not part of the automated e2e suite. The cross-tenant variant (target Postgres in a different tenant from the source's seaweedfs) stays a manual / dev-cluster exercise — reachability is blocked by the per-tenant Cilium egress policy. The in-place restore code path is shipped and is covered at the unit level by TestClusterHasRecoveryBootstrap_TerminatingCluster, TestCNPGBackupWALArchived, TestCNPGPurgeNeeded, and the rest of the internal/backupcontroller/cnpgstrategy_controller_test.go suite.

How to recover a backup (chart-managed bootstrap)

CloudNativePG supports point-in-time-recovery. Recovering a backup is done by creating a new database instance and restoring the data in it.

Create a new PostgreSQL application with a different name, but identical configuration. Set bootstrap.enabled to true and fill in the name of the database instance to recover from and the recovery time:

## @param bootstrap.enabled Restore database cluster from a backup
## @param bootstrap.recoveryTime Timestamp (PITR) up to which recovery will proceed, expressed in RFC 3339 format. If left empty, will restore latest
## @param bootstrap.oldName Name of database cluster before deleting
##
bootstrap:
  enabled: false
  recoveryTime: ""  # leave empty for latest or exact timestamp; example: 2020-11-26 15:22:00.00000+00
  oldName: "<previous-postgres-instance>"

How to switch primary/secondary replica

See:

storageClass is annotated as immutable in the chart schema — see docs/storage-immutability.md for the contract and which consumers enforce it.

TLS for server connections

CNPG manages the cert chain end-to-end. The operator auto-generates a self-signed CA, signs server, client, and replication leaf certs from it, and rotates them as needed. The chart does not render any cert-manager Issuer/Certificate objects — that path is mutually exclusive with the operator-managed chain on the CNPG admission webhook.

What the chart contributes: when TLS is on and external: true, the chart sets spec.certificates.serverAltDNSNames on the CNPG Cluster CR to inject the external hostname <release>.<_namespace.host> into the auto-generated server certificate's SAN list. CNPG's default SAN coverage already includes the three built-in ClusterIP services (-rw, -r, -ro) across the four DNS forms (<svc>, <svc>.<ns>, <svc>.<ns>.svc, <svc>.<ns>.svc.<cluster-domain>); only the external hostname needs to be added.

The tri-state tls.enabled controls whether the chart injects serverAltDNSNames:

  • tls.enabled: null (the default) — TLS posture inherits from external. When external: true, the chart injects the external hostname into the operator-managed cert.
  • tls.enabled: true with external: true — same effect as the default.
  • tls.enabled: true with external: false — no serverAltDNSNames injection is needed (there is no external hostname to add); CNPG's auto-generated cert covers internal services.
  • tls.enabled: false — the chart skips serverAltDNSNames injection. Note: CNPG keeps its built-in TLS on the wire regardless of this flag; this toggle only controls whether the external hostname is added to the cert. To force PostgreSQL to drop TLS entirely you would need to set postgresql.parameters.ssl = "off" at the CNPG layer, which is out of scope for this flag.

Retrieving the CA bundle for client verification:

CNPG bundles the CA certificate in every user-credentials Secret it creates under the key ca.crt. Retrieve it from the <release>-credentials Secret, which is already accessible to tenants via the dashboard RBAC:

kubectl --context <ctx> --namespace <tenant> \
  get secret <release>-credentials \
  --output jsonpath='{.data.ca\.crt}' | base64 --decode

Connecting with full verification (psql example):

psql "host=<host> port=5432 dbname=app user=app \
  sslmode=verify-full sslrootcert=ca.crt"

For sslmode=verify-full to work, the CA bundle retrieved above must be saved to ca.crt. Without it, use sslmode=require (encrypts but does not verify the server certificate).

Parameters

Common parameters

Name Description Type Value
replicas Number of Postgres replicas. int 2
resources Explicit CPU and memory configuration for each PostgreSQL replica. When omitted, the preset defined in resourcesPreset is applied. object {}
resources.cpu CPU available to each replica. quantity ""
resources.memory Memory (RAM) available to each replica. quantity ""
resourcesPreset Default sizing preset used when resources is omitted. string t1.micro
size Persistent Volume Claim size available for application data. quantity 10Gi
storageClass StorageClass used to store the data. string ""
external Enable external access from outside the cluster. bool false
version PostgreSQL major version to deploy string v18
allowCollationChange Allow a cluster created on a Debian bullseye image (before the move to standard-trixie) to move to the new image without a clean locale check. Such a cluster is checked before each upgrade, except while bootstrap.enabled is set (set it back to false once a restore set up by hand has finished), and stays on its current image until the check finds nothing that depends on a collation other than C, POSIX or builtin: while this is false, a cluster the check found affected (an ICU or libc locale, or C.UTF-8) or could not finish on stays put, because glibc and ICU on the new image sort text differently and every index on such text must be rebuilt. A held cluster runs the bare bullseye tag it has, gets no further PostgreSQL minors and so none of their security fixes, and refuses a change of version, since new majors are built only on the new images. To leave that state, either remove the dependency (move such columns and indexes to C, or to the builtin pg_c_utf8 on PostgreSQL 17 and later) and let the next upgrade check again, or set this to true in a maintenance window: the cluster moves on the next upgrade, replicas restart on the new image first and can return wrong results through -ro, and unique indexes can accept duplicates, until the indexes are rebuilt on the primary. The init Job rebuilds the indexes on such text, those on C.UTF-8 and other C.* locales included; check range partitions, CHECK constraints and materialized views on it, which a rebuild does not fix. A held cluster shows the hold only as an unchanged image; the result and the objects found are in the postgres.cozystack.io/locale-data and postgres.cozystack.io/locale-data-objects annotations of the cnpg.io Cluster, which an administrator can read. A restore of a backup taken on one of those bullseye images comes back on that image and is checked by the next upgrade. bool false

TLS configuration

Name Description Type Value
tls TLS configuration for server connections. object {}
tls.enabled Tri-state switch controlling whether the chart injects the external hostname into the operator-managed CNPG cert via spec.certificates.serverAltDNSNames. When omitted, the chart injects the SAN if external: true and skips it otherwise. Set explicitly to true to inject regardless of external (no-op when external: false since there is no external hostname to add). Set to false to skip injection. Note that CNPG keeps its built-in TLS on the wire regardless of this flag — this toggle only controls the chart-side SAN injection; to disable PostgreSQL TLS entirely set postgresql.parameters.ssl = "off" at the CNPG layer. *bool null

Application-specific parameters

Name Description Type Value
postgresql PostgreSQL server configuration. object {}
postgresql.parameters PostgreSQL server parameters. Values may be strings or integers; integers are coerced to strings by the template (e.g. both max_connections: 100 and max_connections: "100" are accepted). BLOCKED (enable arbitrary code execution): archive_command, restore_command, ssl_passphrase_command, archive_cleanup_command, recovery_end_command, dynamic_library_path, local_preload_libraries, session_preload_libraries, shared_preload_libraries. Do NOT override CloudNativePG-managed parameters: archive_mode, primary_conninfo, wal_level, max_replication_slots. map[string]intOrString {}

Quorum-based synchronous replication

Name Description Type Value
quorum Quorum configuration for synchronous replication. object {}
quorum.minSyncReplicas Minimum number of synchronous replicas required for commit. int 0
quorum.maxSyncReplicas Maximum number of synchronous replicas allowed (must be less than total replicas). int 0

Users configuration

Name Description Type Value
users Users configuration map. map[string]object {}
users[name].password Password for the user. string ""
users[name].replication Whether the user has replication privileges. bool false

Databases configuration

Name Description Type Value
databases Databases configuration map. map[string]object {}
databases[name].roles Roles assigned to users. object {}
databases[name].roles.admin List of users with admin privileges. []string []
databases[name].roles.readonly List of users with read-only privileges. []string []
databases[name].extensions List of enabled PostgreSQL extensions. []string []

Backup parameters

Name Description Type Value
backup Backup configuration. object {}
backup.enabled Enable regular backups. bool false
backup.useSystemBucket Opt-in: when true, the chart-emitted <release>-s3-creds Secret is skipped AND spec.plugins (plus the barman-cloud ObjectStore) is left UNSET in the chart-rendered Cluster — the cozy-default BackupClass driver SSA-applies an ObjectStore (carrying destinationPath/endpointURL/credentials) and patches spec.plugins on the live Cluster when the first BackupJob runs. Consequence: plugin WAL archiving is NOT active until that first BackupJob fires; WAL accumulates on the PVC in the meantime, so fire an ad-hoc BackupJob immediately after enabling the flag on existing releases. Use together with the platform cozy-default BackupClass — tenants do not need to fill s3AccessKey/s3SecretKey or destinationPath/endpointURL. The destination path automatically scopes to s3://cozy-backups/<namespace>/<release>/. bool false
backup.schedule Legacy. Cron schedule for the chart-emitted ScheduledBackup, either a standard five-field cron such as 0 2 * * * for every day at 02:00, or six fields with leading seconds such as 0 0 2 * * * for the same time. Empty means no chart-managed schedule, which is the recommended setup when a BackupClass from backups.cozystack.io already drives backup orchestration. In the legacy chart-managed flow spec.plugins plus the barman-cloud ObjectStore is rendered when backup.enabled=true AND useSystemBucket=false AND destinationPath is non-empty AND inline-or-external creds are supplied; in the platform useSystemBucket=true flow the chart skips emitting spec.plugins and the CNPG driver SSA-applies the ObjectStore and patches spec.plugins onto the live Cluster at first BackupJob time. string ""
backup.retentionPolicy Retention policy (e.g. "30d"). string 30d
backup.destinationPath DEPRECATED. Per-tenant S3 configuration is superseded by the platform-managed cozy-default BackupClass and the cozy-backups system bucket. Leave empty for new installations; the BackupClass driver picks up the system-managed coordinates. Kept for in-place upgrade compatibility. string s3://bucket/path/to/folder/
backup.endpointURL DEPRECATED. See destinationPath. string http://minio-gateway-service:9000
backup.s3AccessKey DEPRECATED. Tenants no longer supply S3 keys; the system Bucket Secret is projected into the tenant namespace by the backup controller. Ignored when s3CredentialsSecret.name is set or useSystemBucket is true. The chart skips materialising <release>-s3-creds whenever this field is empty so a default install does not leak placeholder credentials into the tenant namespace. string ""
backup.s3SecretKey DEPRECATED. See s3AccessKey. string ""
backup.s3CredentialsSecret DEPRECATED. Pre-existing Secret with S3 credentials. Use the platform-managed cozy-default BackupClass instead. When set, the chart references this Secret directly (legacy chart-managed flow). The CNPG backup driver writes this field on restore so credentials never land in the CR .spec. object {}
backup.s3CredentialsSecret.name Name of the Secret in the application namespace. Empty means the chart materialises <release>-s3-creds from s3AccessKey/s3SecretKey. string ""
backup.s3CredentialsSecret.accessKeyIDKey Key in the Secret holding the access key ID. Defaults to AWS_ACCESS_KEY_ID. string ""
backup.s3CredentialsSecret.secretAccessKeyKey Key in the Secret holding the secret access key. Defaults to AWS_SECRET_ACCESS_KEY. string ""
backup.endpointCA DEPRECATED. Pre-existing Secret with the CA bundle the barman-cloud plugin should trust when reaching a self-signed S3 endpoint. Used for both backup and bootstrap recovery in the legacy chart-managed flow. object {}
backup.endpointCA.name Name of the Secret in the application namespace. Empty means no endpointCA is emitted (the plugin uses the system trust store). string ""
backup.endpointCA.key Key within the Secret containing the CA bundle. Defaults to ca.crt. string ""

Bootstrap (recovery) parameters

Name Description Type Value
bootstrap Bootstrap configuration. object {}
bootstrap.enabled Whether to restore from a backup. bool false
bootstrap.recoveryTime Timestamp (RFC3339) for point-in-time recovery; empty means latest. string ""
bootstrap.oldName Previous cluster name before deletion. string ""
bootstrap.serverName Server name (S3 path prefix) used by the original cluster when writing backups; passed to the barman-cloud plugin via externalClusters[].plugin.parameters.serverName. Defaults to bootstrap.oldName. Set this only when the original cluster wrote backups under an explicit server name that differed from its Kubernetes resource name. string ""
bootstrap.newServerName WAL-archive server name (S3 path prefix) the RESTORED cluster writes to. Must differ from serverName (the recovery source) so a restored cluster archives to a fresh, empty prefix and barman-cloud-check-wal-archive passes while it recovers from the source's prefix. The CNPG backup driver sets this on restore; empty means the cluster archives under its own name. string ""
bootstrap.sourceImageName Image of the cluster the backup was taken from. A restore of a backup taken on one of the bare Debian bullseye tags the chart used before standard-trixie comes back on that image (see allowCollationChange); any other value is ignored. The CNPG backup driver sets this on restore and clears it with enabled. string ""

Parameter examples and reference

resources and resourcesPreset

resources sets explicit CPU and memory configurations for each replica. When left empty, the preset defined in resourcesPreset is applied.

resources:
  cpu: 4000m
  memory: 4Gi

resourcesPreset sets named CPU and memory configurations for each replica. This setting is ignored if the corresponding resources value is set.

Presets follow a cloud-style <series>.<size> naming convention. Five series cover the full CPU-to-memory ratio range (t1 1:0.5, c1 1:1, s1 1:2, u1 1:4, m1 1:8) and each series ships eight sizes (nano through 4xlarge). The legacy flat names (nano, micro, small, medium, large, xlarge, 2xlarge) remain accepted as deprecated aliases of their 1:1 instance-type equivalents.

See docs/operations/resource-presets.md for the full size matrix and the legacy-to-instance-type mapping.

users

users:
  user1:
    password: strongpassword
  user2:
    password: hackme
  airflow:
    password: qwerty123
  debezium:
    replication: true

databases

databases:          
  myapp:            
    roles:          
      admin:        
      - user1       
      - debezium    
      readonly:     
      - user2       
  airflow:          
    roles:          
      admin:        
      - airflow     
    extensions:     
    - hstore