___ _____ __ __ __
/ _ \/ ___/ ___ ____/ / ___ ___/ /_ __/ /__ ____
/ ___/ (_ / (_-</ __/ _ \/ -_) _ / // / / -_) __/
/_/ \___/ /___/\__/_//_/\__/\_,_/\_,_/_/\__/_/
PG scheduler alias pgsched
is a minimal python daemon providing cron/at/init
functionality at a PostgreSQL server.
pgsched
is developed by Jakub Ružička for LinuxBox.cz under Modified BSD
License (see COPYING).
-
pgsched
daemon connects to PostgreSQL server and looks for all databases containingpgsched
schema. -
pgsched
schema contains (among other thing) 3 tables:pgs_cron
: periodic tasks with cron schedulingpgs_at
: one-time tasks ran at specific timepgs_runner
: continuous tasks
By INSERTing into these tables, tasks are scheduled and later run by pgsched.
server-side requirements:
- PostgreSQL (tested on 9.0 and 9.1, should work on 8.4)
hstore
module frompostgresql-contrib
deamon-side requirements:
python
>= 2.4psycopg2
lbasync
: LinuxBox library also hosted on github
-
Install
hstore
frompostgresql-contrib
into public schema of all databases you wish to usepgsched
in. (tip:/usr/pgsql-9.X/share/contrib/hstore.sql
) -
Create PostgreSQL
pgsched
superuser and installpgsched
schema into all databases you wish to usepgsched
in usingsql/pgsched.sql
(edit to your needs). -
If not using RPM, copy
init-script
to/etc/init.d/pgsched
on daemon side.
LinuxBox: /home/lbox/rpms/lbox-pgsched/
- Obtain source tarball by running
make dist
and copy lbox-pgsched-X.Y.tgz torpmbuild/SOURCES
. - Copy
rpm/lbox-pgsched-X.Y.spec
torpmbuild/SPECS
and edit to your needs. rpmbuild -ba lbox-pgsched-X.Y.spec
pgsched.py
deamon is controlled by init-script
(which should be at
/etc/init.d/pgsched
).
lbasync and pgasync are used, daemon can be controlled by environmental variables:
PGHOST, PGUSER, PGPASSWORD
LOG_FILE
When using pgsched service from RPM, export set these in /etc/sysconfig/pgsched
, i.e.:
export PGHOST=hostname
export PGUSER=pgsched
export PGPASSWORD=secret
INSERT into pgs_{cron,at,runner}
tables to schedule tasks.
Interesting columns are COMMENTed, use \d+ pgs_{cron,at,runner}
in psql to
get some info.
Task event logging is controled by per-task log_level
column. Possible values are:
- 0 - never log
- 1 - log errors [default]
- 2 - log errors & task run/finish
Logs are saved in pgsched.pgs_log
table.
Daemon also logs into file using lbasync
- LOG_FILE
env. variable is used,
defaults to /var/log/lbox/pgsched.log