From 7bf7d9aa66a7dda19ace3e0e72585ca385763df1 Mon Sep 17 00:00:00 2001 From: Roland Date: Sun, 5 Jul 2026 13:31:30 -0600 Subject: [PATCH] reset_api_db.sh: heal Postgres cluster ownership before resetting. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If cluster files lose postgres ownership (stray recursive chown, interrupted install), the postmaster stays up but every new backend dies with FATAL: could not open file "global/pg_filenode.map": Permission denied — and dropdb/psql cannot work either. Restore ownership of /var/lib/postgresql and /etc/postgresql and restart postgres before recreating the database, and start the API when done. Co-Authored-By: Claude Fable 5 --- scripts/reset_api_db.sh | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/scripts/reset_api_db.sh b/scripts/reset_api_db.sh index 1fb64bf3..bfdc88d1 100755 --- a/scripts/reset_api_db.sh +++ b/scripts/reset_api_db.sh @@ -16,8 +16,19 @@ set -x systemctl stop wrolpi-api +# Heal Postgres cluster ownership before touching the database. A stray recursive chown or an +# interrupted install can leave cluster files unreadable by the server; new backends then die +# with: FATAL: could not open file "global/pg_filenode.map": Permission denied +if id postgres >/dev/null 2>&1; then + [ -d /var/lib/postgresql ] && chown -R postgres:postgres /var/lib/postgresql + [ -d /etc/postgresql ] && chown -R postgres:postgres /etc/postgresql + systemctl restart postgresql +fi + # Delete the WROLPi API DB, if it exists. sudo -iu postgres dropdb wrolpi sudo -iu postgres dropuser wrolpi /bin/bash /opt/wrolpi/scripts/initialize_api_db.sh + +systemctl start wrolpi-api