Re: Passing current_database to BackgroundWorkerInitializeConnection - Mailing list pgsql-hackers

From Jeremy Finzel
Subject Re: Passing current_database to BackgroundWorkerInitializeConnection
Date
Msg-id CAMa1XUigRtJxc3kELAhmOX9rj=zh9ax9x_esctssjRyMKTAtbA@mail.gmail.com
Whole thread Raw
In response to Re: Passing current_database to BackgroundWorkerInitializeConnection  (Andres Freund <andres@anarazel.de>)
Responses Re: Passing current_database to BackgroundWorkerInitializeConnection
List pgsql-hackers


On Mon, Apr 2, 2018 at 2:27 PM, Andres Freund <andres@anarazel.de> wrote:
Hi,

On 2018-04-02 14:24:53 -0500, Jeremy Finzel wrote:
> Thank you, this makes sense.  However, how can this be done since I can
> only pass one argument to bgw_main?  Is there any way to do this without
> having to store the value in shared memory?

No (I mean you can store it in the filesystem or such as well, but
...). Pretty fundamentally sharing data between concurrently running
processes needs a medium to share the data over. The bgw infrastructure
allocates just enough so you can put an index to it into
shmem. Allocating more would be wasteful and/or not enough for some
users.

Greetings,

Andres Freund

Hmmm... not sure if I follow.  My goal is to run a SQL statement every 10 seconds (or what value is chosen) in a particular database, using a background worker.  Those are the two arguments.  Am I missing some way to implement this apart from passing those 2 arguments into the launcher function?  Is the way to do this properly then to allocate shared memory for it, as opposed to trying to pass args into the main function?

Thanks,
Jeremy

pgsql-hackers by date:

Previous
From: Andres Freund
Date:
Subject: Re: PostgreSQL's handling of fsync() errors is unsafe and risks data loss at least on XFS
Next
From: Andres Freund
Date:
Subject: Re: Passing current_database to BackgroundWorkerInitializeConnection