Re: [v9.3] Extra Daemons (Re: elegant and effective way for running jobs inside a database)

Alvaro Herrera <alvherre@2ndquadrant.com>

From: Alvaro Herrera <alvherre@2ndquadrant.com>
To: Kohei KaiGai <kaigai@kaigai.gr.jp>
Cc: Boszormenyi Zoltan <zb@cybertec.at>, Simon Riggs <simon@2ndquadrant.com>, Jaime Casanova <jaime@2ndquadrant.com>, Andrew Dunstan <andrew@dunslane.net>, Robert Haas <robertmhaas@gmail.com>, David E. Wheeler <david@justatheory.com>, Pg Hackers <pgsql-hackers@postgresql.org>, Hans-Jürgen Schönig <hs@cybertec.at>
Date: 2012-09-11T16:35:17Z
Lists: pgsql-hackers
Excerpts from Kohei KaiGai's message of mar sep 11 13:25:18 -0300 2012:
> 2012/9/11 Alvaro Herrera <alvherre@2ndquadrant.com>:

> >> > - an SQL-driven scheduler, similar to pgAgent, it's generic enough,
> >> >   we might port it to this scheme and publish it
> >
> > Hm, this would benefit from a direct backend connection to get the
> > schedule data (SPI interface I guess).
> >
> I also think SPI interface will be first candidate for the daemons that
> needs database access. Probably, lower layer interfaces (such as
> heap_open and heap_beginscan) are also available if SPI interface
> can be used.

Well, as soon as you have a database connection on which you can run
SPI, you need a lot of stuff to ensure your transaction is aborted in
case of trouble and so on.  At that point you can do direct access as
well.

I think it would be a good design to provide different cleanup routes
for the different use cases: for those that need database connections we
nede to go through AbortOutOfAnyTransaction() or something similar; for
others we can probably get away with much less than that.  Not 100% sure
at this point.

-- 
Álvaro Herrera                http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services