From a51f0a0156904fb57a8b63783f933edbb1170565 Mon Sep 17 00:00:00 2001 From: claude-hdb Date: Wed, 15 Jul 2026 21:02:57 +0000 Subject: [PATCH] fix: restore-db.sh connects as the container's Coolify superuser, not "postgres" Coolify provisions each Postgres resource with a random POSTGRES_USER; the role "postgres" does not exist, so the hardcoded `psql -U postgres` fails with FATAL: role "postgres" does not exist. Surfaced by the Task 9 restore drill against box B. Expand $POSTGRES_USER inside the container (single-quoted sh -c) so the restore uses the resource's own superuser. Co-Authored-By: Claude Opus 4.8 --- scripts/restore-db.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/scripts/restore-db.sh b/scripts/restore-db.sh index 36f55a5..98831a9 100755 --- a/scripts/restore-db.sh +++ b/scripts/restore-db.sh @@ -3,10 +3,13 @@ # Streams a Coolify Postgres backup artifact into the target container over # tailnet SSH. Refuses to run without explicit confirmation of the target. set -euo pipefail -ARTIFACT="${1:?backup artifact (.sql.gz)}"; HOST="${2:?target host (tailnet name)}"; CONTAINER="${3:?postgres container name}"; DBNAME="${4:?target database name (docker exec psql -U postgres -lqt to list)}" +ARTIFACT="${1:?backup artifact (.sql.gz)}"; HOST="${2:?target host (tailnet name)}"; CONTAINER="${3:?postgres container name}"; DBNAME="${4:?target database name (docker exec env | grep POSTGRES_DB)}" echo "About to RESTORE ${ARTIFACT} into database ${DBNAME} in ${CONTAINER} on ${HOST} — this overwrites that database." read -r -p "Type the target host to confirm: " CONFIRM [ "$CONFIRM" = "$HOST" ] || { echo "confirmation mismatch; aborting"; exit 1; } +# Connect as the container's own superuser: Coolify provisions each Postgres +# resource with a random POSTGRES_USER — "postgres" does not exist. Expand +# $POSTGRES_USER inside the container (single-quoted sh -c), never client-side. # shellcheck disable=SC2029 # intentional: $CONTAINER/$DBNAME are local vars, expand client-side before they reach the remote shell -gunzip -c "$ARTIFACT" | ssh "root@${HOST}" "docker exec -i ${CONTAINER} psql -U postgres -d ${DBNAME} -v ON_ERROR_STOP=1" +gunzip -c "$ARTIFACT" | ssh "root@${HOST}" "docker exec -i ${CONTAINER} sh -c 'psql -U \"\$POSTGRES_USER\" -d ${DBNAME} -v ON_ERROR_STOP=1'" echo "restore complete — run the verification checks in runbooks/restore-drill.md step 4"