Potgres createuser: creation of new role failed: ERROR: role "postgres" already exists

1/27/2021

After starting kubernetes container with postgres DB engine, and running scrpts to create schema and load initial data, I get error: createuser: creation of new role failed: ERROR: role "postgres" already exists

I'm not creating postgres role withub sql schema/data files, and don't know from where this error comes from.

YAML file content:

apiVersion: apps/v1beta2
kind: StatefulSet
metadata:
  creationTimestamp: "2021-01-27T18:02:58Z"
  generation: 1
  labels:
    app: xx-postgres
    helm: xxpostgres
    helm.sh/chart: xxpostgres-0.1.0
    release: 1.0.0-SNAPSHOT
  name: x-postgres
  namespace: build-xx
  resourceVersion: "105583631"
  selfLink: /apis/apps/v1beta2/namespaces/build-xx/statefulsets/xx-postgres
  uid: e34cc3ba-60c9-11eb-876a-00505696ddc4
spec:
  podManagementPolicy: OrderedReady
  replicas: 1
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      app: xx-postgres
  serviceName: xx-postgres-service
  template:
    metadata:
      annotations:
        checksum/configmap: 4bad85d0c44b1f0f16fb4e7221c753d6068c5c5f16ec4c0d35872b29d0a67263
        checksum/secret: 2e5d3a662b07c414cc8b2f21b5fae91dc058386593cb98952bab28e0df8a1316
      creationTimestamp: null
      labels:
        app: xx-postgres
        helm: xxpostgres
        helm.sh/chart: xxpostgres-0.1.0
        release: 1.0.0-SNAPSHOT
    spec:
      containers:
      - env:
        - name: POSTGRESQL_DATABASE
          value: xx
        - name: POSTGRESQL_USER
          value: postgres
        - name: POSTGRESQL_PASSWORD
          valueFrom:
            secretKeyRef:
              key: postgres.admin.password
              name: xx-postgres-secret
        - name: POSTGRESQL_HOST
        - name: POSTGRESQL_PORT
          value: "5432"
        - name: PGPASSWORD
          valueFrom:
            secretKeyRef:
              key: postgres.admin.password
              name: xx-postgres-secret
        - name: auth_USER
          value: auth
        - name: auth_PASSWORD
          valueFrom:
            secretKeyRef:
              key: postgres.db.xxauth.password
              name: xx-postgres-secret
        image: 10.168.252.43:8082/rhscl/postgresql-10-rhel7:latest
        imagePullPolicy: Always
        name: xx-postgres
        ports:
        - containerPort: 5432
          protocol: TCP
        resources: {}
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
        volumeMounts:
        - mountPath: /var/lib/pgsql/data
          name: xx-postgres-datafiles
        - mountPath: /opt/app-root/src/postgresql-init/initialize_database.sh
          name: xx-postgres-scripts-volume
          subPath: initialize_database.sh
        - mountPath: /opt/app-root/src/postgresql-start/upgrade_database.sh
          name: xx-postgres-scripts-volume
          subPath: upgrade_database.sh
        - mountPath: /opt/app-root/src/postgresql-drop/drop_database.sh
          name: xx-postgres-scripts-volume
          subPath: drop_database.sh
        - mountPath: /opt/app-root/src/sql
          name: xx-postgres-sql-volume
      dnsPolicy: ClusterFirst
      nodeSelector:
        node-type: worker
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext: {}
      terminationGracePeriodSeconds: 30
      volumes:
      - configMap:
          defaultMode: 504
          name: xx-postgres-scripts-configmap
        name: xx-postgres-scripts-volume
      - configMap:
          defaultMode: 504
          name: xx-postgres-sql-configmap
        name: xx-postgres-sql-volume
  updateStrategy:
    rollingUpdate:
      partition: 0
    type: RollingUpdate
  volumeClaimTemplates:
  - metadata:
      creationTimestamp: null
      labels:
        app: xx-postgres
      name: xx-postgres-datafiles
      namespace: build-xx
    spec:
      accessModes:
      - ReadWriteMany
      dataSource: null
      resources:
        requests:
          storage: 10Gi
      storageClassName: nfs
      volumeMode: Filesystem
    status:
      phase: Pending
status:
  collisionCount: 0
  currentReplicas: 1
  currentRevision: xx-postgres-84b5dcd79f
  observedGeneration: 1
  readyReplicas: 1
  replicas: 1
  updateRevision: xx-postgres-84b5dcd79f
  updatedReplicas: 1

..........................................................................

-- ernest
kubernetes
postgresql

0 Answers