How to change Postgresql max_connections config via Kubernetes statefulset environment variable? How to change Postgresql max_connections config via Kubernetes statefulset environment variable? kubernetes kubernetes

How to change Postgresql max_connections config via Kubernetes statefulset environment variable?


Postgresql docker image can only support several env parameters, POSTGRES_PASSWORD, POSTGRES_USER ,POSTGRES_DB, POSTGRES_INITDB_ARGS, POSTGRES_INITDB_WALDIR, POSTGRES_HOST_AUTH_METHOD, PGDATA.

If you want modify some database configuration parameters, you can use args in kubernetes.

Deployment yaml file fraction

  containers:  - args:    - -c    - max_connections=1000    - -c    - shared_buffers=1024MB    envFrom:    - configMapRef:        name: postgres-config    image: postgres    imagePullPolicy: IfNotPresent    name: postgres


When max_connections is specified by the environment variable of PGOPTIONS, the following error occurs. Therefore, it is correct to specify it in args instead of the environment variable of PGOPTIONS.

2020-05-27 06:51:55.327 UTC [62] FATAL:  parameter "max_connections" cannot be changed without restarting the serverpsql: FATAL:  parameter "max_connections" cannot be changed without restarting the server


containers:        - name: postgres          image: postgres:latest          args: ["-c", "max_connections=500"]


you need to extend the base image ( postgres:latest ). overwrite the default configurations with custom changes and then launch postgres.