From: Thomas Munro <tmunro@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Refactor pid, random seed and start time initialization.
Date: Fri, 19 Oct 2018 01:01:13 +0000
Message-ID: <E1gDJA9-0000eR-42@gemulon.postgresql.org> (raw)
Refactor pid, random seed and start time initialization.
Background workers, including parallel workers, were generating
the same sequence of numbers in random(). This showed up as DSM
handle collisions when Parallel Hash created multiple segments,
but any code that calls random() in background workers could be
affected if it cares about different backends generating different
numbers.
Repair by making sure that all new processes initialize the seed
at the same time as they set MyProcPid and MyStartTime in a new
function InitProcessGlobals(), called by the postmaster, its
children and also standalone processes. Also add a new high
resolution MyStartTimestamp as a potentially useful by-product,
and remove SessionStartTime from struct Port as it is now
redundant.
No back-patch for now, as the known consequences so far are just
a bunch of harmless shm_open(O_EXCL) collisions.
Author: Thomas Munro
Reviewed-by: Tom Lane
Discussion: https://postgr.es/m/CAEepm%3D2eJj_6%3DB%2B2tEpGu2nf1BjthCf9nXXUouYvJJ4C5WSwhg%40mail.gmail.com
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/197e4af9d5da180190a0f2be851b095dba57d9cd
Modified Files
--------------
src/backend/postmaster/pgstat.c | 10 +------
src/backend/postmaster/postmaster.c | 60 ++++++++++++++++++-------------------
src/backend/tcop/postgres.c | 2 +-
src/backend/utils/init/globals.c | 1 +
src/backend/utils/init/miscinit.c | 16 ++--------
src/include/libpq/libpq-be.h | 7 -----
src/include/miscadmin.h | 2 ++
src/include/postmaster/postmaster.h | 1 +
8 files changed, 37 insertions(+), 62 deletions(-)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-committers@postgresql.org
Cc: tmunro@postgresql.org
Subject: Re: pgsql: Refactor pid, random seed and start time initialization.
In-Reply-To: <E1gDJA9-0000eR-42@gemulon.postgresql.org>
References: <E1gDJA9-0000eR-42@gemulon.postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox