postgresqldockerbitnamipostgresql-15

bitnami postgresql replaces postgresql.conf after restarting docker


I'm using docker pull bitnami/postgresql:15.2.0 and I mount 2 directories:

/opt/bitnami/postgresql/conf has postgresql.conf which I'm trying to change

After changing some values and restarting Docker the file has the default values back i.e. modified file replaced with the default conf file. It doesn't matter if Docker was running at the time of the change or not - I tried both ways.

I found the instructions on the site, but there are also a lot of questions about it. I don't understand how to use this:

Add your custom file to files/postgresql.conf in your working directory.

Apparently I'm doing something wrong ... so, do you guys have any advice on how to change postgresql.conf?

Thank you!


Solution

  • For simplicity, you can declare just the config you want to overwrite, then mount it onto opt/bitnami/postgresql/conf/conf.d/postgresql.conf.

    For example I have this config file

    ➜  code cat postgresql.conf
    log_connections = yes
    shared_buffers = 128MB
    log_min_messages=DEBUG5
    log_min_error_statement=DEBUG
    
    ➜  code pwd
    /Users/hoaphan/dev/code
    
    
    ➜  code docker run  --rm --name postgresql -ePOSTGRESQL_PASSWORD=123456 -v  /Users/hoaphan/dev/code/postgresql.conf:/opt/bitnami/postgresql/conf/conf.d/postgresql.conf bitnami/postgresql:15.2.0
    

    You can verify that this is effective when compare the mount of logging: enter image description here

    with just (no config mounted)

    docker run  --rm --name postgresql -ePOSTGRESQL_PASSWORD=123456 bitnami/postgresql:15.2.0 
    

    enter image description here


    Not recommended. But if for some reason you still want to override the full original config, you can:

    now after edited the conf/postgresql.con, I start another, overriding the full config: docker run --rm --name postgresql -ePOSTGRESQL_PASSWORD=123456 -v /Users/hoaphan/dev/code/conf/postgresql.conf:/opt/bitnami/postgresql/conf/postgresql.conf bitnami/postgresql:15.2.0

    similar result, the config should be effective enter image description here


    Also if you postgres via binami helm chart:

    helm repo add bitnami https://charts.bitnami.com/bitnami
    helm install myrelease bitnami/postgresql
    

    I'm pretty sure the https://docs.bitnami.com/kubernetes/infrastructure/postgresql/configuration/customize-config-file/ is BS from the look of https://charts.bitnami.com/bitnami/postgresql-12.4.2.tgz But you can add your config file using a values.yaml with content like:

    primary:
      extendedConfiguration: |
        log_connections=yes
        log_min_messages=DEBUG5
        log_min_error_statement=DEBUG5
    

    Then

    helm install myrelease bitnami/postgresql --values values.yaml
    

    will create ConfigMap like this and mount it into the running container as /opt/bitnami/postgresql/conf/conf.d/override.conf, postgres will know to pick it up and apply.

    apiVersion: v1
    data:
      override.conf: |-
        log_connections=yes
        log_min_messages=DEBUG5
        log_min_error_statement=DEBUG5
    kind: ConfigMap
    metadata:
      annotations:
        meta.helm.sh/release-name: myrelease
        meta.helm.sh/release-namespace: default
      creationTimestamp: "2023-05-03T09:13:58Z"
      labels:
        app.kubernetes.io/component: primary
        app.kubernetes.io/instance: myrelease
        app.kubernetes.io/managed-by: Helm
        app.kubernetes.io/name: postgresql
        helm.sh/chart: postgresql-12.4.2
      name: myrelease-postgresql-extended-configuration
      namespace: default