Skip to content

[Bug]: max_connections not updated in replica Cluster #9855

Closed

Description

@mateusoliveira43

Is there an existing issue already for this bug?

  • I have searched for an existing issue, and could not find anything. I believe this is a new bug.

I have read the troubleshooting guide

  • I have read the troubleshooting guide and I think this is a new bug.

I am running a supported version of CloudNativePG

  • I have read the troubleshooting guide and I think this is a new bug.

Contact Details

No response

Version

trunk (main)

What version of Kubernetes are you using?

1.34

What is your Kubernetes environment?

Self-managed: kind (evaluation)

How did you install the operator?

Other

What happened?

After decreasing max_connections value in replica Cluster (but still keep its value greater than value in primary), value is not updated in postgres running in Pods

Reproduction steps

git clone [email protected]:cloudnative-pg/cloudnative-pg.git
cd cloudnative-pg
./hack/setup-cluster.sh create load deploy
kubectl apply -f docs/src/samples/cluster-example.yaml
kubectl apply -f docs/src/samples/cluster-replica-tls.yaml
# wait Cluster become healthy
kubectl exec -it cluster-example-1 -- psql -c 'show max_connections;'
#Defaulted container "postgres" out of: postgres, bootstrap-controller (init)
# max_connections
#-----------------
# 100
#(1 row)
kubectl exec -it cluster-replica-tls-1 -- psql -c 'show max_connections;'
#Defaulted container "postgres" out of: postgres, bootstrap-controller (init)
# max_connections
#-----------------
# 100
#(1 row)

# update max_connections on primary
kubectl patch cluster cluster-example --type=merge --patch '{"spec": {"postgresql": {"parameters": {"max_connections": "90"}}}}'
# wait Cluster become healthy
kubectl exec -it cluster-example-1 -- psql -c 'show max_connections;'
#Defaulted container "postgres" out of: postgres, bootstrap-controller (init)
# max_connections
#-----------------
# 90
#(1 row)

# update max_connections on replica
kubectl patch cluster cluster-replica-tls --type=merge --patch '{"spec": {"postgresql": {"parameters": {"max_connections": "95"}}}}'
# wait as long as you want... Cluster is healthy, but postgres was not updated
kubectl exec -it cluster-replica-tls-1 -- psql -c 'show max_connections;'
#Defaulted container "postgres" out of: postgres, bootstrap-controller (init)
# max_connections
#-----------------
# 100
#(1 row)

Cluster resource

apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
  name: cluster-example
spec:
  instances: 3
  
  storage:
    size: 1Gi
---
apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
  name: cluster-replica-tls
spec:
  instances: 3

  bootstrap:
    pg_basebackup:
      source: cluster-example

  replica:
    primary: cluster-example
    source: cluster-example

  storage:
    size: 1Gi

  externalClusters:
  - name: cluster-example
    connectionParameters:
      host: cluster-example-rw.default.svc
      user: streaming_replica
      sslmode: verify-full
      dbname: postgres
    sslKey:
      name: cluster-example-replication
      key: tls.key
    sslCert:
      name: cluster-example-replication
      key: tls.crt
    sslRootCert:
      name: cluster-example-ca
      key: ca.crt

Relevant log output

last lines from Pod cluster-replica-tls-1

