Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions scripts/restore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,45 @@ if [[ "${TDE_ENABLED:-false}" == "true" ]]; then
echo "pg_tde.cipher = '${TDE_CIPHER:-aes_128}'" >>/tmp/postgresql.conf
fi
cat /run_scripts/role/postgresql.conf >>/tmp/postgresql.conf
# The role template does not end in a newline, so anything appended after it would be
# swallowed by its last comment line. Start a fresh line before writing more.
printf '\n' >>/tmp/postgresql.conf

# Replaying WAL makes this a standby, so PostgreSQL enforces that these settings are
# each >= the value recorded in the source's pg_control; otherwise recovery stops with
# FATAL: recovery aborted because of insufficient parameter settings
# On a KubeDB database these are normally raised through the config secret, which is
# mounted at /etc/config in the DB pod but NOT here -- the role template's
# `include_if_exists = '/etc/config/user.conf'` therefore resolves to nothing and we
# would fall back to the built-in defaults (100 / 8 / 64 / 0). Read the real values out
# of the restored control file instead: pg_controldata reports exactly what the check
# compares against, so this needs no knowledge of how the source was configured.
# Appended after the role template so nothing downstream can lower them again.
if command -v pg_controldata >/dev/null 2>&1; then
control_setting() {
pg_controldata "$PGDATA" 2>/dev/null |
sed -n "s/^$1 setting: *\([0-9]\+\)$/\1/p"
}
for pair in \
"max_connections:max_connections" \
"max_worker_processes:max_worker_processes" \
"max_prepared_xacts:max_prepared_transactions" \
"max_locks_per_xact:max_locks_per_transaction"; do
control_field="${pair%%:*}"
guc="${pair##*:}"
value="$(control_setting "$control_field")"
if [[ -n "$value" ]]; then
echo "$guc = $value" >>/tmp/postgresql.conf
fi
done
# max_wal_senders is already pinned to 90 above; only raise it further if the
# source ran with more, never lower it.
senders="$(control_setting max_wal_senders)"
if [[ -n "$senders" ]] && [[ "$senders" -gt 90 ]]; then
echo "max_wal_senders = $senders" >>/tmp/postgresql.conf
fi
fi

mv /tmp/postgresql.conf "$PGDATA/postgresql.conf"
echo "max_replication_slots = 90" >>/tmp/postgresql.conf
# setup pg_hba.conf for initial start. this one is just for initialization
Expand Down
Loading