[dev-db/postgresql] add from pr with improved init script

This commit is contained in:
2023-05-13 14:20:09 +02:00
parent df53d9636f
commit 19e3768c10
10 changed files with 1467 additions and 0 deletions

View File

@@ -0,0 +1,146 @@
--- a/contrib/Makefile
+++ b/contrib/Makefile
@@ -5,59 +5,9 @@
include $(top_builddir)/src/Makefile.global
SUBDIRS = \
- adminpack \
- amcheck \
- auth_delay \
- auto_explain \
- basic_archive \
- basebackup_to_shell \
- bloom \
- btree_gin \
- btree_gist \
- citext \
- cube \
- dblink \
- dict_int \
- dict_xsyn \
- earthdistance \
- file_fdw \
- fuzzystrmatch \
- hstore \
- intagg \
- intarray \
- isn \
- lo \
- ltree \
oid2name \
- old_snapshot \
- pageinspect \
- passwordcheck \
- pg_buffercache \
- pg_freespacemap \
- pg_prewarm \
- pg_stat_statements \
- pg_surgery \
- pg_trgm \
- pgrowlocks \
- pgstattuple \
- pg_visibility \
- pg_walinspect \
- postgres_fdw \
- seg \
- spi \
- tablefunc \
- tcn \
- test_decoding \
- tsm_system_rows \
- tsm_system_time \
- unaccent \
vacuumlo
-ifeq ($(with_ssl),openssl)
-SUBDIRS += pgcrypto sslinfo
-else
-ALWAYS_SUBDIRS += pgcrypto sslinfo
-endif
ifneq ($(with_uuid),no)
SUBDIRS += uuid-ossp
--- a/src/backend/Makefile
+++ b/src/backend/Makefile
@@ -56,7 +56,7 @@
##########################################################################
-all: submake-libpgport submake-catalog-headers submake-utils-headers postgres $(POSTGRES_IMP)
+all: generated-headers
ifneq ($(PORTNAME), cygwin)
ifneq ($(PORTNAME), win32)
@@ -194,23 +194,7 @@
##########################################################################
-install: all installdirs install-bin
-ifeq ($(PORTNAME), cygwin)
-ifeq ($(MAKE_DLL), true)
- $(INSTALL_DATA) libpostgres.a '$(DESTDIR)$(libdir)/libpostgres.a'
-endif
-endif
-ifeq ($(PORTNAME), win32)
-ifeq ($(MAKE_DLL), true)
- $(INSTALL_DATA) libpostgres.a '$(DESTDIR)$(libdir)/libpostgres.a'
-endif
-endif
- $(MAKE) -C catalog install-data
- $(MAKE) -C tsearch install-data
- $(MAKE) -C utils install-data
- $(INSTALL_DATA) $(srcdir)/libpq/pg_hba.conf.sample '$(DESTDIR)$(datadir)/pg_hba.conf.sample'
- $(INSTALL_DATA) $(srcdir)/libpq/pg_ident.conf.sample '$(DESTDIR)$(datadir)/pg_ident.conf.sample'
- $(INSTALL_DATA) $(srcdir)/utils/misc/postgresql.conf.sample '$(DESTDIR)$(datadir)/postgresql.conf.sample'
+install:
ifeq ($(with_llvm), yes)
install-bin: install-postgres-bitcode
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -14,22 +14,8 @@
include $(top_builddir)/src/Makefile.global
SUBDIRS = \
- initdb \
- pg_amcheck \
- pg_archivecleanup \
- pg_basebackup \
- pg_checksums \
pg_config \
- pg_controldata \
- pg_ctl \
pg_dump \
- pg_resetwal \
- pg_rewind \
- pg_test_fsync \
- pg_test_timing \
- pg_upgrade \
- pg_verifybackup \
- pg_waldump \
pgbench \
psql \
scripts
--- a/src/Makefile
+++ b/src/Makefile
@@ -17,19 +17,11 @@
port \
timezone \
backend \
- backend/utils/mb/conversion_procs \
- backend/snowball \
include \
interfaces \
- backend/replication/libpqwalreceiver \
- backend/replication/pgoutput \
fe_utils \
bin \
- pl \
- makefiles \
- test/regress \
- test/isolation \
- test/perl
+ makefiles
ifeq ($(with_llvm), yes)
SUBDIRS += backend/jit/llvm

