summaryrefslogtreecommitdiffstats
path: root/systemd/system
diff options
context:
space:
mode:
Diffstat (limited to 'systemd/system')
-rw-r--r--systemd/system/pg_basebackup@.service14
-rw-r--r--systemd/system/pg_basebackup@.timer12
-rw-r--r--systemd/system/pg_compresswal@.service9
-rw-r--r--systemd/system/pg_compresswal@.timer12
-rw-r--r--systemd/system/pg_dump@.service14
-rw-r--r--systemd/system/pg_dump@.timer12
-rw-r--r--systemd/system/pg_receivewal@.service21
-rw-r--r--systemd/system/postgresql.service18
-rw-r--r--systemd/system/postgresql@.service40
9 files changed, 152 insertions, 0 deletions
diff --git a/systemd/system/pg_basebackup@.service b/systemd/system/pg_basebackup@.service
new file mode 100644
index 0000000..011c11e
--- /dev/null
+++ b/systemd/system/pg_basebackup@.service
@@ -0,0 +1,14 @@
+[Unit]
+Description=Basebackup of PostgreSQL Cluster %i
+AssertPathExists=/etc/postgresql/%I/postgresql.conf
+Wants=postgresql@%i.service
+After=postgresql@%i.service
+RequiresMountsFor=/var/backups/postgresql
+
+[Service]
+Type=oneshot
+User=postgres
+Environment="KEEP=3"
+ExecStartPre=+/usr/bin/pg_backupcluster %i createdirectory
+ExecStart=/usr/bin/pg_backupcluster %i basebackup
+ExecStart=/usr/bin/pg_backupcluster %i expirebasebackups $KEEP
diff --git a/systemd/system/pg_basebackup@.timer b/systemd/system/pg_basebackup@.timer
new file mode 100644
index 0000000..da0bb3f
--- /dev/null
+++ b/systemd/system/pg_basebackup@.timer
@@ -0,0 +1,12 @@
+[Unit]
+Description=Weekly Basebackup of PostgreSQL Cluster %i
+AssertPathExists=/etc/postgresql/%I/postgresql.conf
+
+[Timer]
+OnCalendar=weekly
+RandomizedDelaySec=1h
+FixedRandomDelay=true
+
+[Install]
+# when enabled, start along with postgresql@%i
+WantedBy=postgresql@%i.service
diff --git a/systemd/system/pg_compresswal@.service b/systemd/system/pg_compresswal@.service
new file mode 100644
index 0000000..e5eae6b
--- /dev/null
+++ b/systemd/system/pg_compresswal@.service
@@ -0,0 +1,9 @@
+[Unit]
+Description=Compress WAL of PostgreSQL Cluster %i
+AssertPathExists=/etc/postgresql/%I/postgresql.conf
+RequiresMountsFor=/var/backups/postgresql
+
+[Service]
+Type=oneshot
+User=postgres
+ExecStart=/usr/bin/pg_backupcluster %i compresswal
diff --git a/systemd/system/pg_compresswal@.timer b/systemd/system/pg_compresswal@.timer
new file mode 100644
index 0000000..6dddbb9
--- /dev/null
+++ b/systemd/system/pg_compresswal@.timer
@@ -0,0 +1,12 @@
+[Unit]
+Description=Daily Compress WAL of PostgreSQL Cluster %i
+AssertPathExists=/etc/postgresql/%I/postgresql.conf
+
+[Timer]
+OnCalendar=daily
+RandomizedDelaySec=1h
+FixedRandomDelay=true
+
+[Install]
+# when enabled, start along with pg_receivewal@%i
+WantedBy=pg_receivewal@%i.service
diff --git a/systemd/system/pg_dump@.service b/systemd/system/pg_dump@.service
new file mode 100644
index 0000000..a7f7f3d
--- /dev/null
+++ b/systemd/system/pg_dump@.service
@@ -0,0 +1,14 @@
+[Unit]
+Description=Dump of PostgreSQL Cluster %i
+AssertPathExists=/etc/postgresql/%I/postgresql.conf
+Wants=postgresql@%i.service
+After=postgresql@%i.service
+RequiresMountsFor=/var/backups/postgresql
+
+[Service]
+Type=oneshot
+User=postgres
+Environment="KEEP=3"
+ExecStartPre=+/usr/bin/pg_backupcluster %i createdirectory
+ExecStart=/usr/bin/pg_backupcluster %i dump
+ExecStart=/usr/bin/pg_backupcluster %i expiredumps $KEEP
diff --git a/systemd/system/pg_dump@.timer b/systemd/system/pg_dump@.timer
new file mode 100644
index 0000000..a1d2799
--- /dev/null
+++ b/systemd/system/pg_dump@.timer
@@ -0,0 +1,12 @@
+[Unit]
+Description=Weekly Dump of PostgreSQL Cluster %i
+AssertPathExists=/etc/postgresql/%I/postgresql.conf
+
+[Timer]
+OnCalendar=weekly
+RandomizedDelaySec=1h
+FixedRandomDelay=true
+
+[Install]
+# when enabled, start along with postgresql@%i
+WantedBy=postgresql@%i.service
diff --git a/systemd/system/pg_receivewal@.service b/systemd/system/pg_receivewal@.service
new file mode 100644
index 0000000..a15b432
--- /dev/null
+++ b/systemd/system/pg_receivewal@.service
@@ -0,0 +1,21 @@
+[Unit]
+Description=WAL archival of PostgreSQL Cluster %i
+AssertPathExists=/etc/postgresql/%I/postgresql.conf
+Wants=postgresql@%i.service
+After=postgresql@%i.service
+RequiresMountsFor=/var/backups/postgresql
+
+[Service]
+Type=simple
+User=postgres
+ExecStartPre=+/usr/bin/pg_backupcluster %i createdirectory
+ExecStart=/usr/bin/pg_backupcluster %i receivewal
+Restart=on-failure
+RestartSec=1min
+# pg_receivewal only flushes compressed output on SIGINT
+# (https://www.postgresql.org/message-id/flat/Yvo/5No5S0c4EFMj%40msg.df7cb.de)
+KillSignal=SIGINT
+
+[Install]
+# when enabled, start along with postgresql@%i
+WantedBy=postgresql@%i.service
diff --git a/systemd/system/postgresql.service b/systemd/system/postgresql.service
new file mode 100644
index 0000000..f53834e
--- /dev/null
+++ b/systemd/system/postgresql.service
@@ -0,0 +1,18 @@
+# postgresql.service is the meta unit for managing all PostgreSQL clusters on
+# the system at once. Conceptually, this unit is more like a systemd target,
+# but we are using a service since targets cannot be reloaded.
+#
+# The unit actually managing PostgreSQL clusters is postgresql@.service,
+# instantiated as postgresql@15-main.service for individual clusters.
+
+[Unit]
+Description=PostgreSQL RDBMS
+
+[Service]
+Type=oneshot
+ExecStart=/bin/true
+ExecReload=/bin/true
+RemainAfterExit=on
+
+[Install]
+WantedBy=multi-user.target
diff --git a/systemd/system/postgresql@.service b/systemd/system/postgresql@.service
new file mode 100644
index 0000000..8eed65c
--- /dev/null
+++ b/systemd/system/postgresql@.service
@@ -0,0 +1,40 @@
+# systemd service template for PostgreSQL clusters. The actual instances will
+# be called "postgresql@version-cluster", e.g. "postgresql@9.3-main". The
+# variable %i expands to "version-cluster", %I expands to "version/cluster".
+# (%I breaks for cluster names containing dashes.)
+
+[Unit]
+Description=PostgreSQL Cluster %i
+AssertPathExists=/etc/postgresql/%I/postgresql.conf
+RequiresMountsFor=/etc/postgresql/%I /var/lib/postgresql/%I
+PartOf=postgresql.service
+ReloadPropagatedFrom=postgresql.service
+Before=postgresql.service
+# stop server before networking goes down on shutdown
+After=network.target
+
+[Service]
+Type=forking
+# -: ignore startup failure (recovery might take arbitrarily long)
+# the actual pg_ctl timeout is configured in pg_ctl.conf
+ExecStart=-/usr/bin/pg_ctlcluster --skip-systemctl-redirect %i start
+# 0 is the same as infinity, but "infinity" needs systemd 229
+TimeoutStartSec=0
+ExecStop=/usr/bin/pg_ctlcluster --skip-systemctl-redirect -m fast %i stop
+TimeoutStopSec=1h
+ExecReload=/usr/bin/pg_ctlcluster --skip-systemctl-redirect %i reload
+PIDFile=/run/postgresql/%i.pid
+SyslogIdentifier=postgresql@%i
+# prevent OOM killer from choosing the postmaster (individual backends will
+# reset the score to 0)
+OOMScoreAdjust=-900
+# restarting automatically will prevent "pg_ctlcluster ... stop" from working,
+# so we disable it here. Also, the postmaster will restart by itself on most
+# problems anyway, so it is questionable if one wants to enable external
+# automatic restarts.
+#Restart=on-failure
+# (This should make pg_ctlcluster stop work, but doesn't:)
+#RestartPreventExitStatus=SIGINT SIGTERM
+
+[Install]
+WantedBy=multi-user.target