# cnpg-cluster

PostgreSQL cluster run by the CloudNativePG operator (Cluster)

This page is generated from [`kix/packages/stable/cnpg-cluster`](https://github.com/kix-run/kix/tree/main/kix/packages/stable/cnpg-cluster).

| | |
| --- | --- |
| Stability | Stable |
| `package` value | `packages.cnpg-cluster` |
| Default aliases | `postgres` |

## Dependencies

Kix matches each dependency below to another package instance by instance name, alias, or role. To bind a specific instance, set [`deps.<name>`](/docs/reference/instances-and-composition/#deps) in your cluster definition. See [Declaring dependencies](/docs/reference/package-anatomy/#declaring-dependencies) for how required and optional dependencies work.

| Dependency | Requirement |
| --- | --- |
| `cnpgOperator` | Required |
| `barmanCloud` | Optional |
| `cloudIdentity` | Optional |
| `endpointService` | Optional |
| `importCa` | Optional |
| `importPassword` | Optional |
| `importSource` | Optional |
| `prometheus` | Optional |
| `storageClasses` | Optional |
| `storageCredentials` | Optional |

## Options

### `backup`

WAL archiving and scheduled base backups to S3 through the Barman Cloud
plugin. Requires the `barmanCloud` and `storageCredentials` dependencies
when set. Pass a Secret instance with S3 access keys or an AWS IAM role
(`kix.cloudIdentity.aws { roleArn = "..."; }`) as `storageCredentials`.

- **Type:** `null or (submodule)`
- **Default:** `null`

### `backup.credentialKeys.accessKeyId`

Key in the `storageCredentials` Secret that holds `accessKeyId`. Defaults to `accessKeyId` when `null`. Cannot be set when `storageCredentials` is a cloud identity.

- **Type:** `null or non-empty string`
- **Default:** `null`

### `backup.credentialKeys.region`

Key in the `storageCredentials` Secret that holds the S3 region. When `null`, no region key is read from the Secret. Cannot be set when `storageCredentials` is a cloud identity.

- **Type:** `null or non-empty string`
- **Default:** `null`

### `backup.credentialKeys.secretAccessKey`

Key in the `storageCredentials` Secret that holds `secretAccessKey`. Defaults to `secretAccessKey` when `null`. Cannot be set when `storageCredentials` is a cloud identity.

- **Type:** `null or non-empty string`
- **Default:** `null`

### `backup.destinationPath`

Where WAL and base backups go, as `s3://<bucket>[/<prefix>]` (`configuration.destinationPath`). The plugin writes under `serverName`.

- **Type:** `string matching the pattern s3://[^/]+(/.*)?`
- **Example:** `"s3://pg-backups/main"`

### `backup.endpointScheme`

Scheme of the `endpointService` dependency's URL in `configuration.endpointURL` (null means `http`). Set only with an `endpointService` dependency.

- **Type:** `null or one of "http", "https"`
- **Default:** `null`

### `backup.extraSpec`

Merged over the `ObjectStore` spec. Refused:
`configuration.destinationPath`, `configuration.s3Credentials`,
`retentionPolicy`, and, with an `endpointService` dependency,
`configuration.endpointURL`. An `endpointURL` pointing to an
in-cluster `.svc` hostname is refused; wire `endpointService`
instead.

- **Type:** `attribute set of anything`
- **Default:** `{ }`
- **Example:**

  ```nix
  {
    configuration = {
      endpointURL = "https://s3.example.com";
      wal = {
        compression = "gzip";
      };
    };
  }
  ```

### `backup.retention`

Retention window (`retentionPolicy` on ObjectStore): a number followed by `d`, `w`, or `m`. Null keeps everything.

- **Type:** `null or string matching the pattern [1-9][0-9]*[dwm]`
- **Default:** `null`
- **Example:** `"30d"`

### `backup.schedule`

When to take a base backup (`spec.schedule` on ScheduledBackup): six cron fields with seconds first, or `@yearly`, `@annually`, `@monthly`, `@weekly`, `@daily`, `@midnight`, `@hourly`, or `@every <duration>`.

- **Type:** `non-empty string`
- **Default:** `"0 0 0 * * *"`

### `backup.serverName`

Folder under `destinationPath` that this Cluster archives to
(the plugin's `serverName` parameter). Null uses
`<namespace>-<instance>`.

- **Type:** `null or string matching the pattern [A-Za-z0-9][-A-Za-z0-9._]*`
- **Default:** `null`
- **Example:** `"pg"`

### `extraSpec`

Merged over the `Cluster` spec. Refused: `instances`, `imageName`,
`imageCatalogRef`, `resources`, `storage.size`, `storage.storageClass`,
`affinity.enablePodAntiAffinity`, `monitoring.enablePodMonitor`,
`bootstrap.initdb.import` (set `import` instead), when `backup` is
set, `plugins` and `backup.barmanObjectStore`, and, when `import` is
set, `externalClusters`, `bootstrap.recovery`, and
`bootstrap.pg_basebackup`.
`topologySpreadConstraints` replaces the spread derived from the
availability level, and `enablePDB` replaces the package default.

- **Type:** `attribute set of anything`
- **Default:** `{ }`
- **Example:**

  ```nix
  {
    postgresql = {
      parameters = {
        max_connections = "200";
      };
    };
  }
  ```

### `image`

PostgreSQL operand image (`spec.imageName`). The tag must start with the PostgreSQL version. The `standard` images include contrib extensions, `pgvector`, `pgaudit`, and `pg_failover_slots`.

- **Type:** `submodule`
- **Default:**

  ```nix
  {
    digest = "sha256:37fdeea29a4d3ed14570f719488ba55bd21e8975eaea864be5ce74d25a9a13de";
    pullPolicy = "IfNotPresent";
    repository = "ghcr.io/cloudnative-pg/postgresql";
    tag = "18.7-standard-trixie";
  }
  ```

### `image.digest`

Resolved manifest digest, `sha256:` followed by 64 hex characters. What will actually run. Null means not resolved.

- **Type:** `null or string`
- **Default:** the package's digest while `tag` is the package's tag, otherwise null

### `image.note`

Whatever a person wanted to say about this pin. Kix never reads it and a promotion never discards it. Declared here for the same reason as the three fields above: a pin carries its own record-keeping, and the option accepts the whole pin rather than a subset of it.

- **Type:** `null or string`
- **Default:** `null`

### `image.promotedBy`

Who resolved this pin, for the record. Null when unknown.

- **Type:** `null or string`
- **Default:** `null`

### `image.pullPolicy`

imagePullPolicy for containers using this image. Null leaves it to Kubernetes.

- **Type:** `null or string`
- **Default:** `"IfNotPresent"`

### `image.repository`

Image repository, registry host included.

- **Type:** `string`
- **Default:** `"ghcr.io/cloudnative-pg/postgresql"`

### `image.resolvedAt`

When this pin was resolved, RFC 3339. Null when unknown.

- **Type:** `null or string`
- **Default:** `null`

### `image.sourceRev`

Revision of the source the image was built from, when Kix built it. Null for upstream images.

- **Type:** `null or string`
- **Default:** `null`

### `image.tag`

Image tag. What was asked for.

- **Type:** `string`
- **Default:** `"18.7-standard-trixie"`

### `import`

Copy databases from another PostgreSQL server when the Cluster is
created (`bootstrap.initdb.import`). CloudNativePG runs `pg_dump`
against the source and `pg_restore` into the new primary, once,
before the instance starts. Writes to the source after that are not
copied, so stop them before the first deploy. The source can run an
older major version. Requires the `importSource` and `importPassword`
dependencies when non-null.

- **Type:** `null or (submodule)`
- **Default:** `null`

### `import.databases`

Databases to copy from the source. `microservice` takes exactly one; `monolith` also takes `*` for every database.

- **Type:** `non-empty (list of non-empty string)`
- **Example:**

  ```nix
  [
    "registry"
  ]
  ```

### `import.extraSpec`

Merged over `bootstrap.initdb.import`. Refused: `type`, `databases`, `roles`, and `source`. CloudNativePG runs `postImportApplicationSQL` after a microservice import only, so it is refused on a monolith import.

- **Type:** `attribute set of anything`
- **Default:** `{ }`
- **Example:**

  ```nix
  {
    pgDumpExtraOptions = [
      "--jobs=2"
    ];
    postImportApplicationSQL = [
      "ANALYZE"
    ];
  }
  ```

### `import.passwordKey`

Key of the `importPassword` Secret that holds the password of `user`.

- **Type:** `non-empty string`
- **Default:** `"password"`

### `import.roles`

Roles to copy, with `monolith` only. `*` copies every role.

- **Type:** `list of non-empty string`
- **Default:** `[ ]`

### `import.sourceDatabase`

Database the import first connects to on the source (`connectionParameters.dbname`).

- **Type:** `non-empty string`
- **Default:** `"postgres"`

### `import.sslMode`

libpq `sslmode` for the connection to the source. `verify-ca`
and `verify-full` check the source's certificate against the
`importCa` dependency, so they need one. `require` encrypts
the connection without checking whose certificate it is.

- **Type:** `one of "disable", "allow", "prefer", "require", "verify-ca", "verify-full"`
- **Default:** `"verify-full"`

### `import.type`

`microservice` copies one database into the application
database (`bootstrap.initdb.database`, owned by
`bootstrap.initdb.owner`) and no roles. `monolith` copies the
listed databases and roles and keeps their owners.

- **Type:** `one of "microservice", "monolith"`
- **Default:** `"microservice"`

### `import.user`

Role the import connects as. It must be able to read every object in the databases, and with `monolith`, the roles.

- **Type:** `non-empty string`
- **Example:** `"postgres"`

### `instances`

PostgreSQL instances (`spec.instances`): one primary, the rest streaming replicas the operator fails over to.

- **Type:** `positive integer, meaning >0`
- **Default:** `kix.availability.pick availability { none = 1; pod = 2; node = 2; zone = 2; }`

### `metrics.enabled`

Enable metrics endpoint and monitoring resources (ServiceMonitor, PrometheusRules) when prometheus is available.

- **Type:** `boolean`
- **Default:** `true`

### `metrics.interval`

Scrape interval (e.g. "30s"). Null = use Prometheus default.

- **Type:** `null or string`
- **Default:** `null`

### `metrics.maxBackupAge`

Maximum age of the last completed base backup before `CNPGBackupMissing` fires, as a Prometheus duration. Null derives it from `backup.schedule` via `kix.schedules.staleAfter` (two periods plus two hours). Must be set explicitly when `backup.schedule` has no derivable period.

- **Type:** `null or string matching the pattern ([0-9]+(ms|s|m|h|d|w|y))+`
- **Default:** `null`
- **Example:** `"15d"`

### `metrics.maxReplicationLag`

Maximum replay lag before `CNPGReplicationLagHigh` fires, as a Prometheus duration.

- **Type:** `string matching the pattern ([0-9]+(ms|s|m|h|d|w|y))+`
- **Default:** `"5m"`
- **Example:** `"30s"`

### `resources`

Container resource requests and limits. Each field keeps its default until set, and null removes a default.

- **Type:** `submodule`
- **Default:**

  ```nix
  {
    limits = {
      cpu = "1";
      memory = "2Gi";
    };
    requests = {
      cpu = "1";
      memory = "2Gi";
    };
  }
  ```

### `resources.claims`

Dynamic resource claims the container uses. Null leaves it unset.

- **Type:** `null or (list of (submodule))`
- **Default:** `null`

### `resources.claims.*.name`

Name of an entry in the pod's `resourceClaims`.

- **Type:** `string`

### `resources.claims.*.request`

Request within the claim to use. Null uses the whole claim.

- **Type:** `null or string`
- **Default:** `null`

### `resources.limits`

Resource quantities by name.

- **Type:** `open submodule of attribute set of Kubernetes quantity, such as "500m" or "1Gi" (a non-negative decimal or integer with an optional suffix m, k, M, G, T, P, E, Ki, Mi, Gi, Ti, Pi or Ei)`
- **Default:** `{ }`

### `resources.limits.cpu`

The cpu quantity. Null leaves it unset.

- **Type:** `null or Kubernetes quantity, such as "500m" or "1Gi" (a non-negative decimal or integer with an optional suffix m, k, M, G, T, P, E, Ki, Mi, Gi, Ti, Pi or Ei)`
- **Default:** `"1"`

### `resources.limits.ephemeral-storage`

The ephemeral-storage quantity. Null leaves it unset.

- **Type:** `null or Kubernetes quantity, such as "500m" or "1Gi" (a non-negative decimal or integer with an optional suffix m, k, M, G, T, P, E, Ki, Mi, Gi, Ti, Pi or Ei)`
- **Default:** `null`

### `resources.limits.memory`

The memory quantity. Null leaves it unset.

- **Type:** `null or Kubernetes quantity, such as "500m" or "1Gi" (a non-negative decimal or integer with an optional suffix m, k, M, G, T, P, E, Ki, Mi, Gi, Ti, Pi or Ei)`
- **Default:** `"2Gi"`

### `resources.requests`

Resource quantities by name.

- **Type:** `open submodule of attribute set of Kubernetes quantity, such as "500m" or "1Gi" (a non-negative decimal or integer with an optional suffix m, k, M, G, T, P, E, Ki, Mi, Gi, Ti, Pi or Ei)`
- **Default:** `{ }`

### `resources.requests.cpu`

The cpu quantity. Null leaves it unset.

- **Type:** `null or Kubernetes quantity, such as "500m" or "1Gi" (a non-negative decimal or integer with an optional suffix m, k, M, G, T, P, E, Ki, Mi, Gi, Ti, Pi or Ei)`
- **Default:** `"1"`

### `resources.requests.ephemeral-storage`

The ephemeral-storage quantity. Null leaves it unset.

- **Type:** `null or Kubernetes quantity, such as "500m" or "1Gi" (a non-negative decimal or integer with an optional suffix m, k, M, G, T, P, E, Ki, Mi, Gi, Ti, Pi or Ei)`
- **Default:** `null`

### `resources.requests.memory`

The memory quantity. Null leaves it unset.

- **Type:** `null or Kubernetes quantity, such as "500m" or "1Gi" (a non-negative decimal or integer with an optional suffix m, k, M, G, T, P, E, Ki, Mi, Gi, Ti, Pi or Ei)`
- **Default:** `"2Gi"`

### `storage.size`

Size of each instance's data volume (`spec.storage.size`).

- **Type:** `Kubernetes quantity, such as "500m" or "1Gi" (a non-negative decimal or integer with an optional suffix m, k, M, G, T, P, E, Ki, Mi, Gi, Ti, Pi or Ei)`
- **Default:** `"20Gi"`

### `storage.storageClass`

StorageClass of the data volumes. Null takes the `storageClasses` dependency's class, or the cluster's default class without one.

- **Type:** `null or non-empty string`
- **Default:** `null`