For AI agents: this documentation is indexed for you in llms.txt, and all of it in /llms.txt. Every page is also available as markdown: append .md to its address.

Create a database

Important

To create a database, your PostgreSQL user must have the CREATEDBOpens in a new tab privilege. The default user provisioned automatically by PostgreSQLInstance has this privilege. For more information about the database users, see the Create a database user guide.

After you deploy the PostgreSQL cluster using the PostgreSQLInstance Custom Resource, you can create logical databases on this cluster. The Cennso Database extension lets you provision a logical database either declaratively with the PostgreSQLSchema Custom Resource, or manually. Both methods are described below.

Provision a database using PostgreSQLSchema CR

To create a database using the PostgreSQLSchema Custom Resource, create a resource with the database name you want to create and apply it to the Management Cluster. For example:

yaml

Note

Omit spec.connectionSecretRef when the target PostgreSQLInstance is deployed on the Management Cluster. For more information, see the Cennso PostgreSQL Schema document.

You can apply the PostgreSQLSchema Custom Resource to your Management Cluster using the following command:

bash

After you apply the PostgreSQLSchema manifest, a Kubernetes Job is created on the Core Cluster specified by {CORE-CLUSTER-NAME}, or on the Management Cluster if spec.connectionSecretRef is skipped. This Job creates a new logical database named {DATABASE-NAME} in the {NAMESPACE-WITH-DATABASE-CLUSTER} namespace.

To create a database at the given database instance, the Job must be able to find the database cluster. The spec.dbInstanceName field is used for this purpose. Set it to the metadata.name of the PostgreSQLInstance resource related to the target database cluster.

Note

For now, the Cennso Database extension only creates the logical database. It does not update or delete it. Deleting a PostgreSQLSchema Custom Resource from your Management Cluster does not drop the provisioned database from PostgreSQL. To delete a database, use the DROP SCHEMAOpens in a new tab SQL statement.

You can control the behaviour and lifetime of the Kubernetes Job generated by this CR using the standard configuration options of the Kubernetes JobOpens in a new tab:

  • spec.backoffLimit
  • spec.ttlSecondsAfterFinished
  • spec.activeDeadlineSeconds

For more information about available configuration options, see the Cennso PostgreSQL Schema document.

Provision a database manually

To create a database, execute the following steps:

  1. Find the primary PostgreSQL instance. The primary PostgreSQL instance Pod must have the postgres-operator.crunchydata.com/role label set to primary. You can find the Pod with the primary PostgreSQL instance using the following command:

    bash
  2. Open a shell in the primary PostgreSQL instance container:

    bash
  3. Connect to the primary PostgreSQL instance:

    bash

    Enter the password of {USER-NAME} when prompted.

  4. Create a database using the CREATE DATABASE SQL statement. For example, you can use the following SQL statement to create a database with the cennso_database name:

    sql

For more information, see the official PostgreSQL documentationOpens in a new tab.