2026-09-23 15:19:50
This commit is contained in:
1 parent
e808725578
commit
5ea2bdbed7
12 files changed
+642
No files matched your search
@@ -0,0 +1,89 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -Eeuo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
|
||||
readonly INVOCATION_DIR="$PWD"
|
||||
|
||||
[[ $# -eq 1 ]] || {
|
||||
printf 'Usage: %s <postgresql-version>\n' "$0" >&2
|
||||
exit 2
|
||||
}
|
||||
readonly POSTGRES_VERSION="$1"
|
||||
readonly PROCESS_LOG="$INVOCATION_DIR/postgresql-$POSTGRES_VERSION-process.log"
|
||||
readonly ENGINE_ARCHIVE="$INVOCATION_DIR/postgresql-$POSTGRES_VERSION-engine.tar.gz"
|
||||
|
||||
exec > >(tee "$PROCESS_LOG") 2>&1
|
||||
|
||||
printf 'Installation started: %s\n' "$(date -Is)"
|
||||
printf 'Invocation directory: %s\n' "$INVOCATION_DIR"
|
||||
|
||||
"$SCRIPT_DIR/install_postgresql.sh" "$POSTGRES_VERSION"
|
||||
"$SCRIPT_DIR/install_pg_cron.sh" "$POSTGRES_VERSION"
|
||||
"$SCRIPT_DIR/install_timescaledb.sh" "$POSTGRES_VERSION"
|
||||
"$SCRIPT_DIR/install_pgaudit.sh" "$POSTGRES_VERSION"
|
||||
"$SCRIPT_DIR/install_set_user.sh" "$POSTGRES_VERSION"
|
||||
"$SCRIPT_DIR/install_pg_stat_statements.sh" "$POSTGRES_VERSION"
|
||||
"$SCRIPT_DIR/install_pg_repack.sh" "$POSTGRES_VERSION"
|
||||
"$SCRIPT_DIR/install_pg_stat_monitor.sh" "$POSTGRES_VERSION"
|
||||
|
||||
readonly POSTGRES_ROOT="${POSTGRES_ROOT:-/app/postgres/rdbms}"
|
||||
readonly PREFIX="$POSTGRES_ROOT/$POSTGRES_VERSION"
|
||||
readonly CONFIG_FILE="${CONFIG_FILE:-}"
|
||||
readonly SHARED_PRELOAD_LIBRARIES="pg_cron,timescaledb,pgaudit,pg_stat_statements,pg_stat_monitor"
|
||||
|
||||
if [[ -n "$CONFIG_FILE" ]]; then
|
||||
[[ -f "$CONFIG_FILE" ]] || {
|
||||
printf 'ERROR: configuration file does not exist: %s\n' "$CONFIG_FILE" >&2
|
||||
exit 1
|
||||
}
|
||||
python3 - "$CONFIG_FILE" <<'PY'
|
||||
import pathlib
|
||||
import re
|
||||
import sys
|
||||
|
||||
path = pathlib.Path(sys.argv[1])
|
||||
text = path.read_text()
|
||||
pattern = r"(?m)^[ \t]*(#?)[ \t]*shared_preload_libraries[ \t]*=[ \t]*'([^']*)'[^\n]*$"
|
||||
match = re.search(pattern, text)
|
||||
required = ("pg_cron", "timescaledb", "pgaudit", "pg_stat_statements", "pg_stat_monitor")
|
||||
if match:
|
||||
libraries = [item.strip() for item in match.group(2).split(",") if item.strip()]
|
||||
for library in required:
|
||||
if library not in libraries:
|
||||
libraries.append(library)
|
||||
line = "shared_preload_libraries = '" + ",".join(libraries) + "'\\t# (change requires restart)"
|
||||
text = re.sub(pattern, line, text, count=1)
|
||||
else:
|
||||
text = text.rstrip("\n") + "\n\nshared_preload_libraries = '" + ",".join(required) + "'\\t# (change requires restart)\n"
|
||||
path.write_text(text)
|
||||
PY
|
||||
fi
|
||||
|
||||
printf 'Installed PostgreSQL and extensions in %s\n' "$PREFIX"
|
||||
if [[ -n "$CONFIG_FILE" ]]; then
|
||||
grep -E '^[[:space:]]*shared_preload_libraries[[:space:]]*=' "$CONFIG_FILE"
|
||||
fi
|
||||
|
||||
extension_version() {
|
||||
local extension="$1"
|
||||
awk -F"'" '/^[[:space:]]*default_version[[:space:]]*=/{print $2; exit}' \
|
||||
"$PREFIX/share/extension/$extension.control"
|
||||
}
|
||||
|
||||
printf '\nInstalled products and extensions:\n'
|
||||
printf ' PostgreSQL: %s\n' "$("$PREFIX/bin/pg_config" --version | sed 's/^PostgreSQL //')"
|
||||
printf ' pg_cron: %s\n' "$(extension_version pg_cron)"
|
||||
printf ' TimescaleDB: %s\n' "$(extension_version timescaledb)"
|
||||
printf ' pgaudit: %s\n' "$(extension_version pgaudit)"
|
||||
printf ' set_user: %s\n' "$(extension_version set_user)"
|
||||
printf ' pg_stat_statements: %s\n' "$(extension_version pg_stat_statements)"
|
||||
printf ' pg_repack: %s\n' "$(extension_version pg_repack)"
|
||||
printf ' pg_stat_monitor: %s\n' "$(extension_version pg_stat_monitor)"
|
||||
printf " shared_preload_libraries = '%s'\n" "$SHARED_PRELOAD_LIBRARIES"
|
||||
|
||||
rm -f -- "$ENGINE_ARCHIVE"
|
||||
tar -czf "$ENGINE_ARCHIVE" -C "$POSTGRES_ROOT" "$POSTGRES_VERSION"
|
||||
printf '\nCreated engine archive: %s\n' "$ENGINE_ARCHIVE"
|
||||
printf 'Archive size: %s\n' "$(du -h "$ENGINE_ARCHIVE" | awk '{print $1}')"
|
||||
printf 'Installation completed: %s\n' "$(date -Is)"
|
||||
Reference in new issue
Block a user