Dynamic background workers & docs question

Started by Magnus Haganderalmost 12 years ago4 messages
#1Magnus Hagander
magnus@hagander.net

I was looking at
http://www.postgresql.org/docs/devel/static/bgworker.htmlwith a client
today.

It says:
"Unlike RegisterBackgroundWorker, which can only be called from within the
postmaster,RegisterDynamicBackgroundWorker must be called from a regular
backend."

Is that the correct restriction? In particular, don't we allow calling
RegisterDynamicBackgroundWorker from another background worker? (In the
launcher/worker kind of scenario, like AutoVacuum).

Also:
"Background workers are expected to be continuously running; if they exit
cleanly, postgres will restart them immediately. "

This doesn't apply to dynamic ones, which we might want to clarify. Do we
have a "term" for non-dynamic background workers? "static workers"?

--
Magnus Hagander
Me: http://www.hagander.net/
Work: http://www.redpill-linpro.com/

#2Michael Paquier
michael.paquier@gmail.com
In reply to: Magnus Hagander (#1)
Re: Dynamic background workers & docs question

On Mon, Mar 24, 2014 at 5:54 PM, Magnus Hagander <magnus@hagander.net> wrote:

I was looking at http://www.postgresql.org/docs/devel/static/bgworker.html
with a client today.

It says:
"Unlike RegisterBackgroundWorker, which can only be called from within the
postmaster,RegisterDynamicBackgroundWorker must be called from a regular
backend."

Is that the correct restriction? In particular, don't we allow calling
RegisterDynamicBackgroundWorker from another background worker? (In the
launcher/worker kind of scenario, like AutoVacuum).

Yes, you can start a dynamic background worker from another background
worker, have a look for example at contrib/worker_spi. Perhaps the
correct wording would be "RegisterDynamicBackgroundWorker must be
called from a regular backend or another background worker".

Also:
"Background workers are expected to be continuously running; if they exit
cleanly, postgres will restart them immediately. "

This doesn't apply to dynamic ones, which we might want to clarify. Do we
have a "term" for non-dynamic background workers? "static workers"?

In the code or the documentation, there is no explicit
differentiation, bgworkers are either called plainly "bgworker", or
"dynamic bgworker". Perhaps the solution here is simply to say
"background workers started by the postmaster are expected blabla".
--
Michael

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#3Magnus Hagander
magnus@hagander.net
In reply to: Michael Paquier (#2)
Re: Dynamic background workers & docs question

On Mon, Mar 24, 2014 at 12:20 PM, Michael Paquier <michael.paquier@gmail.com

wrote:

On Mon, Mar 24, 2014 at 5:54 PM, Magnus Hagander <magnus@hagander.net>
wrote:

I was looking at

http://www.postgresql.org/docs/devel/static/bgworker.html

with a client today.

It says:
"Unlike RegisterBackgroundWorker, which can only be called from within

the

postmaster,RegisterDynamicBackgroundWorker must be called from a regular
backend."

Is that the correct restriction? In particular, don't we allow calling
RegisterDynamicBackgroundWorker from another background worker? (In the
launcher/worker kind of scenario, like AutoVacuum).

Yes, you can start a dynamic background worker from another background
worker, have a look for example at contrib/worker_spi. Perhaps the
correct wording would be "RegisterDynamicBackgroundWorker must be
called from a regular backend or another background worker".

That's what I thought. Can a dynamic background worker start *another*
dynamic background worker, or can they only be started from "first level"
background workers?

Also:
"Background workers are expected to be continuously running; if they exit
cleanly, postgres will restart them immediately. "

This doesn't apply to dynamic ones, which we might want to clarify. Do we
have a "term" for non-dynamic background workers? "static workers"?

In the code or the documentation, there is no explicit
differentiation, bgworkers are either called plainly "bgworker", or
"dynamic bgworker". Perhaps the solution here is simply to say
"background workers started by the postmaster are expected blabla".

That, or we need to invite a term for it?

--
Magnus Hagander
Me: http://www.hagander.net/
Work: http://www.redpill-linpro.com/

#4Michael Paquier
michael.paquier@gmail.com
In reply to: Magnus Hagander (#3)
Re: Dynamic background workers & docs question

On Mon, Mar 24, 2014 at 11:03 PM, Magnus Hagander <magnus@hagander.net> wrote:

That's what I thought. Can a dynamic background worker start *another*
dynamic background worker, or can they only be started from "first level"
background workers?

I have never really tried by myself, but I don't see any reason why it
wouldn't work as it is only a matter of doing what is for example in
worker_spi_launch:worker_spi.c. Btw, a bgworker could also behave like
a "regular backend" as mentioned in the docs, so a regular backend is
just a subclass of a bgworker :)

Also:
"Background workers are expected to be continuously running; if they
exit
cleanly, postgres will restart them immediately. "

This doesn't apply to dynamic ones, which we might want to clarify. Do
we
have a "term" for non-dynamic background workers? "static workers"?

In the code or the documentation, there is no explicit
differentiation, bgworkers are either called plainly "bgworker", or
"dynamic bgworker". Perhaps the solution here is simply to say
"background workers started by the postmaster are expected blabla".

That, or we need to invite a term for it?

Hm... Seems like an overkill. The main difference between a
non-dynamic and dynamic bgworker is the way they are registered.
"Static" bgworkers use RegisterBackgroundWorker that can only be
called in _PG_init when a module is loaded with
shared_preload_libraries. Dynamic bgworkers use
RegisterDynamicbackgroundWorker. And this differentiation is clearly
done in the 2nd paragraph.

So perhaps the solution here is simply to write "Background workers
registered with RegisterBackgroundWorker are expected...".

I am not a native English speaker, but "static" sounds like a daemon
process that has to restart, and a bgworker could perform a one-time
task as well.
--
Michael

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers