bgworkers should share more of BackendRun / PostgresMain

From: Craig Ringer <craig(at)2ndquadrant(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: bgworkers should share more of BackendRun / PostgresMain
Date: 2018-07-12 02:34:22
Message-ID: CAMsr+YEwjEUj78hGGobMZ1FugpTXpjdFyJ_rLJ4=Zk0n=YayJw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi folks

As I work on background workers almost exclusively at the moment, I keep on
running into things that are just not initialized, or not supported, in
bgworkers. Many are quite surprising.

I think bgworkers should just share more of the main Pg startup path.

My latest surprise is that we don't re-initialize the RNG for bgworkers,
because it's done in BackendRun before calling PostgresMain, and bgworker
code path diverges before we call BackendRun.

bgworkers also have to do all their own error handling, duplicating lots of
logic in PostgresMain, if they want to have any error recovery except "die
and restart".

bgworkers don't participate in the ProcSignal mechanism, get query cancels,
etc, unless they do extra setup.

There are all sorts of other small surprises, like the way we don't set up
the dbname in shmem, so logs for bgworkers show it as empty.

There's no patch here because I'm not yet sure what the best approach is.
Some things seem clear, like moving the RNG init work from BackendRun a bit
earlier so all backends hit it. Other parts much less so.

Look at the number of calls to InitProcess() from our profusion of custom
worker types, user backends, the bgworker infrastructure, etc.

I could just copy stuff from BackendRun / PostgresMain to
StartBackgroundWorker() but I'm sure that's not the right approach. I think
we need to decide what should be common and factor it out a bit.

So discussion/ideas appreciated.

--
Craig Ringer http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Paquier 2018-07-12 02:53:08 Re: TRUNCATE tables referenced by FKs on partitioned tables
Previous Message Michael Paquier 2018-07-12 02:16:25 Re: _isnan() on Windows