From: Paul Jungwirth <pj@illuminatedcomputing.com>
To: pgsql-general@lists.postgresql.org
Subject: Re: Autonomous transaction, background worker
Date: Tue, 27 Mar 2018 08:13:02 -0700
Message-ID: <08a96585-d20d-e7c4-9bfe-7297fe629f3a@illuminatedcomputing.com> (raw)
In-Reply-To: <cdaf268a-0d50-961d-be12-e6d0a99212db@gelassene-pferde.biz>
References: <cdaf268a-0d50-961d-be12-e6d0a99212db@gelassene-pferde.biz>
> I try to setup a logging facility and want it to do its work
> asynchronously in autonomous transactions. I have read
> http://blog.dalibo.com/2016/08/19/Autonoumous_transactions_support_in_PostgreSQL.html
> and chapter 47 of the documentation believing those articles are about
> the same. However, pg_background_launch mentioned in the blog is not
> available on my vanilla installation of Debian 10.3-2 from the
> PostgreSQL repositories.
> CHapter 47 makes me believe I need to code some C functions to use
> background workers.
I've experimented with background workers a bit. Yes, normally you'd
write some C, but you could also install this (mentioned in the blog
post and the source of pg_background_launch):
https://github.com/vibhorkum/pg_background
Note that is not part of contrib and is not on pgxn, so to install it
you need to clone the repo and run `make && sudo make install`. Also I'm
not sure it is really production-level. In particular this is a serious
issue:
https://github.com/vibhorkum/pg_background/issues/1
(If the launching process exits, the child process won't be able to map
the shared memory segment.)
This is another example of background workers that might interest you,
just to see how they're doing it:
https://github.com/citusdata/pg_cron
In that case they start the worker upon database startup, so it doesn't
have problems with shared memory going away.
I took a stab recently at using background workers to run ad hoc async
SQL, but eventually I wound up doing something simpler.
I think background workers is a pretty interesting feature though, so if
you get something working I'm sure others would be happy to hear about
it. Good luck!
Yours,
--
Paul ~{:-)
pj@illuminatedcomputing.com
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: pj@illuminatedcomputing.com
Subject: Re: Autonomous transaction, background worker
In-Reply-To: <08a96585-d20d-e7c4-9bfe-7297fe629f3a@illuminatedcomputing.com>
References: <cdaf268a-0d50-961d-be12-e6d0a99212db@gelassene-pferde.biz> <08a96585-d20d-e7c4-9bfe-7297fe629f3a@illuminatedcomputing.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox