[Unit]
Description=PostgreSQL database server
After=network.target
AssertPathExists={{postgres_server_root}}/data/postgresql.conf
RequiresMountsFor={{postgres_server_root}}

[Service]
Type=notify
TimeoutSec=120
User=postgres
Group=postgres

Environment=PGROOT={{postgres_server_root}}

SyslogIdentifier=postgres
PIDFile=${PGROOT}/data/postmaster.pid
RuntimeDirectory=postgresql
RuntimeDirectoryMode=755

ExecStart=/usr/lib/postgresql/12/bin/postgres -D ${PGROOT}/data
ExecReload=/bin/kill -HUP ${MAINPID}
KillMode=mixed
KillSignal=SIGINT

# Due to PostgreSQL's use of shared memory, OOM killer is often overzealous in
# killing Postgres, so adjust it downward
OOMScoreAdjust=-200

# Additional security-related features
PrivateTmp=true
ProtectHome=true
ProtectSystem=full
NoNewPrivileges=true
ProtectControlGroups=true
ProtectKernelModules=true
ProtectKernelTunables=true
PrivateDevices=true
RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6
RestrictNamespaces=true
RestrictRealtime=true
SystemCallArchitectures=native

[Install]
WantedBy=multi-user.target
