Skip to content

Initialization SQL is not being applied #3422

Closed
@rhrytskiv

Description

@rhrytskiv

I'm following you tutorial here: https://access.crunchydata.com/documentation/postgres-operator/5.2.0/tutorial/customize-cluster/#database-initialization-sql
but the sql is not being executed, and there's not echo statement in operator or db pod logs either.
Sql itself is completely valid, if I just log in to db pod and execute it via psql it works and grants permissions.

I've created my configmap: with kube create configmap qa3-nextgen-db-init-sql --from-file=init.sql=./init.sql

Here's my init.sql

\set ON_ERROR_STOP
\echo "EXECUTING DB INIT SCRIPT"

\c partners
GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA "public" TO "partners-writer";
GRANT SELECT                         ON ALL TABLES IN SCHEMA "public" TO "partners-reader";

\c organizations
GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA "public" TO "organizations-writer";
GRANT SELECT                         ON ALL TABLES IN SCHEMA "public" TO "organizations-reader";

Here's my cluster definition:

apiVersion: postgres-operator.crunchydata.com/v1beta1
kind: PostgresCluster
metadata:
  name: qa3-nextgen-db
spec:
  image: registry.developers.crunchydata.com/crunchydata/crunchy-postgres:ubi8-14.5-1
  postgresVersion: 14
  databaseInitSQL:
    key: init.sql
    name: qa3-nextgen-db-init-sql
  instances:
    - name: qa3-db-inst
      replicas: 1
      resources:
        requests:
          cpu: 250m
          memory: 256Mi
        limits:
          cpu: 2.0
          memory: 4Gi
      dataVolumeClaimSpec:
        storageClassName: mayastor-1
        accessModes:
        - "ReadWriteOnce"
        resources:
          requests:
            storage: 5Gi
      affinity:
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
          - topologyKey: kubernetes.io/hostname
            labelSelector:
              matchLabels:
                postgres-operator.crunchydata.com/cluster: qa3-nextgen-db
                postgres-operator.crunchydata.com/instance-set: qa3-db-inst

  backups:
    pgbackrest:
      image: registry.developers.crunchydata.com/crunchydata/crunchy-pgbackrest:ubi8-2.40-1
      metadata:
        annotations:
          sidecar.istio.io/inject: "false"
      repos:
      - name: repo1
        volume:
          volumeClaimSpec:
            storageClassName: mayastor-1
            accessModes:
            - "ReadWriteOnce"
            resources:
              requests:
                storage: 1Gi

  users:
    - name: organizations-owner
      databases:
        - organizations
      options: "CREATEDB"
      password:
        type: AlphaNumeric

    - name:organizations-writer
      password:
        type: AlphaNumeric

    - name:organizations-reader
      password:
        type: AlphaNumeric
    
    - name:partners-owner
      databases:
        - partners
      options: "CREATEDB"
      password:
        type: AlphaNumeric

    - name:partners-writer
      password:
        type: AlphaNumeric

    - name:partners-reader
      password:
        type: AlphaNumeric

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions