005/006: mount /dev/sdb at /var/lib/postgresql + install PostgreSQL 17 on it

This commit is contained in:
wan
2026-08-31 16:11:37 +09:00
parent 9284569222
commit 873d254009
3 changed files with 84 additions and 1 deletions
+42
View File
@@ -0,0 +1,42 @@
#!/usr/bin/env bash
# 006-install-postgres - Install PostgreSQL (Debian 13 -> PG 17).
# Must run after 005: with /var/lib/postgresql already being the dedicated
# disk, the Debian installer creates the cluster directly on it - no
# data_directory changes needed.
# up: apt install postgresql + contrib, cluster started/enabled
# down: stop + purge packages and /etc/postgresql; data on disk is kept
set -euo pipefail
export DEBIAN_FRONTEND=noninteractive
PGROOT=/var/lib/postgresql
case "${1:-}" in
up)
if command -v pg_lsclusters >/dev/null 2>&1 && pg_lsclusters --no-header | grep -q .; then
echo " postgres cluster already present - skipping"
exit 0
fi
apt-get update -qq
apt-get install -y postgresql postgresql-contrib >/dev/null
chown postgres:postgres "$PGROOT"
systemctl enable --now postgresql >/dev/null
pg_isready -q
pg_lsclusters --no-header | while read -r _ _ _ _ _ datadir _; do
if findmnt -rn "$datadir" >/dev/null; then
echo " cluster data on dedicated disk: $datadir"
else
echo " WARNING: $datadir is NOT on the dedicated disk" >&2
fi
done
pg_lsclusters --no-header
;;
down)
{ pg_lsclusters --no-header 2>/dev/null || true; } | while read -r ver name _; do
pg_ctlcluster "$ver" "$name" stop 2>/dev/null || true
done
apt-get purge -y 'postgresql*' >/dev/null
apt-get autoremove --purge -y >/dev/null
rm -rf /etc/postgresql
echo " postgres stopped + packages purged (data kept under $PGROOT)"
;;
esac