View File

@@ -0,0 +1,35 @@
#!/bin/sh
# Copyright 1999-2014 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
eerror() {
echo "$@" >&2
}
# Check that DATA_DIR has been set
if [ -z ${DATA_DIR} ] ; then
eerror "DATA_DIR not set"
exit 1
fi
# Check that DATA_DIR exists
if [ ! -d ${DATA_DIR} ] ; then
eerror "Directory not found: ${DATA_DIR}"
eerror "HINT: Ensure that DATA_DIR points to the right path."
eerror "HINT: Or perhaps you need to create the database cluster:"
eerror " emerge --config dev-db/postgresql:@SLOT@"
exit 1
fi
# Check for the existence of PostgreSQL's config files, and set the
# proper mode and ownership.
# Only three files should be checked as potentially other files
# may be in PGDATA that should not be touched.
for file in postgresql pg_hba pg_ident ; do
file="${PGDATA%/}/${file}.conf"
if [ ! -f ${file} ] ; then
eerror "${file} not found"
eerror "HINT: mv ${DATA_DIR%/}/*.conf ${PGDATA}"
exit 1
fi
done

View File

@@ -0,0 +1,65 @@
# Comma-separated list of directories that contain a unix
# socket. Created and controlled by the related initscript. The
# directories created will be owned root:postgres with mode 1775.
#
# /run/postgresql is the default directory.
PG_SOCKET_DIRECTORIES="/run/postgresql"
# Which port and socket to bind PostgreSQL
PGPORT="5432"
# How long to wait for server to start in seconds
START_TIMEOUT=10
# NICE_QUIT ignores new connections and wait for clients to disconnect from
# server before shutting down. NICE_TIMEOUT in seconds determines how long to
# wait for this to succeed.
NICE_TIMEOUT=60
# Forcefully disconnect clients from server and shut down. This is performed
# after NICE_QUIT. Terminated client connections have their open transactions
# rolled back.
# Set RUDE_QUIT to "NO" to disable. RUDE_TIMEOUT in seconds.
RUDE_QUIT="YES"
RUDE_TIMEOUT=30
# If the server still fails to shutdown, you can force it to quit by setting
# this to YES and a recover-run will execute on the next startup.
# Set FORCE_QUIT to "YES" to enable. FORCE_TIMEOUT in seconds.
FORCE_QUIT="NO"
FORCE_TIMEOUT=2
# Extra options to run postmaster with, e.g.:
# -N is the maximal number of client connections
# -B is the number of shared buffers and has to be at least 2x the value for -N
# Please read the man-page to postmaster for more options. Many of these
# options can be set directly in the configuration file.
#PGOPTS="-N 512 -B 1024"
# Pass extra environment variables. If you have to export environment variables
# for the database process, this can be done here.
# Don't forget to escape quotes.
#PG_EXTRA_ENV="PGPASSFILE=\"/path/to/.pgpass\""
##############################################################################
#
# The following values should not be arbitrarily changed.
#
# `emerge --config dev-db/postgresql:@SLOT@' uses these values to
# determine where to create the data directory, where to place the
# configuration files, and any additional options to pass to initdb.
#
# The initscript also uses these variables to inform PostgreSQL where to find
# its data directory and configuration files.
#
##############################################################################
# Location of configuration files
PGDATA="/etc/postgresql-@SLOT@/"
# Where the data directory is located/to be created
DATA_DIR="/var/lib/postgresql/@SLOT@/data"
# Additional options to pass to initdb.
# See `man initdb' for available options.
PG_INITDB_OPTS="--encoding=UTF8"

View File

@@ -0,0 +1,204 @@
#!/sbin/openrc-run
# Copyright 1999-2023 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
extra_started_commands="reload promote"
PG_CTL="/usr/@LIBDIR@/postgresql-@SLOT@/bin/pg_ctl"
PG_CONTROLDATA="/usr/@LIBDIR@/postgresql-@SLOT@/bin/pg_controldata"
description="PostgreSQL @SLOT@ -- the world's most advanced open source database --
${RC_SERVICE} is a wrapper around pg_ctl with additional administrative checks
and convenience"
# pid is read by fscanf(3) with the first argument which should be integer,
# so this multiple line pidfile can be used.
PIDFILE="${DATA_DIR%/}/postmaster.pid"
get_config() {
[ -f "${PGDATA%/}/postgresql.conf" ] || return 1
eval echo $(sed -e 's:#.*::' "${PGDATA%/}/postgresql.conf" \
| awk '$1 == "'$1'" { print ($2 == "=" ? $3 : $2) }')
}
depend() {
use net
provide postgresql
if [ "$(get_config log_destination)" = "syslog" ] ; then
use logger
fi
}
configured_port=${PGPORT}
config_port() {
local port=$(get_config port)
[ -z ${port} ] || configured_port=${port}
}
checkconfig() {
# Check that DATA_DIR has been set
if [ -z "${DATA_DIR}" ] ; then
eerror "DATA_DIR not set"
eerror "HINT: Perhaps you need to update /etc/conf.d/postgresql-@SLOT@"
return 1
fi
# Check that DATA_DIR exists
if [ ! -d "${DATA_DIR}" ] ; then
eerror "Directory not found: ${DATA_DIR}"
eerror "HINT: Ensure that DATA_DIR points to the right path."
eerror "HINT: Or perhaps you need to create the database cluster:"
eerror " emerge --config dev-db/postgresql:@SLOT@"
return 1
fi
# Check for the existence of PostgreSQL's config files, and set the
# proper mode and ownership.
# Only three files should be checked as potentially other files
# may be in PGDATA that should not be touched.
local file
for file in postgresql pg_hba pg_ident ; do
file="${PGDATA%/}/${file}.conf"
if [ -f "${file}" ] ; then
checkpath -f -m 0600 -o postgres:postgres "${file}"
else
eerror "${file} not found"
eerror "HINT: mv ${DATA_DIR%/}/*.conf ${PGDATA}"
return 1
fi
done
# Set the proper permission for the socket paths and create it if
# it doesn't exist.
set -f
local IFS=',' s
for s in ${PG_SOCKET_DIRECTORIES}; do
checkpath -d -m 1775 -o root:postgres "${s}"
if [ -e "${s%/}/.s.PGSQL.${configured_port}" ] ; then
eerror "Socket conflict."
eerror "A server is already listening on:"
eerror " ${s%/}/.s.PGSQL.${configured_port}"
eerror "HINT: Change PGPORT to listen on a different socket."
return 1
fi
done
set +f
}
start() {
config_port
checkconfig || return 1
ebegin "Starting PostgreSQL @SLOT@"
rm -f "${DATA_DIR%/}/postmaster.pid"
export PGPORT=${configured_port}
eval "${PG_EXTRA_ENV:+export} ${PG_EXTRA_ENV}"
start-stop-daemon --start --user postgres:postgres \
--pidfile "${PIDFILE}" \
--exec "${PG_CTL}" -- \
start \
-s -w -t ${START_TIMEOUT} -l "${DATA_DIR%/}/postmaster.log" \
-D "${PGDATA}" \
-o "-c data_directory=\"${DATA_DIR}\" \
-c unix_socket_directories=\"${PG_SOCKET_DIRECTORIES}\" \
${PGOPTS}"
local retval=$?
if [ ${retval} -ne 0 ] ; then
eerror "Check the log for a possible explanation of the above error."
eerror "The log may be located at:"
eerror " ${DATA_DIR%/}/postmaster.log"
eerror "Or wherever you configured PostgreSQL @SLOT@ to log."
fi
eend ${retval}
}
stop() {
: "${NICE_TIMEOUT:=5}"
: "${RUDE_TIMEOUT:=5}"
: "${FORCE_TIMEOUT:=5}"
# The SIGTERM is the default signal for s-s-d, and corresponds to the
# default stop mode 'smart' of postgres.
local retry="SIGTERM/${NICE_TIMEOUT}"
local seconds=${NICE_TIMEOUT}
if yesno RUDE_QUIT; then
# retry fast stop mode after NICE_TIMEOUT
retry="${retry}/SIGINT/${RUDE_TIMEOUT}"
seconds=$(( ${seconds} + ${RUDE_TIMEOUT} ))
fi
if yesno FORCE_QUIT; then
# retry immediate stop mode after RUDE_TIMEOUT
retry="${retry}/SIGQUIT/${FORCE_TIMEOUT}"
seconds=$(( ${seconds} + ${FORCE_TIMEOUT} ))
fi
ebegin "Stopping PostgreSQL @SLOT@ (this can take up to ${seconds} seconds)"
start-stop-daemon --stop --retry ${retry} --pidfile ${PIDFILE}
local retval=$?
if [ ${retval} -eq 0 ] ; then
# clean up remaining socket files for the case which postgres has crashed before stopping
config_port
local IFS=',' s
for s in ${PG_SOCKET_DIRECTORIES}; do
if ls -1 "${s%/}/.s.PGSQL.${configured_port}"* >/dev/null 2>&1; then
ewarn "cleaning up remaining socket files in '$s'"
rm -vf "${s%/}/.s.PGSQL.${configured_port}"*
fi
done
fi
eend ${retval}
}
status() {
default_status
local retval=$?
local postopts_file="${DATA_DIR%/}/postmaster.opts"
if [ $retval -eq 0 -a -r "${postopts_file}" ] ; then
einfo "opts: $(cat ${postopts_file})"
fi
}
description_reload="Simply sends the postgres process a SIGHUP signal, causing
it to reread its configuration files (postgresql.conf, pg_hba.conf,
etc.). This allows changing of configuration-file options that do not
require a complete restart to take effect."
reload() {
ebegin "Reloading PostgreSQL @SLOT@ configuration"
start-stop-daemon \
--signal SIGHUP \
--user postgres:postgres \
--pidfile "${PIDFILE}"
eend $?
}
description_promote="If the server is in standby, it is commanded to exit
recovery and begin read-write operations."
promote() {
ebegin "Promoting PostgreSQL @SLOT@"
local retval=1
if "${PG_CONTROLDATA}" -D "${DATA_DIR}" 2>/dev/null \
| grep 'in archive recovery' >/dev/null 2>&1; then
local promotefile="${DATA_DIR%/}/promote"
checkpath -q -f -m 644 -o postgres:postgres "${promotefile}" && \
start-stop-daemon \
--signal SIGUSR1 \
--user postgres:postgres \
--pidfile "${PIDFILE}"
retval=$?
if [ ${retval} -ne 0 ] ; then
rm -f "${promotefile}"
fi
else
eerror "server is not in standby mode"
fi
eend ${retval}
}

View File

@@ -0,0 +1,52 @@
# It's not recommended to modify this file in-place, because it will be
# overwritten during package upgrades. If you want to customize, the
# best way is to create file
# "/etc/systemd/system/postgresql-@SLOT@.service.d/*.conf"
# containing your changes
# For example, if you want to change the server's port number to 5433,
# create a file named
# "/etc/systemd/system/postgresql-@SLOT@.service.d/port.conf"
# containing:
# [Service]
# Environment=PGPORT=5433
# This will override the setting appearing below.
[Unit]
Description=PostgreSQL database server
After=network.target
[Service]
Type=notify
User=postgres
Group=postgres
# Port number for server to listen on
Environment=PGPORT=5432
# Location of configuration files
Environment=PGDATA=/etc/postgresql-@SLOT@
# Where the data directory is located
Environment=DATA_DIR=/var/lib/postgresql/@SLOT@/data
# Where to send early-startup messages from the server (before the logging
# options of postgresql.conf take effect)
# This is normally controlled by the global default set by systemd
# StandardOutput=syslog
ExecStartPre=/usr/bin/postgresql-@SLOT@-check-db-dir
ExecStart=/usr/@LIBDIR@/postgresql-@SLOT@/bin/postgres -p ${PGPORT} -D ${DATA_DIR}
ExecReload=/bin/kill -HUP $MAINPID
KillMode=mixed
KillSignal=SIGINT
# Give a reasonable amount of time for the server to start up/shut down
TimeoutSec=300
# Disable OOM kill on the postmaster
OOMScoreAdjust=-1000
[Install]
WantedBy=multi-user.target

View File

@@ -0,0 +1 @@
d /run/postgresql 1775 root postgres -