Оригинал инструкции размещен на сайте https://gist.github.com/peterneave/83cefce2a081add244ad7dc1c53bc0c3
- Устанавливаем приложение
sudo apt update sudo apt install pgagent
- Далее создаем файл .pgpass в рабочей директории postgresql (/var/lib/postgresql)
sudo su - postgres echo localhost:5432:*:pgagent:securepassword >> ~/.pgpass chmod 600 ~/.pgpass chown postgres:postgres /var/lib/postgresql/.pgpass
- Настраиваем журналирование:
mkdir /var/log/pgagent chown -R postgres:postgres /var/log/pgagent chmod g+w /var/log/pgagent
- Создаем в PostgreSQL пользователя pgagent
//use Postgres database //This creates the pgagent schema. Dropping this extension will remove this schema and any jobs you have created. CREATE EXTENSION pgagent; CREATE USER "pgagent" WITH LOGIN NOSUPERUSER INHERIT NOCREATEDB NOCREATEROLE NOREPLICATION encrypted password 'securepassword'; GRANT USAGE ON SCHEMA pgagent TO pgagent; GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA pgagent TO pgagent; GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA pgagent TO pgagent;
- Создаем загрузчик, а для того создаем файл /etc/pgagent.conf
#/etc/pgagent.conf DBNAME=postgres DBUSER=pgagent DBHOST=localhost DBPORT=5432 # ERROR=0, WARNING=1, DEBUG=2 LOGLEVEL=1 LOGFILE="/var/log/pgagent/pgagent.log"
И создаем сервис /usr/lib/systemd/system/pgagent.service
[Unit]
Description=PgAgent for PostgreSQL
After=syslog.target
After=network.target
[Service]
Type=forking
User=postgres
Group=postgres
# Location of the configuration file
EnvironmentFile=/etc/pgagent.conf
# Where to send early-startup messages from the server (before the logging
# options of pgagent.conf take effect)
# This is normally controlled by the global default set by systemd
# StandardOutput=syslog
# Disable OOM kill on the postmaster
OOMScoreAdjust=-1000
ExecStart=/usr/bin/pgagent -s ${LOGFILE} -l ${LOGLEVEL} host=${DBHOST} dbname=${DBNAME} user=${DBUSER} port=${DBPORT}
KillMode=mixed
KillSignal=SIGINT
Restart=on-failure
# Give a reasonable amount of time for the server to start up/shut down
TimeoutSec=300
[Install]
WantedBy=multi-user.target
sudo -i systemctl daemon-reload systemctl disable pgagent systemctl enable pgagent systemctl start pgagent
Настраиваем логирование и создаем файл /etc/logrotate.d/pgagent:
#/etc/logrotate.d/pgagent
/var/log/pgagent/*.log {
weekly
rotate 10
copytruncate
delaycompress
compress
notifempty
missingok
su root root
}
В pgAdmin4 не отображается пункт pgAgent Jobs
Суть проблемы в следующем. Нужно чтобы в базе данных, которая указана в /etc/pgagent.conf -> DBNAME создать Extension pgagent:
CREATE EXTENSION pgagent;
Далее в pgAdmin 4 нужно создать подключение, где Maintenance database равен DBNAME.