# stackgres-cluster

PostgreSQL cluster run by the StackGres operator (SGCluster)

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

| | |
| --- | --- |
| Stability | Experimental |
| `package` value | `packages.experimental.stackgres-cluster` |
| Default aliases | `postgres` |

## How-to guides

- [Deploy StackGres](/docs/how-to/package-task-guides/deploy-stackgres/)

## 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 |
| --- | --- |
| `stackgresOperator` | Required |
| `backupIdentity` | Optional |
| `cloudIdentity` | Optional |
| `prometheus` | Optional |
| `sgObjectStorage` | Optional |
| `storageClasses` | Optional |

## Options

### `backups`

Entries of `spec.configurations.backups`, each wired to the
`sgObjectStorage` dependency's `SGObjectStorage`. Requires that
dependency in this namespace when non-null. Takes at most one entry,
because StackGres schedules backups only from the first entry.

- **Type:** `null or (list of (open submodule of attribute set of anything))`
- **Default:** `null`
- **Example:**

  ```nix
  [
    {
      cronSchedule = "0 1 * * *";
      retention = 7;
    }
  ]
  ```

### `backups.*.compression`

Backup compression. Null takes StackGres's default.

- **Type:** `null or one of "lz4", "lzma", "zstd", "brotli"`
- **Default:** `null`

### `backups.*.cronSchedule`

When to take a base backup, in cron syntax (UTC). Null takes StackGres's default.

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

### `backups.*.reconciliationTimeout`

Seconds StackGres allows, after each backup, for deleting the
base backups and WAL that retention no longer keeps. StackGres's
own default is 300. A database that archives tens of thousands
of WAL segments a day cannot delete them in that time: the
delete is cut off, the backup still succeeds, and the bucket
grows without limit. Null takes StackGres's default.

- **Type:** `null or (positive integer, meaning >0)`
- **Default:** `3600`

### `backups.*.retention`

Base backups to keep. Null takes StackGres's default.

- **Type:** `null or (positive integer, meaning >0)`
- **Default:** `null`

### `extensions`

Extensions the operator installs (`spec.postgres.extensions`). A
`stackgres-database` instance on this cluster injects the extensions it
requests, so list here only extensions no database requests. Entries
with the same name are merged; `vchord` adds `vector` and is preloaded.

- **Type:** `list of (submodule)`
- **Default:** `[ ]`

### `extensions.*.name`

Extension name in the StackGres extensions repository.

- **Type:** `non-empty string`

### `extensions.*.publisher`

Extension publisher. Null takes the repository's default.

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

### `extensions.*.repository`

Base URL of the extensions repository to install from. Null lets the operator choose from its `SGConfig`.

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

### `extensions.*.version`

Extension version. Null takes the repository's default.

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

### `extraSpec`

Merged over the `SGCluster` spec. Refused: `instances`,
`postgres.version`, `postgres.extensions`, `postgres.flavor`,
`sgInstanceProfile`, `configurations.sgPostgresConfig`,
`configurations.sgPoolingConfig`, `configurations.backups`,
`managedSql.scripts`, `pods.persistentVolume.size`,
`pods.persistentVolume.storageClass`, `pods.disableConnectionPooling`,
and `pods.disableEnvoy = false`. `pods.scheduling.topologySpreadConstraints`
replaces the spread derived from the availability level. A
non-production `profile` or
`nonProductionOptions.disableClusterPodAntiAffinity = true` is refused
at availability `node` or `zone` with more than one instance.

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

  ```nix
  {
    pods = {
      scheduling = {
        nodeSelector = {
          "example.com/database" = "true";
        };
      };
    };
  }
  ```

### `instanceProfile`

The `SGInstanceProfile` spec: CPU and memory per instance, and any other `SGInstanceProfile` field.

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

### `instanceProfile.cpu`

CPU per instance, for the PostgreSQL container and the sidecars StackGres sizes from it.

- **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:** `"1"`

### `instanceProfile.memory`

Memory per instance.

- **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:** `"2Gi"`

### `instances`

PostgreSQL instances (`spec.instances`): one primary, the rest streaming replicas that Patroni 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.maxReplicationLag`

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

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

### `persistentVolume.size`

Size of each instance's data volume.

- **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"`

### `persistentVolume.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`

### `pooling`

`SGPoolingConfig` spec. Non-null creates it and enables the PgBouncer
sidecar (`{ }` uses StackGres's defaults). Null runs no pooler, so
clients connect to PostgreSQL directly.

- **Type:** `null or (attribute set of anything)`
- **Default:** `null`
- **Example:**

  ```nix
  {
    pgBouncer = {
      "pgbouncer.ini" = {
        pgbouncer = {
          pool_mode = "transaction";
        };
      };
    };
  }
  ```

### `postgres.version`

PostgreSQL major (`"17"`) or minor (`"17.11"`), checked against the
versions the operator's release ships. A major selects its newest minor
when the cluster is created. Changing the major requires an `SGDbOps` of
type `majorVersionUpgrade`.

- **Type:** `string`
- **Default:** `"17"`

### `postgresqlConf`

`postgresql.conf` parameters, merged over StackGres's defaults and the
keys the package sets (`archive_timeout` when `backups` is set, and
`shared_preload_libraries` when an extension needs preloading). Null
removes a package key.

- **Type:** `attribute set of (null or string)`
- **Default:** `{ }`
- **Example:**

  ```nix
  {
    max_connections = "200";
    work_mem = "16MB";
  }
  ```

### `scripts`

Entries of the `SGScript` the cluster runs once each (`spec.scripts`).

- **Type:** `list of (open submodule of attribute set of anything)`
- **Default:** `[ ]`

### `scripts.*.database`

Database the script runs in. Null runs it in `postgres`.

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

### `scripts.*.name`

Script name, shown in the `SGCluster` status.

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

### `scripts.*.script`

SQL to run. Set this or `scriptFrom`.

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

### `scripts.*.scriptFrom`

A `secretKeyRef` or `configMapKeyRef` holding the SQL. Set this or `script`.

- **Type:** `null or (attribute set of anything)`
- **Default:** `null`