PostgreSQL hot standby cannot start because max_connections is a lower setting than on the master

postgresqlreplication

I have a PostgreSQL 9.6 master and standby server each. Both this line in their respective postgresql.conf:

max_connections = 100

The standby's recovery.conf looks as follows (actuals host, user, and cluster hidden):

standby_mode = on
recovery_target_timeline = latest
primary_conninfo = 'host=<host> port=5433 user=<user>'

When I pg_ctlcluster 9.6 <cluster> start the following error is reported:

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

I am wondering: Where does the value 2000 come from. Both clusters should see 100, i.e. equal values. And indeed SHOW max_connections on the master yields 100.

What is going on here and how can I make the standby start successfully?

Best Answer

This occured because both my master and standby were initialized from a pg_basebackup that was taken on a cluster that indeed had max_connections = 2000. Details of the situation and two remedies are explained here:

[...] this is because pg_control on the standby remembers that the previous primary server's max_connections [...] So you'll either have to have higher settings on the standby for at least one restart or [...] simply start the standby for a second with hot_standby = off, and then re-enable it after it has replayed pending WAL.