Re: How to kill a Background worker and Its metadata

From: Akash Agrawal <aagrawa6(at)ncsu(dot)edu>
To: Craig Ringer <craig(at)2ndquadrant(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: How to kill a Background worker and Its metadata
Date: 2016-06-28 00:54:35
Message-ID: CALF3U-4Z=3LtHnoBWHRXKxpsmA2WcOrm9WGY=LmXE4VAkzO2QQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

I am calling proc_exit(1) once the worker encounters SIGTERM signal. I've
attached my code here.

Here is the link to stackoverflow:
http://stackoverflow.com/questions/38058628/how-to-kill-a-background-worker-including-its-metadata-in-postgres

On Mon, Jun 27, 2016 at 8:41 PM, Craig Ringer <craig(at)2ndquadrant(dot)com> wrote:

> On 28 June 2016 at 02:27, Akash Agrawal <aagrawa6(at)ncsu(dot)edu> wrote:
>
>> Hi,
>>
>> I've created a background worker and I am using Postgresql-9.4. This
>> bgworker handles the job queue dynamically and goes to sleep if there is no
>> job to process within the next 1 hour.
>>
>> Now, I want to have a mechanism to wake the bgworker up in case if
>> someone adds a new job while the bgworker is in sleep mode. So to do it, I
>> have created a trigger which initially removes the existing background
>> worker and then registers a new one.
>>
>
> Don't do that.
>
> Instead, set the background worker's process latch, which you can find in
> the PGPROC array. There are a variety of examples of how to set latches in
> the sources.
>
>>
>> I am retrieving the pid from pg_Stat_activity. The maximum number of
>> background worker that can run simultaneously is equal to 8. I think even
>> if I call pg_terminate_backend the metadata of the background worker is not
>> being deleted
>>
>
> Correct. Unless you register it as a dynamic bgworker with no automatic
> restart, it'll get restarted when it exits uncleanly.
>
> Have the worker call proc_exit(0) if you want it not to be restarted.
>
>
> --
> Craig Ringer http://www.2ndQuadrant.com/
> PostgreSQL Development, 24x7 Support, Training & Services
>

Attachment Content-Type Size
bgworker.rtf application/rtf 4.6 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Paquier 2016-06-28 01:27:06 Re: OpenSSL 1.1 breaks configure and more
Previous Message Craig Ringer 2016-06-28 00:41:58 Re: How to kill a Background worker and Its metadata