mirror of
https://github.com/rootzoll/raspiblitz.git
synced 2025-02-28 16:58:03 +01:00
use the installed postgres version to create the cluster (#4504)
This commit is contained in:
parent
e2d9d29164
commit
7d41e56e02
1 changed files with 15 additions and 10 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue