I have PostgreSQL-11 installed on Ubuntu 18.04 via apt-get, and based from here, I managed to install 2 instances of postgreSQL on port 5432 and 5433.
My Question is, can I have separate start-stop script for these two instances? As my other server running postgresql 9.6 on Centos 7, has several startup script which are:
postgresql-9.6-instanceA.service
postgresql-9.6-instanceB.service
postgresql-9.6-instanceC.service
postgresql-9.6-instanceD.service
postgresql-9.6-instanceE.service
Where those files difference only in the environment (notice the Environment section):
[root@root]# cat /etc/systemd/system/postgresql-9.6-instanceA.service
# 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 a file "/etc/systemd/system/postgresql-9.6.service",
# containing
# .include /lib/systemd/system/postgresql-9.6.service
# ...make your changes here...
# For more info about custom unit files, see
# http://fedoraproject.org/wiki/Systemd#How_do_I_customize_a_unit_file.2F_add_a_custom_unit_file.3F
# Note: changing PGDATA will typically require adjusting SELinux
# configuration as well.
# Note: do not use a PGDATA pathname containing spaces, or you will
# break postgresql-setup.
[Unit]
Description=PostgreSQL 9.6 database server
Documentation=https://www.postgresql.org/docs/9.6/static/
After=syslog.target
After=network.target
[Service]
Type=notify
User=postgres
Group=postgres
# Note: avoid inserting whitespace in these Environment= lines, or you may
# break postgresql-setup.
# Location of database directory
Environment=PGDATA=/var/lib/pgsql/instanceA/9.6/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
# Disable OOM kill on the postmaster
OOMScoreAdjust=-1000
Environment=PG_OOM_ADJUST_FILE=/proc/self/oom_score_adj
Environment=PG_OOM_ADJUST_VALUE=0
ExecStartPre=/usr/pgsql-9.6/bin/postgresql96-check-db-dir ${PGDATA}
ExecStart=/usr/pgsql-9.6/bin/postmaster -D ${PGDATA}
ExecReload=/bin/kill -HUP $MAINPID
KillMode=mixed
KillSignal=SIGINT
# Do not set any timeout value, so that systemd will not kill postmaster
# during crash recovery.
TimeoutSec=0
[Install]
WantedBy=multi-user.target
Based from what I read here, the script above can be created if the installation is from source, thus we need to add systemd unit file.
These are the content of the systemd script on my ubuntu server.
These below are the postgresql.service
file on my ubuntu 18.04:
The first one is /var/lib/systemd/deb-systemd-helper-enabled/multi-user.target.wants/postgresql.service
, which is empty:
root@hostname:~# ls -lah /var/lib/systemd/deb-systemd-helper-enabled/multi-user.target.wants/postgresql.service
-rw-r--r-- 1 root root 0 Feb 25 03:50 /var/lib/systemd/deb-systemd-helper-enabled/multi-user.target.wants/postgresql.service
The second and third file has the same content:
/etc/systemd/system/multi-user.target.wants/postgresql.service
/lib/systemd/system/postgresql.service
# systemd service for managing all PostgreSQL clusters on the system. This
# service is actually a systemd target, but we are using a service since
# targets cannot be reloaded.
[Unit]
Description=PostgreSQL RDBMS
[Service]
Type=oneshot
ExecStart=/bin/true
ExecReload=/bin/true
RemainAfterExit=on
[Install]
WantedBy=multi-user.target
So again, can I have such situation with my ubuntu server? So that I can have start-stop-reload-restart script for my two postgres instances, as I'm not sure where or which file to edit.