@@ -134,17 +134,43 @@ sudo -u postgres chmod 0644 "${DATA_DIR}/server.crt"
134134# Backup original Crunchy Bridge config for reference
135135sudo -u postgres cp " ${DATA_DIR} /postgresql.conf" " ${DATA_DIR} /postgresql.conf.crunchybridge"
136136
137- log " Extracting recovery-critical parameters from conf.d before removing include_dir ..."
137+ log " Extracting recovery-critical parameters from postgresql.conf and conf.d ..."
138138
139- # Extract recovery-critical parameters from conf.d files
139+ # Extract recovery-critical parameters from BOTH postgresql. conf (backup values) and conf.d
140140# These MUST be >= the primary server's values for recovery to succeed
141- MAX_CONNECTIONS=$( sudo -u postgres grep -h " ^max_connections" " ${DATA_DIR} /conf.d/" * .conf 2> /dev/null | tail -1 | sed " s/.*=\s*['\" ]*//" | sed " s/['\" ].*//" || echo " 100" )
142- MAX_WORKER_PROCESSES=$( sudo -u postgres grep -h " ^max_worker_processes" " ${DATA_DIR} /conf.d/" * .conf 2> /dev/null | tail -1 | sed " s/.*=\s*['\" ]*//" | sed " s/['\" ].*//" || echo " 8" )
143- MAX_WAL_SENDERS=$( sudo -u postgres grep -h " ^max_wal_senders" " ${DATA_DIR} /conf.d/" * .conf 2> /dev/null | tail -1 | sed " s/.*=\s*['\" ]*//" | sed " s/['\" ].*//" || echo " 10" )
144- MAX_PREPARED_XACTS=$( sudo -u postgres grep -h " ^max_prepared_transactions" " ${DATA_DIR} /conf.d/" * .conf 2> /dev/null | tail -1 | sed " s/.*=\s*['\" ]*//" | sed " s/['\" ].*//" || echo " 0" )
145- MAX_LOCKS_PER_XACT=$( sudo -u postgres grep -h " ^max_locks_per_transaction" " ${DATA_DIR} /conf.d/" * .conf 2> /dev/null | tail -1 | sed " s/.*=\s*['\" ]*//" | sed " s/['\" ].*//" || echo " 64" )
141+ # We take the MAX of both sources to ensure we meet recovery requirements
142+
143+ # Helper function to get max of two numbers
144+ max_value () {
145+ local val1=$1
146+ local val2=$2
147+ if [ " $val1 " -ge " $val2 " ]; then
148+ echo " $val1 "
149+ else
150+ echo " $val2 "
151+ fi
152+ }
146153
147- log " Extracted parameters: max_connections=${MAX_CONNECTIONS} , max_worker_processes=${MAX_WORKER_PROCESSES} "
154+ # Extract from main postgresql.conf (has correct backup values)
155+ PG_MAX_CONNECTIONS=$( sudo -u postgres grep -h " ^max_connections" " ${DATA_DIR} /postgresql.conf" 2> /dev/null | tail -1 | sed " s/.*=\s*['\" ]*//" | sed " s/['\" ].*//" || echo " 100" )
156+ PG_MAX_WORKER_PROCESSES=$( sudo -u postgres grep -h " ^max_worker_processes" " ${DATA_DIR} /postgresql.conf" 2> /dev/null | tail -1 | sed " s/.*=\s*['\" ]*//" | sed " s/['\" ].*//" || echo " 8" )
157+ PG_MAX_WAL_SENDERS=$( sudo -u postgres grep -h " ^max_wal_senders" " ${DATA_DIR} /postgresql.conf" 2> /dev/null | tail -1 | sed " s/.*=\s*['\" ]*//" | sed " s/['\" ].*//" || echo " 10" )
158+ PG_MAX_PREPARED_XACTS=$( sudo -u postgres grep -h " ^max_prepared_transactions" " ${DATA_DIR} /postgresql.conf" 2> /dev/null | tail -1 | sed " s/.*=\s*['\" ]*//" | sed " s/['\" ].*//" || echo " 0" )
159+ PG_MAX_LOCKS_PER_XACT=$( sudo -u postgres grep -h " ^max_locks_per_transaction" " ${DATA_DIR} /postgresql.conf" 2> /dev/null | tail -1 | sed " s/.*=\s*['\" ]*//" | sed " s/['\" ].*//" || echo " 64" )
160+
161+ # Extract from conf.d files
162+ CONFD_MAX_CONNECTIONS=$( sudo -u postgres grep -h " ^max_connections" " ${DATA_DIR} /conf.d/" * .conf 2> /dev/null | tail -1 | sed " s/.*=\s*['\" ]*//" | sed " s/['\" ].*//" || echo " 0" )
163+ CONFD_MAX_WORKER_PROCESSES=$( sudo -u postgres grep -h " ^max_worker_processes" " ${DATA_DIR} /conf.d/" * .conf 2> /dev/null | tail -1 | sed " s/.*=\s*['\" ]*//" | sed " s/['\" ].*//" || echo " 0" )
164+ CONFD_MAX_WAL_SENDERS=$( sudo -u postgres grep -h " ^max_wal_senders" " ${DATA_DIR} /conf.d/" * .conf 2> /dev/null | tail -1 | sed " s/.*=\s*['\" ]*//" | sed " s/['\" ].*//" || echo " 0" )
165+ CONFD_MAX_PREPARED_XACTS=$( sudo -u postgres grep -h " ^max_prepared_transactions" " ${DATA_DIR} /conf.d/" * .conf 2> /dev/null | tail -1 | sed " s/.*=\s*['\" ]*//" | sed " s/['\" ].*//" || echo " 0" )
166+ CONFD_MAX_LOCKS_PER_XACT=$( sudo -u postgres grep -h " ^max_locks_per_transaction" " ${DATA_DIR} /conf.d/" * .conf 2> /dev/null | tail -1 | sed " s/.*=\s*['\" ]*//" | sed " s/['\" ].*//" || echo " 0" )
167+
168+ # Use MAX of both to ensure recovery requirements are met
169+ MAX_CONNECTIONS=$( max_value " $PG_MAX_CONNECTIONS " " $CONFD_MAX_CONNECTIONS " )
170+ MAX_WORKER_PROCESSES=$( max_value " $PG_MAX_WORKER_PROCESSES " " $CONFD_MAX_WORKER_PROCESSES " )
171+ MAX_WAL_SENDERS=$( max_value " $PG_MAX_WAL_SENDERS " " $CONFD_MAX_WAL_SENDERS " )
172+ MAX_PREPARED_XACTS=$( max_value " $PG_MAX_PREPARED_XACTS " " $CONFD_MAX_PREPARED_XACTS " )
173+ MAX_LOCKS_PER_XACT=$( max_value " $PG_MAX_LOCKS_PER_XACT " " $CONFD_MAX_LOCKS_PER_XACT " )
148174
149175log " Modifying postgresql.conf for dev branch..."
150176
0 commit comments