Cennso PostgreSQL Schema
A Cennso PostgreSQL Schema is represented by the PostgreSQLSchema Custom Resource (CR). Applying this CR to a Management Cluster creates a Kubernetes Job that provisions a logical PostgreSQL database inside an existing Cennso PostgreSQL Instance.
Important
Before provisioning a logical database, the target PostgreSQLInstance must be deployed, and its PgBouncerOpens in a new tab Kubernetes Service must be reachable from the provisioning Job. The Job connects to the PostgreSQL cluster through that Service and authenticates as the default database user with the credentials stored in the {POSTGRESQL-INSTANCE-NAME}-pguser-{POSTGRESQL-INSTANCE-NAME} Kubernetes Secret.
PostgreSQLSchema provisions a PostgreSQL database, not a PostgreSQL SCHEMA object, which is a namespace inside a database.
The sections below provide information about configuration parameters that you can specify in the PostgreSQLSchema CR. For more information on how to provision a logical database, see the Create a PostgreSQL database document.
Kubernetes cluster secret reference
To deploy the Cennso PostgreSQL Schema to a Core Cluster, you must specify a reference to the Kubernetes secretOpens in a new tab so the Core Cluster is accessible. You can do this using the following configuration parameters:
Set spec.connectionSecretRef.name to the name of the Core Cluster that contains the PostgreSQL cluster where the database should be created. 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 Schema to the Management Cluster, do not specify spec.connectionSecretRef. In both cases, the target cluster must be the same as the one of the Cennso PostgreSQL Operator that manages the namespace of the database instances.
Target PostgreSQL Instance reference
To select the PostgreSQL cluster where the logical database is created, you must specify the PostgreSQLInstance name and the Kubernetes Namespace where it is deployed:
The spec.namespace must match spec.namespace of the PostgreSQLInstance.
The spec.dbInstanceName must match the metadata.name of an existing PostgreSQLInstance resource. The schema-provisioning Job connects to the {POSTGRESQL-INSTANCE-NAME}-pgbouncer.{POSTGRESQL-CLUSTER-NAMESPACE}.svc:5432 Kubernetes Service and uses the credentials from the {POSTGRESQL-INSTANCE-NAME}-pguser-{POSTGRESQL-INSTANCE-NAME} Kubernetes Secret.
Database name
To define the logical database that should be created, use the following configuration parameter:
The spec.schemaName must be a valid, unquoted PostgreSQL identifier: a letter or underscore, followed by letters, digits, or underscores, up to 63 characters.
Note
PostgreSQLSchema only creates the logical database. It does not update or delete it. Deleting a PostgreSQLSchema Custom Resource does not drop the provisioned database from PostgreSQL. To delete a schema, use the DROP SCHEMAOpens in a new tab SQL statement.
Job retries, lifetime, and deadline
To control how the schema-provisioning Kubernetes JobOpens in a new tab behaves on failure and after completion, use the following configuration parameters:
The spec.backoffLimit configures the number of retries before the Job is marked as failed. The default value is 1. For more information, see the pod backoff failure policyOpens in a new tab documentation.
The spec.ttlSecondsAfterFinished configures how long a finished Job (either Complete or Failed) is retained before it is automatically cleaned up. If omitted, the Job is not deleted automatically. For more information, see the TTL mechanism for finished JobsOpens in a new tab documentation.
Note
The Job exists as long as the PostgreSQLSchema exists. After spec.ttlSecondsAfterFinished expires, the Job is deleted and then created again. The new Job run does not change the database because it creates the database only if it does not already exist. However, each new run starts a new Pod. Leave spec.ttlSecondsAfterFinished unset to avoid this behavior.
The spec.activeDeadlineSeconds configures a wall-clock deadline, measured from the Job start time, after which the Job is terminated and marked as failed. The default value is 600 seconds.
The spec.restartPolicy configures the restart policy of the Job Pod. The supported values are OnFailure and Never. The default value is OnFailure. For more information, see the pod lifecycleOpens in a new tab documentation.
Readiness and failed Jobs
The PostgreSQLSchema becomes Ready when the Job has completed. A PostgreSQLSchema that stays not ready has a Job that is still running or has failed. You can use the following commands to check the Job and its Pod in spec.namespace on the target cluster:
A failed Job is not restarted automatically. To run it again, delete the Job, and a new one will be created:
The same applies after changing spec.image, spec.restartPolicy, or spec.schemaName of an existing PostgreSQLSchema. The Pod template of a Kubernetes Job cannot be changed, so the update is rejected until the existing Job is deleted.
Image and pull secret
You can configure the image of the schema-provisioning Job and the Kubernetes Secret used to pull it with the following configuration options:
The spec.imagePullSecretRef.name refers to a Kubernetes Secret that must exist on the target cluster in the same Kubernetes Namespace as the Job.