Thread: How many postmasters should be running?

How many postmasters should be running?

From
"Stock, Stuart"
Date:
Hello,

A few minutes ago, we were surprised to find a second postmaster process
running on our database machine as a child of the original postmaster. The
child postmaster was around for about a minute then disappeared. This is a
Opteron machine running RedHat AS4 with Postgres 8.1.2.

Does the postmaster process ever spawn a child postmaster? Is this normal?

Thanks,
Stuart


If you have received this e-mail in error or wish to read our e-mail disclaimer statement and monitoring policy, please
referto http://www.drkw.com/disc/email/ or contact the sender. 


Re: How many postmasters should be running?

From
Michael Fuhr
Date:
On Mon, Feb 27, 2006 at 09:05:51PM -0500, Stock, Stuart wrote:
> A few minutes ago, we were surprised to find a second postmaster process
> running on our database machine as a child of the original postmaster. The
> child postmaster was around for about a minute then disappeared. This is a
> Opteron machine running RedHat AS4 with Postgres 8.1.2.
>
> Does the postmaster process ever spawn a child postmaster? Is this normal?

Each connection causes the postmaster to fork a new process to
handle that connection.  When the connection ends so does that
process; that might be what you saw.  For more information see the
"Monitoring Database Activity" and postmaster documentation:

http://www.postgresql.org/docs/8.1/interactive/monitoring.html
http://www.postgresql.org/docs/8.1/interactive/app-postmaster.html

--
Michael Fuhr

Re: How many postmasters should be running?

From
Tom Lane
Date:
Michael Fuhr <mike@fuhr.org> writes:
> On Mon, Feb 27, 2006 at 09:05:51PM -0500, Stock, Stuart wrote:
>> A few minutes ago, we were surprised to find a second postmaster process
>> running on our database machine as a child of the original postmaster.

> Each connection causes the postmaster to fork a new process to
> handle that connection.

Also, all postmaster child processes will properly identify themselves
as long as you are using the appropriate ps options.  (Depending on your
OS, the default ps output format might just list them all as "postmaster".)
Try something like "ps auxww | grep postgres" if using Linux.

            regards, tom lane

Re: How many postmasters should be running?

From
"Stock, Stuart"
Date:
Here's ps output, as you can see there is a second postmaster (pid 17303)
that is a child of the original postmaster (pid 28317):

prod 28317     1  0 Feb25 ?  00:00:02
/mnt/prod/postgresql-8.1.2/bin/postmaster -i
prod 28321 28317  0 Feb25 ?  00:00:11 postgres: logger process
prod 28323 28317  0 Feb25 ?  00:02:32 postgres: writer process
prod 28324 28317  0 Feb25 ?  00:00:00 postgres: archiver process
prod 28325 28317  0 Feb25 ?  00:00:05 postgres: stats buffer process
prod 28326 28325  0 Feb25 ?  00:00:11 postgres: stats collector process
prod 13571 28317  0 09:19 ?  00:00:00 postgres: pos abdb host.x.y.net(33623)
idle
prod 16214 28317  5 10:05 ?  00:00:46 postgres: pos abdb 10.123.45.79(4232)
idle
prod 16268 28317  0 10:05 ?  00:00:00 postgres: pos abdb 10.123.45.79(4237)
idle
prod 16328 28317  0 10:06 ?  00:00:05 postgres: pos xyzdb 10.123.45.79(4245)
idle
prod 17303 28317  0 10:19 ?  00:00:00
/mnt/prod/postgresql-8.1.2/bin/postmaster -i

Viewing this as a tree (ps aefx) makes it a little more obvious:

28317 ?  S 0:02 /mnt/prod/postgresql-8.1.2/bin/postmaster -i HOSTNAME=host1
TERM=xterm SHE
28321 ?  S 0:11  \_ postgres: logger process
28323 ?  S 2:32  \_ postgres: writer process
28324 ?  S 0:00  \_ postgres: archiver process
28325 ?  S 0:05  \_ postgres: stats buffer process
28326 ?  S 0:11  |   \_ postgres: stats collector process
13571 ?  S 0:00  \_ postgres: pos abdb host.x.y.net(33623) idle
16214 ?  S 0:46  \_ postgres: pos abdb 10.123.45.79(4232) idle
16268 ?  S 0:00  \_ postgres: pos abdb 10.123.45.79(4237) idle
16328 ?  S 0:05  \_ postgres: pos xyzdb 10.123.45.79(4245) idle
17327 ?  S 0:00  \_ /mnt/prod/postgresql-8.1.2/bin/postmaster -i
HOSTNAME=host1 TERM=xterm

Wait a sec...looking at the above I just noticed that the process id of the
second postmaster in the first 'ps' output listing is different from the pid
in the tree listing. At the time this second postmaster appeared, there were
a lot of connections to the database being attempted (and rejected due to
pg_hba.conf configuration).

Perhaps I'm just seeing a moment-in-time snapshot of the postmaster
fork()'ing to handle these connections, but because they were rejected, it
never had time to rename itself to 'postgres'?

Stuart

-----Original Message-----
From: Tom Lane [mailto:tgl@sss.pgh.pa.us]
Sent: Monday, February 27, 2006 10:09 PM
To: Michael Fuhr
Cc: Stock, Stuart; pgsql-general@postgresql.org
Subject: Re: [GENERAL] How many postmasters should be running?

Michael Fuhr <mike@fuhr.org> writes:
> On Mon, Feb 27, 2006 at 09:05:51PM -0500, Stock, Stuart wrote:
>> A few minutes ago, we were surprised to find a second postmaster process
>> running on our database machine as a child of the original postmaster.

> Each connection causes the postmaster to fork a new process to
> handle that connection.

Also, all postmaster child processes will properly identify themselves
as long as you are using the appropriate ps options.  (Depending on your
OS, the default ps output format might just list them all as "postmaster".)
Try something like "ps auxww | grep postgres" if using Linux.

            regards, tom lane


If you have received this e-mail in error or wish to read our e-mail disclaimer statement and monitoring policy, please
referto http://www.drkw.com/disc/email/ or contact the sender. 


Re: How many postmasters should be running?

From
Tom Lane
Date:
"Stock, Stuart" <Stuart.Stock@DrKW.com> writes:
> Perhaps I'm just seeing a moment-in-time snapshot of the postmaster
> fork()'ing to handle these connections, but because they were rejected, it
> never had time to rename itself to 'postgres'?

There's definitely a short window between the fork and the point where
the child process is able to change the way it appears in ps.
[ eyes code... ]  In particular, if you have log_hostname enabled,
it looks like we could wait for a DNS response (to the lookup of the
client IP address) before we change the ps status.

            regards, tom lane