{"level":"info","ts":"2026-02-03T21:44:34.381195838Z","msg":"Installed configuration file","logger":"instance-manager","logging_pod":"cluster-replica-tls-1","controller":"instance-cluster","controllerGroup":"postgresql.cnpg.io","controllerKind":"Cluster","Cluster":{"name":"cluster-replica-tls","namespace":"default"},"namespace":"default","name":"cluster-replica-tls","reconcileID":"e9da8260-6ec6-42a9-b267-b03bad6e1b20","logging_pod":"cluster-replica-tls-1","pgdata":"/var/lib/postgresql/data/pgdata","filename":"custom.conf"}
{"level":"info","ts":"2026-02-03T21:44:34.405881851Z","msg":"reloading the instance","logger":"instance-manager","logging_pod":"cluster-replica-tls-1","controller":"instance-cluster","controllerGroup":"postgresql.cnpg.io","controllerKind":"Cluster","Cluster":{"name":"cluster-replica-tls","namespace":"default"},"namespace":"default","name":"cluster-replica-tls","reconcileID":"e9da8260-6ec6-42a9-b267-b03bad6e1b20","instance":"cluster-replica-tls-1","cluster":"cluster-replica-tls","namespace":"default","logging_pod":"cluster-replica-tls-1"}
{"level":"info","ts":"2026-02-03T21:44:34.405894184Z","msg":"Requesting configuration reload","logger":"instance-manager","logging_pod":"cluster-replica-tls-1","controller":"instance-cluster","controllerGroup":"postgresql.cnpg.io","controllerKind":"Cluster","Cluster":{"name":"cluster-replica-tls","namespace":"default"},"namespace":"default","name":"cluster-replica-tls","reconcileID":"e9da8260-6ec6-42a9-b267-b03bad6e1b20","logging_pod":"cluster-replica-tls-1","pgdata":"/var/lib/postgresql/data/pgdata","pgCtlOptions":["-D","/var/lib/postgresql/data/pgdata","reload"]}
{"level":"info","ts":"2026-02-03T21:44:34.406666476Z","logger":"pg_ctl","msg":"server signaled","pipe":"stdout","logging_pod":"cluster-replica-tls-1"}
{"level":"info","ts":"2026-02-03T21:44:34.407541851Z","logger":"postgres","msg":"record","logging_pod":"cluster-replica-tls-1","record":{"log_time":"2026-02-03 21:44:34.406 UTC","process_id":"30","session_id":"698269bf.1e","session_line_num":"7","session_start_time":"2026-02-03 21:33:51 UTC","transaction_id":"0","error_severity":"LOG","sql_state_code":"00000","message":"received SIGHUP, reloading configuration files","backend_type":"postmaster","query_id":"0"}}
{"level":"info","ts":"2026-02-03T21:44:34.408268435Z","logger":"postgres","msg":"record","logging_pod":"cluster-replica-tls-1","record":{"log_time":"2026-02-03 21:44:34.407 UTC","process_id":"30","session_id":"698269bf.1e","session_line_num":"8","session_start_time":"2026-02-03 21:33:51 UTC","transaction_id":"0","error_severity":"LOG","sql_state_code":"55P02","message":"parameter \"max_connections\" cannot be changed without restarting the server","backend_type":"postmaster","query_id":"0"}}
{"level":"info","ts":"2026-02-03T21:44:34.408716477Z","logger":"postgres","msg":"record","logging_pod":"cluster-replica-tls-1","record":{"log_time":"2026-02-03 21:44:34.408 UTC","process_id":"30","session_id":"698269bf.1e","session_line_num":"9","session_start_time":"2026-02-03 21:33:51 UTC","transaction_id":"0","error_severity":"LOG","sql_state_code":"00000","message":"parameter \"cnpg.config_sha256\" changed to \"c55a61044eb02f9e8b0787321d858782dd2f069200a11d3c708836dcf02bff04\"","backend_type":"postmaster","query_id":"0"}}
{"level":"info","ts":"2026-02-03T21:44:34.408729227Z","logger":"postgres","msg":"record","logging_pod":"cluster-replica-tls-1","record":{"log_time":"2026-02-03 21:44:34.408 UTC","process_id":"30","session_id":"698269bf.1e","session_line_num":"10","session_start_time":"2026-02-03 21:33:51 UTC","transaction_id":"0","error_severity":"LOG","sql_state_code":"F0000","message":"configuration file \"/var/lib/postgresql/data/pgdata/custom.conf\" contains errors; unaffected changes were applied","backend_type":"postmaster","query_id":"0"}}

Code of Conduct

  • I agree to follow this project's Code of Conduct

Activity

  1. dosubot commented on Feb 3, 2026

    @dosubot

    This is a known limitation in CloudNativePG: changing max_connections in a replica cluster updates the configuration file, but does not trigger a PostgreSQL restart, so the running value remains unchanged until a manual restart occurs. This happens because max_connections is a fixed parameter that requires a full server restart to take effect, and the operator currently does not automatically restart replica pods for such changes—only a configuration reload (SIGHUP) is triggered, which is insufficient for this parameter source.

    Several issues have been reported about this behavior, including #5268 and #6409, which describe how restart-required changes (like max_connections) may not be applied to replicas until a reconciliation cycle or manual intervention. This can lead to configuration drift between primary and replica clusters.

    As a workaround, you can manually restart the affected replica pods to apply the new value. Keep in mind that this limitation may cause temporary inconsistencies in cluster configuration, especially after promotions or parameter changes. For future updates, monitor the project's changelog and issues for improvements in how the operator handles restarts for fixed parameters in replica clusters.

    To reply, just mention @dosu.


    Docs are dead. Just use Dosu.

    Leave Feedback Ask Dosu about cloudnative-pg Share Dosu with your team

  2. added a commit that references this issue on Feb 10, 2026
    3145a88
  3. gbartolini commented on Feb 16, 2026

    @gbartolini
    Contributor

    /test

  4. added 4 commits that reference this issue on Feb 19, 2026
    dfd8518
    014a478
    d82e589
    8592a1e
  5. added a commit that references this issue on Feb 20, 2026
    efdddd2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

triagePending triage

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions