Script de inicio Systemgres postgresql


14

Estoy en el proceso de instalar postgresql en un segundo servidor

Anteriormente instalé postgresql y luego usé el script proporcionado

./contrib/start-scripts/linux

Colocado en el directorio correcto

# cp ./contrib/start-scripts/linux /etc/rc.d/init.d/postgresql92
# chmod 755 /etc/rc.d/init.d/postgresql92

Que luego podría ejecutar como se esperaba con

# service postgresql92 start

Sin embargo, la nueva máquina está usando Systemd y parece que hay una forma completamente diferente de hacerlo

No quiero hackear esto y arruinar algo, así que me preguntaba si alguien por ahí podría señalarme en la dirección correcta de cómo lograr el mismo resultado.

Respuestas:


21

Al instalar desde la fuente, deberá agregar un archivo de unidad systemd que funcione con la instalación de la fuente. Para RHEL, Fedora mi archivo de unidad se ve así:

/usr/lib/systemd/system/postgresql.service

[Unit]
Description=PostgreSQL database server
After=network.target

[Service]
Type=forking

User=postgres
Group=postgres

# 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

# Disable OOM kill on the postmaster
OOMScoreAdjust=-1000
# ... but allow it still to be effective for child processes
# (note that these settings are ignored by Postgres releases before 9.5)
Environment=PG_OOM_ADJUST_FILE=/proc/self/oom_score_adj
Environment=PG_OOM_ADJUST_VALUE=0

# Maximum number of seconds pg_ctl will wait for postgres to start.  Note that
# PGSTARTTIMEOUT should be less than TimeoutSec value.
Environment=PGSTARTTIMEOUT=270

Environment=PGDATA=/usr/local/pgsql/data


ExecStart=/usr/local/pgsql/bin/pg_ctl start -D ${PGDATA} -s -w -t ${PGSTARTTIMEOUT}
ExecStop=/usr/local/pgsql/bin/pg_ctl stop -D ${PGDATA} -s -m fast
ExecReload=/usr/local/pgsql/bin/pg_ctl reload -D ${PGDATA} -s

# Give a reasonable amount of time for the server to start up/shut down.
# Ideally, the timeout for starting PostgreSQL server should be handled more
# nicely by pg_ctl in ExecStart, so keep its timeout smaller than this value.
TimeoutSec=300

[Install]
WantedBy=multi-user.target

Luego habilite el servicio al inicio e inicie el servicio PostgreSQL:

$ sudo systemctl daemon-reload # load the updated service file from disk
$ sudo systemctl enable postgresql
$ sudo systemctl start postgresql

6
# systemctl start postgresql.service

Algunos entornos se traducirían service <name> starta systemctl start <name>.service, pero no tiene que confiar en ello.


Pero, ¿dónde colocaría el script postgresql92?
— TheLovelySausage

Ya no lo usas en systemd. Su distribución debe proporcionarle el archivo de servicio systemd postgresql para que pueda iniciar el servicio.
— Emeric

Sin embargo, el postgresql se instaló desde la fuente, sin usar dnf porque necesito instalar 3 versiones de postgres en directorios específicos, ¿es posible usar el archivo linux de start-scripts suministrado para iniciar postgresql?
— TheLovelySausage

Mi distribución agrega este script como /usr/lib/systemd/system/postgresql.service. Los guiones de inicio proporcionados por postgresql parecen cubrir solo SysV.
— Emeric

¿Instalaste postgres usando dnf o yum?
— TheLovelySausage

0

El archivo de unidad systemctl publicado arriba me ayuda mucho, pero para crear el que necesita solo tiene que ponerlo:

/etc/systemd/system/postgresql92.service
systemctl enable postgresql92.service
systemctl start postgresql92.service

Piense en cambiar la ruta binay pg_ctl de acuerdo con su instalación, y si desea ejecutar otra instancia, también debe cambiar el puerto de escucha predeterminado:

ExecStart=/usr/local/pgsql/bin/pg_ctl -o "-p 5489"
Al usar nuestro sitio, usted reconoce que ha leído y comprende nuestra Política de Cookies y Política de Privacidad.
Licensed under cc by-sa 3.0 with attribution required.