mirror of
https://github.com/community-scripts/ProxmoxVE.git
synced 2026-03-19 16:33:01 +01:00
Compare commits
6 Commits
fix/tdarr-
...
MickLesk-p
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
87cbfcea70 | ||
|
|
7c79b278eb | ||
|
|
ee01971321 | ||
|
|
aede3fe092 | ||
|
|
c0da26c179 | ||
|
|
be10f822e5 |
@@ -6698,22 +6698,38 @@ EOF
|
||||
# - Optionally uses official PGDG repository for specific versions
|
||||
# - Detects existing PostgreSQL version
|
||||
# - Dumps all databases before upgrade
|
||||
# - Installs optional PG_MODULES (e.g. postgis, contrib)
|
||||
# - Installs optional PG_MODULES (e.g. postgis, contrib, cron)
|
||||
# - Restores dumped data post-upgrade
|
||||
#
|
||||
# Variables:
|
||||
# USE_PGDG_REPO - Use official PGDG repository (default: true)
|
||||
# Set to "false" to use distro packages instead
|
||||
# PG_VERSION - Major PostgreSQL version (e.g. 15, 16) (default: 16)
|
||||
# PG_MODULES - Comma-separated list of modules (e.g. "postgis,contrib")
|
||||
# PG_MODULES - Comma-separated list of modules (e.g. "postgis,contrib,cron")
|
||||
#
|
||||
# Examples:
|
||||
# setup_postgresql # Uses PGDG repo, PG 16
|
||||
# PG_VERSION="17" setup_postgresql # Specific version from PGDG
|
||||
# USE_PGDG_REPO=false setup_postgresql # Uses distro package instead
|
||||
# setup_postgresql # Uses PGDG repo, PG 16
|
||||
# PG_VERSION="17" setup_postgresql # Specific version from PGDG
|
||||
# USE_PGDG_REPO=false setup_postgresql # Uses distro package instead
|
||||
# PG_VERSION="17" PG_MODULES="cron" setup_postgresql # With pg_cron module
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
function setup_postgresql() {
|
||||
# Internal helper: Configure shared_preload_libraries for pg_cron
|
||||
_configure_pg_cron_preload() {
|
||||
local modules="${1:-}"
|
||||
[[ -z "$modules" ]] && return 0
|
||||
if [[ ",$modules," == *",cron,"* ]]; then
|
||||
local current_libs
|
||||
current_libs=$(sudo -u postgres psql -tAc "SHOW shared_preload_libraries;" 2>/dev/null || echo "")
|
||||
if [[ "$current_libs" != *"pg_cron"* ]]; then
|
||||
local new_libs="${current_libs:+${current_libs},}pg_cron"
|
||||
$STD sudo -u postgres psql -c "ALTER SYSTEM SET shared_preload_libraries = '${new_libs}';"
|
||||
$STD systemctl restart postgresql
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
setup_postgresql() {
|
||||
local PG_VERSION="${PG_VERSION:-16}"
|
||||
local PG_MODULES="${PG_MODULES:-}"
|
||||
local USE_PGDG_REPO="${USE_PGDG_REPO:-true}"
|
||||
@@ -6751,6 +6767,7 @@ function setup_postgresql() {
|
||||
$STD apt install -y "postgresql-${CURRENT_PG_VERSION}-${module}" 2>/dev/null || true
|
||||
done
|
||||
fi
|
||||
_configure_pg_cron_preload "$PG_MODULES"
|
||||
return 0
|
||||
fi
|
||||
|
||||
@@ -6786,6 +6803,7 @@ function setup_postgresql() {
|
||||
$STD apt install -y "postgresql-${INSTALLED_VERSION}-${module}" 2>/dev/null || true
|
||||
done
|
||||
fi
|
||||
_configure_pg_cron_preload "$PG_MODULES"
|
||||
return 0
|
||||
fi
|
||||
|
||||
@@ -6807,6 +6825,7 @@ function setup_postgresql() {
|
||||
$STD apt install -y "postgresql-${PG_VERSION}-${module}" 2>/dev/null || true
|
||||
done
|
||||
fi
|
||||
_configure_pg_cron_preload "$PG_MODULES"
|
||||
return 0
|
||||
fi
|
||||
|
||||
@@ -6834,13 +6853,16 @@ function setup_postgresql() {
|
||||
local SUITE
|
||||
case "$DISTRO_CODENAME" in
|
||||
trixie | forky | sid)
|
||||
|
||||
if verify_repo_available "https://apt.postgresql.org/pub/repos/apt" "trixie-pgdg"; then
|
||||
SUITE="trixie-pgdg"
|
||||
|
||||
else
|
||||
msg_warn "PGDG repo not available for ${DISTRO_CODENAME}, falling back to distro packages"
|
||||
USE_PGDG_REPO=false setup_postgresql
|
||||
return $?
|
||||
fi
|
||||
|
||||
;;
|
||||
*)
|
||||
SUITE=$(get_fallback_suite "$DISTRO_ID" "$DISTRO_CODENAME" "https://apt.postgresql.org/pub/repos/apt")
|
||||
@@ -6924,6 +6946,7 @@ function setup_postgresql() {
|
||||
}
|
||||
done
|
||||
fi
|
||||
_configure_pg_cron_preload "$PG_MODULES"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
@@ -6942,6 +6965,7 @@ function setup_postgresql() {
|
||||
# PG_DB_NAME="immich" PG_DB_USER="immich" PG_DB_EXTENSIONS="pgvector" setup_postgresql_db
|
||||
# PG_DB_NAME="ghostfolio" PG_DB_USER="ghostfolio" PG_DB_GRANT_SUPERUSER="true" setup_postgresql_db
|
||||
# PG_DB_NAME="adventurelog" PG_DB_USER="adventurelog" PG_DB_EXTENSIONS="postgis" setup_postgresql_db
|
||||
# PG_DB_NAME="splitpro" PG_DB_USER="splitpro" PG_DB_EXTENSIONS="pg_cron" setup_postgresql_db
|
||||
#
|
||||
# Variables:
|
||||
# PG_DB_NAME - Database name (required)
|
||||
@@ -6973,6 +6997,13 @@ function setup_postgresql_db() {
|
||||
$STD sudo -u postgres psql -c "CREATE ROLE $PG_DB_USER WITH LOGIN PASSWORD '$PG_DB_PASS';"
|
||||
$STD sudo -u postgres psql -c "CREATE DATABASE $PG_DB_NAME WITH OWNER $PG_DB_USER ENCODING 'UTF8' TEMPLATE template0;"
|
||||
|
||||
# Configure pg_cron database BEFORE creating the extension (must be set before pg_cron loads)
|
||||
if [[ -n "${PG_DB_EXTENSIONS:-}" ]] && [[ ",${PG_DB_EXTENSIONS//[[:space:]]/}," == *",pg_cron,"* ]]; then
|
||||
$STD sudo -u postgres psql -c "ALTER SYSTEM SET cron.database_name = '${PG_DB_NAME}';"
|
||||
$STD sudo -u postgres psql -c "ALTER SYSTEM SET cron.timezone = 'UTC';"
|
||||
$STD systemctl restart postgresql
|
||||
fi
|
||||
|
||||
# Install extensions (comma-separated)
|
||||
if [[ -n "${PG_DB_EXTENSIONS:-}" ]]; then
|
||||
IFS=',' read -ra EXT_LIST <<<"${PG_DB_EXTENSIONS:-}"
|
||||
@@ -6982,6 +7013,12 @@ function setup_postgresql_db() {
|
||||
done
|
||||
fi
|
||||
|
||||
# Grant pg_cron schema permissions to DB user
|
||||
if [[ -n "${PG_DB_EXTENSIONS:-}" ]] && [[ ",${PG_DB_EXTENSIONS//[[:space:]]/}," == *",pg_cron,"* ]]; then
|
||||
$STD sudo -u postgres psql -d "$PG_DB_NAME" -c "GRANT USAGE ON SCHEMA cron TO ${PG_DB_USER};"
|
||||
$STD sudo -u postgres psql -d "$PG_DB_NAME" -c "GRANT ALL ON ALL TABLES IN SCHEMA cron TO ${PG_DB_USER};"
|
||||
fi
|
||||
|
||||
# ALTER ROLE settings for Django/Rails compatibility (unless skipped)
|
||||
if [[ "${PG_DB_SKIP_ALTER_ROLE:-}" != "true" ]]; then
|
||||
$STD sudo -u postgres psql -c "ALTER ROLE $PG_DB_USER SET client_encoding TO 'utf8';"
|
||||
@@ -7023,7 +7060,6 @@ function setup_postgresql_db() {
|
||||
export PG_DB_USER
|
||||
export PG_DB_PASS
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Installs rbenv and ruby-build, installs Ruby and optionally Rails.
|
||||
#
|
||||
|
||||
Reference in New Issue
Block a user