Search code examples
postgresqlpostgresql-13

How to Reduce max_connections value in Postgres Cluster?


I have three node cluster.

Now, I want to reduce the max_connections field from 300 to 100. I have changed the value in both master and replica in postgresql.conf file. I have restarted my master first than the other replica nodes. everything seems ok in master but replicas are shutting down automatically.

Here is the error: hot standby is not possible because max_connections = 100 is a lower setting than on the master server (its value was 300)

I have found a solution where need to start as hot_standby=off.

Is there any other solution rather than this?


Solution

  • So Basically what happened we can't start Replica with less max_connections value than Primary when we have set hot_standby = on.

    Though i have updated The Primary server's max_connections The information didn't arrive in Replica side. Normally, Primary server's config changes are notified with wal log changes. For this reason, after restarting the primary with lower max_connections we need to wait for write operations and then change the Replica's max_connecions.

    But i think this one is not a feasible solution.

    Better Solution:

    1. Start the Primary with lower max_connections
    2. Start replica's with hot_standby = off (if the server stucked in starting state, after few second don't wait for start)
    3. Shut down the replica
    4. Start replica's with hot_standby = on