b7c8d2ed80
Co-authored-by: Cursor <cursoragent@cursor.com>
60 lines
1.8 KiB
Bash
60 lines
1.8 KiB
Bash
#!/bin/bash
|
|
# Установка PostgreSQL 17 (PGDG) или postgresql из Ubuntu
|
|
# sudo bash scripts/install-postgresql-ubuntu.sh
|
|
set -euo pipefail
|
|
|
|
if command -v psql >/dev/null; then
|
|
echo "PostgreSQL уже установлен: $(psql --version | head -1)"
|
|
systemctl enable postgresql 2>/dev/null || true
|
|
systemctl start postgresql 2>/dev/null || true
|
|
exit 0
|
|
fi
|
|
|
|
echo "=== Установка PostgreSQL ==="
|
|
apt update
|
|
apt install -y curl ca-certificates gnupg lsb-release
|
|
|
|
if [ ! -f /etc/os-release ]; then
|
|
echo "Ошибка: не найден /etc/os-release"
|
|
exit 1
|
|
fi
|
|
# shellcheck source=/dev/null
|
|
. /etc/os-release
|
|
CODENAME="${VERSION_CODENAME:-}"
|
|
if [ -z "$CODENAME" ]; then
|
|
echo "Ошибка: не удалось определить VERSION_CODENAME (Ubuntu/Debian?)"
|
|
exit 1
|
|
fi
|
|
|
|
install -d /usr/share/postgresql-common/pgdg
|
|
curl -fsSL https://www.postgresql.org/media/keys/ACCC4CF8.asc \
|
|
-o /usr/share/postgresql-common/pgdg/apt.postgresql.org.asc
|
|
|
|
echo "deb [signed-by=/usr/share/postgresql-common/pgdg/apt.postgresql.org.asc] https://apt.postgresql.org/pub/repos/apt ${CODENAME}-pgdg main" \
|
|
> /etc/apt/sources.list.d/pgdg.list
|
|
|
|
apt update
|
|
|
|
if apt install -y postgresql-17 postgresql-client-17; then
|
|
echo "Установлен PostgreSQL 17 (PGDG)"
|
|
else
|
|
echo "Пакет postgresql-17 недоступен — устанавливаем postgresql из репозитория Ubuntu..."
|
|
apt install -y postgresql postgresql-contrib
|
|
fi
|
|
|
|
systemctl enable postgresql
|
|
systemctl start postgresql
|
|
|
|
for i in $(seq 1 30); do
|
|
if pg_isready -h 127.0.0.1 -p 5432 -q 2>/dev/null; then
|
|
echo "pg_isready: OK"
|
|
psql --version | head -1
|
|
exit 0
|
|
fi
|
|
sleep 1
|
|
done
|
|
|
|
echo "PostgreSQL установлен, но не отвечает на 127.0.0.1:5432"
|
|
echo " journalctl -u postgresql -n 30 --no-pager"
|
|
exit 1
|