Process startup infrastructure is a mess

From: Andres Freund <andres(at)anarazel(dot)de>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Process startup infrastructure is a mess
Date: 2017-09-14 21:44:22
Message-ID: 20170914214422.eskomvmqfmmlhrtd@alap3.anarazel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

The way we currently start and initialize individual postgres (sub-)
processes is pretty complicated and duplicative. I've a couple
complaints:

1) It's completely non-obvious that bootstrap.c:AuxiliaryProcessMain()
can get invoked both via postmaster for subprocesses (startup, wal
writer, bgwriter, checkpointer, wal receiver, "checker"), as well as
directly via main.c for the bootstrap processes. Note the autovacuum
launcher, archiver, logger are *not* started this way.

2) Most of the processes mentioned in 1) and some additional ones
(autovac launcher and walsender / autovacuum workers to some degree)
duplicate a lot of logic for startup, error handling and main loop.
Especially the error handling code is order dependent, complex, and
has been broken in various subprocesses in the past.

3) There exists yet *another* way of starting processes in the form of
background workers. Initially that was "just" for extensions, but is
now employed for builtin tasks too, like the logical rep launcher /
workers. In the course of that special case handling had to be
sprinkled around, because the bgworker logic isn't quite able to be
good enough for something builtin.

4) The naming of initialization functions is, uh, not particularly
clear. How many people can differentiate, without checking,
BaseInit(), BackendInitialize(), InitPostgres(), InitProcess().

I think the complexity here just grew incrementally with the addition of
more and more subprocesses, without sufficient refactoring. I did some
in 31c453165b5a6, but that's not even remotely enough.

I think we should seriously consider doing a larger refactoring of this
soon. I've some ideas about what to do, but I'd welcome some thoughts
on whether others consider this a serious problem or not, and what they
think we should do about this, first.

Greetings,

Andres Freund

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Paquier 2017-09-14 22:11:25 Re: [JDBC] Channel binding support for SCRAM-SHA-256
Previous Message Robert Haas 2017-09-14 21:19:48 Re: Warnings "unrecognized node type" for some DDLs with log_statement = 'ddl'