From 898485adbe67c03cac32a54a54238d26645f8e5d Mon Sep 17 00:00:00 2001 From: openoms <43343391+openoms@users.noreply.github.com> Date: Thu, 28 Mar 2024 13:15:00 +0100 Subject: [PATCH] use the installed postgres version to create the cluster (#4504) --- home.admin/config.scripts/bonus.postgresql.sh | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/home.admin/config.scripts/bonus.postgresql.sh b/home.admin/config.scripts/bonus.postgresql.sh index c5c923c04..334c2365f 100644 --- a/home.admin/config.scripts/bonus.postgresql.sh +++ b/home.admin/config.scripts/bonus.postgresql.sh @@ -26,13 +26,17 @@ if [ "$command" = "1" ] || [ "$command" = "on" ]; then postgres_datadir="/var/lib/postgresql" # default data dir # sudo -u postgres psql -c "show data_directory" - # /var/lib/postgresql/13/main if [ ! -d $postgres_datadir ]; then + # Get the default or highest version of PostgreSQL installed + PG_VERSION=$(psql -V | awk '{print $3}' | cut -d'.' -f1) + echo "Detected PostgreSQL version: $PG_VERSION" + echo "# Create PostgreSQL data" - sudo mkdir -p $postgres_datadir/13/main + sudo mkdir -p $postgres_datadir/$PG_VERSION/main sudo chown -R postgres:postgres $postgres_datadir - # sudo pg_dropcluster 13 main - sudo pg_createcluster 13 main --start + + # create cluster + sudo pg_createcluster $PG_VERSION main --start fi fix_postgres=0 @@ -61,14 +65,14 @@ if [ "$command" = "1" ] || [ "$command" = "on" ]; then fi # always fix ownership - sudo chown -R postgres:postgres /mnt/hdd/app-data/postgresql + sudo chown -R postgres:postgres /mnt/hdd/app-data/postgresql sudo systemctl enable postgresql sudo systemctl start postgresql # check if PostgreSQL was installed if psql --version; then - # wait for the postgres server to start + echo "# wait for the postgresql server to start" count=0 count_max=30 while ! nc -zv 127.0.0.1 5432 2>/dev/null; do @@ -78,6 +82,7 @@ if [ "$command" = "1" ] || [ "$command" = "on" ]; then if [ $count = $count_max ]; then sudo systemctl status postgresql echo "FAIL - Was not able to start PostgreSQL service" + sudo systemctl status postgresql@$PG_VERSION-main.service exit 1 fi done @@ -95,15 +100,15 @@ fi # switch off if [ "$command" = "0" ] || [ "$command" = "off" ]; then - - # setting value in raspiblitz config echo "*** REMOVING POSTGRESQL ***" sudo systemctl stop postgresql sudo systemctl disable postgresql sudo apt remove -y postgresql - echo "OK PostgreSQL removed." + echo "# remove symlink /var/lib/postgresql" + sudo rm /var/lib/postgresql + # would delete all pg data: 'sudo pg_dropcluster $PG_VERSION main' + echo "# OK PostgreSQL is removed." exit 0 - fi # backup