> For the complete documentation index, see [llms.txt](https://docs.cennso.com/cennso/cennso-db/latest/llms.txt) (all documentation: [llms.txt](https://docs.cennso.com/llms.txt)). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.cennso.com/cennso/cennso-db/latest/concepts/cennso-postgresql-operator.md).

# Cennso PostgreSQL Operator

The Cennso PostgreSQL Operator is represented by the `PostgreSQLOperator` Custom Resource (CR) and defines:

- a location where the database operator should be deployed, such as the Management Cluster or the name of the Core Cluster, and a Kubernetes namespace
- a list of Kubernetes namespaces in which the database operator manages the PostgreSQL clusters
- a Kubernetes [Storage Class](https://kubernetes.io/docs/concepts/storage/storage-classes/) for attaching the [Persistent Volumes](https://kubernetes.io/docs/concepts/storage/persistent-volumes/) requested by the database instances

The sections below provide information about configuration parameters that you can specify in the `PostgreSQLOperator` CR. For more information on how to configure and deploy the database operator, see the [Deploy Cennso PostgreSQL](https://docs.cennso.com/cennso/cennso-db/latest/deployment-guides/cennso-postgresql.md) and [Cennso PostgreSQL Operator Custom Resource Definition](https://docs.cennso.com/cennso/cennso-db/latest/technical-reference/configurations/cennso-postgresql/xpostgresqloperator_definition.md) documents.

## Kubernetes cluster secret reference

To deploy the Cennso PostgreSQL Operator to a Core Cluster, you must specify the reference to the [Kubernetes secret](https://kubernetes.io/docs/concepts/configuration/secret/) so this cluster can be accessible. You can do this using the following configuration parameters:

```yaml
spec:
  connectionSecretRef:
    name: {CORE-CLUSTER-NAME}
    namespace: {CORE-CLUSTER-SECRET-NAMESPACE}
```

Set **spec.connectionSecretRef.name** to the name of the Core Cluster where the Cennso PostgreSQL Operator should be installed. The **spec.connectionSecretRef.namespace** configuration parameter defines the Kubernetes Namespace on the Management Cluster where the Kubernetes secret to access this Core Cluster is stored.

If you want to deploy the Cennso PostgreSQL Operator to the Management Cluster, do not specify **spec.connectionSecretRef**.

## Image and chart configuration

You can use the following configuration parameters to specify the container image version, together with the secret to pull the image and the Helm chart for the Cennso PostgreSQL Operator:

```yaml
spec:
  image:
    repository: {DATABASE-OPERATOR-IMAGE-REPOSITORY}
    tag: {DATABASE-OPERATOR-IMAGE-TAG}
  imagePullSecretRef:
    name: {SECRET-NAME}
  chart:
    registry: {CHART-REGISTRY-NAME}
    name: {DATABASE-OPERATOR-CHART-NAME}
    version: {DATABASE-OPERATOR-CHART-VERSION}
    pullSecretRef: {CHART-SECRET-NAME}
```

## Scheduling and placement configuration

`PostgreSQLOperator` custom resource allows you to configure the Cennso PostgreSQL Operator scheduling and placement settings according to your needs.

To control where the Cennso PostgreSQL Operator Pods run and how they are distributed across nodes, use the following configuration options:

- [**spec.nodeSelector**](https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/)
- [**spec.tolerations**](https://kubernetes.io/docs/concepts/scheduling-eviction/taint-and-toleration/)
- [**spec.affinity**](https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/#affinity-and-anti-affinity)

You can also add custom annotations to the operator Pods with the **spec.podAnnotations** configuration option.

In addition, you should specify the **spec.operatorNamespace** configuration option which controls the Kubernetes namespace name where the Cennso PostgreSQL Operator should be deployed.

## Namespaces for the database clusters

The database operator is configured to operate the PostgreSQL clusters which are located in the given Kubernetes namespaces. You can specify one or multiple Kubernetes namespaces where the database clusters are deployed and managed by the database operator. To do this, use the following configuration option:

```yaml
spec:
  watchNamespaces:
    - cluster-1-namespace
    - cluster-2-namespace
    - cluster-3-namespace
```

## Storage configuration

The storage configuration section allows you to declare the `StorageClass` and the node-local paths which the database operator creates to assign to the persistent volumes:

```yaml
spec:
  storage:
    classes:
      - nodePath: /opt/local-path-provisioner/postgresql
        name: postgresql-data-storage
```

Each entry becomes a `StorageClass` backed by the [local-path-provisioner](https://github.com/rancher/local-path-provisioner), which creates the volumes under **spec.storage.classes[].nodePath** on the node where a Pod can be scheduled. A `PostgreSQLInstance` can refer to the class by name in **spec.instances[].storage.className**. For more information, see the [Storage configuration](https://docs.cennso.com/cennso/cennso-db/latest/concepts/cennso-postgresql-instance.md#storage-configuration) section of the Cennso PostgreSQL Instance document.

The local-path-provisioner only creates volumes under the paths listed in the `nodePathMap` of its `local-path-config` ConfigMap on the target cluster. The **spec.storage.classes[].nodePath** must match one of these paths exactly for the nodes where the PostgreSQL Pods run. Otherwise, the Persistent Volume Claims stay `Pending` and the provisioner reports `config doesn't contain path`. Ask the cluster administrator which paths are configured before you choose a **spec.storage.classes[].nodePath**.

The `StorageClass` resources are preserved when the `PostgreSQLOperator` CR is deleted, because the volumes of the running PostgreSQL instances still reference them.

## Logging configuration

You can configure the log level and whether the operator emits structured logs using the following configuration options:

```yaml
spec:
  logging:
    level: {LOG-LEVEL}
    structured: false
```

The **spec.logging.level** configuration option supports `DEBUG`, `INFO`, and `ERROR`. The default value is `INFO`.

## Resources configuration

`PostgreSQLOperator` custom resource allows you to configure the [resources](https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/) for the Cennso PostgreSQL Operator using the following configuration options:

```yaml
spec:
  resources:
    requests:
      cpu: 1
      memory: 512Mi
    limits:
      cpu: 1
      memory: 512Mi
```
