Skip to content

Use $HOSTNAME in restore.sh instead of the hostname binary - #71

Merged
souravbiswassanto merged 1 commit into
masterfrom
fix-restore-hostname
Aug 28, 2026
Merged

Use $HOSTNAME in restore.sh instead of the hostname binary#71
souravbiswassanto merged 1 commit into
masterfrom
fix-restore-hostname

Conversation

@tamalsaha

Copy link
Copy Markdown
Member

scripts/restore.sh is the only script in this repo that shells out to the hostname binary; every other one reads bash's $HOSTNAME.

hostname is not installed in the RHEL/CentOS Stream based images that run this script — neither ghcr.io/appscode-images/postgres-enterprise:16.9-stream9-ext nor the ghcr.io/kubedb/postgres-archiver:*_16.9-stream9* image that actually executes it (Walg.Image, wired up in kubedb/postgres pkg/controller/sidekick.go). There is no hostname package in either; command -v hostname comes back empty in both.

The failure

HOST=$(hostname)

The script has no set -e, so it carries on with HOST empty. Every later branch keys off it:

if [[ "$HOST" =~ -0$ ]]; then
  echo "recovery_target_action = 'promote'" >>/tmp/postgresql.conf
else
  echo "recovery_target_action = 'pause'" >>/tmp/postgresql.conf
fi

With HOST empty the test is false on every pod, so ordinal 0 is configured to pause instead of promote. The script then takes the replica path at the bottom and loops forever on pg_is_wal_replay_paused() waiting for a node that was supposed to promote — a PITR restore that never completes.

The fix

Use $HOSTNAME, which bash sets itself, matching what config_recovery.conf.sh, ha_backup_job.sh, warm_stanby.sh, start.sh and the rest of the repo already do. No os-release branching needed — this works identically on alpine, bookworm and stream9.

Verification

HOST="$HOSTNAME" in a #!/bin/bash script, run with --hostname my-pg-0 and --hostname my-pg-2:

=== ghcr.io/kubedb/postgres-archiver:v0.28.0-rc.2_16.9-stream9_linux_amd64 ===
HOST=[my-pg-0] -> primary path
HOST=[my-pg-2] -> replica path
=== ghcr.io/appscode-images/postgres-enterprise:16.9-stream9-ext ===
HOST=[my-pg-0] -> primary path
HOST=[my-pg-2] -> replica path

bash -n scripts/restore.sh is clean.

restore.sh is the only script in this repo that shells out to hostname;
every other one uses $HOSTNAME. The hostname binary is not installed in
the RHEL/CentOS Stream based images that run this script, so HOST came
back empty. The script has no set -e, so it carried on: the [[ "$HOST"
=~ -0$ ]] test was false on every pod, ordinal 0 got
recovery_target_action = 'pause' instead of 'promote', and the script
then waited forever on pg_is_wal_replay_paused() for a node that was
supposed to promote.

Signed-off-by: Tamal Saha <tamal@appscode.com>
@souravbiswassanto
souravbiswassanto merged commit c317553 into master Aug 28, 2026
5 checks passed
@souravbiswassanto
souravbiswassanto deleted the fix-restore-hostname branch August 28, 2026 08:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants