Creating PostgreSQL instances

A PostgreSQL cluster custom resource is a YAML file that defines the PostgreSQL cluster size, configuration, storage, and behavior. Create a cluster custom resource (CR) to create a PostgreSQL instance.

Before you begin

System owner responsibilities
Tenant user responsibilities
Note: In the following commands, my-postgres is used as an example PostgreSQL cluster name. Replace it with the name of your actual PostgreSQL cluster. Additionally, postgres-namespace is an example namespace and must be replaced with the namespace in which your PostgreSQL cluster is deployed.

Procedure

  1. Verify which ClusterImageCatalogs are available in your cluster. To view the list, run the command:
    
    oc get clusterimagecatalogs.pg.ibm.com
  2. Verify that a namespace exists for PostgreSQL resources
    oc get namespace <postgres-namespace>
    If the namespace does not exist, create one
     oc create namespace <postgres-namespace>
  3. Get block storage class name.
    • View available storage classes
      oc get storageclass
    • Select a block storage class from the list.
    • If no block storage class exist, contact the system owner or editor to setup storage class for your tenant.
  4. Use the IBM sample PostgreSQL cluster CR YAML template and update configuration parameters with values from step 3.
    Basic CR example
    apiVersion: pg.ibm.com/v1                 
    kind: Cluster 
    metadata: 
     name: my-postgres 
     namespace: postgres-namespace           # From step 2 
    spec: 
      imageCatalogRef: 
        apiGroup: pg.ibm.com
       kind: ClusterImageCatalog 
       name: postgresql-image-catalog-latest  # Replace with value from step 1 
       major: 16                              # PostgreSQL major version 
     
     instances: 3                             # Number of replicas 
       storage: 
       size: 10Gi                             # Storage size 
        storageClass: <storageclass-name>     # Storage class name  
       
     # Resource configuration 
     resources: 
       requests: 
         memory: "2Gi" 
          cpu: "1" 
       limits: 
         memory: "4Gi" 
          cpu: "2" 
     
     # Enable superuser access 
      enableSuperuserAccess: true
    Note: For more information on configuring the PostgreSQL cluster, see Configuring TLS/SSL for secure connections and Configuring access from other clusters.
  5. Validate the YAML file in dry-run mode.
    • Validate on the server
      oc apply -f <cluster yaml file name> --dry-run=server
    • Validate on the client
      oc apply -f <cluster yaml file name> --dry-run=client 

    Resolve any errors before proceeding.

  6. Deploy PostgreSQL cluster by applying the PostgreSQL cluster CR.

    Apply using oc apply or by creating the resource directly through the OpenShift Console YAML editor:

    oc apply -f <cluster yaml file name> 

What to do next

After applying the CR, verify the deployment:

  • Check cluster resource status
    oc get clusters.pg.ibm.com -n postgres-namespace
  • Verify that PostgreSQL pods services and PVCs are created
    oc describe clusters.pg.ibm.com my-postgres -n postgres-namespace
  • Verify that the cluster status is Running
    oc get pods -n postgres-namespace -l pg.ibm.com/cluster=my-postgres