diff options
| author | Thomas Munro | 2018-10-19 00:59:14 +0000 |
|---|---|---|
| committer | Thomas Munro | 2018-10-19 00:59:28 +0000 |
| commit | 197e4af9d5da180190a0f2be851b095dba57d9cd (patch) | |
| tree | 4121b3b50a5f020f982eb4cbbe754420d200ff31 /src/include | |
| parent | e74dd00f53cd6dc1887f76b9672e5f6dcf0fd8a2 (diff) | |
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
Diffstat (limited to 'src/include')
| -rw-r--r-- | src/include/libpq/libpq-be.h | 7 | ||||
| -rw-r--r-- | src/include/miscadmin.h | 2 | ||||
| -rw-r--r-- | src/include/postmaster/postmaster.h | 1 |
3 files changed, 3 insertions, 7 deletions
diff --git a/src/include/libpq/libpq-be.h b/src/include/libpq/libpq-be.h index eb8bba4ed88..b2c59df54e4 100644 --- a/src/include/libpq/libpq-be.h +++ b/src/include/libpq/libpq-be.h @@ -151,13 +151,6 @@ typedef struct Port HbaLine *hba; /* - * Information that really has no business at all being in struct Port, - * but since it gets used by elog.c in the same way as database_name and - * other members of this struct, we may as well keep it here. - */ - TimestampTz SessionStartTime; /* backend start time */ - - /* * TCP keepalive settings. * * default values are 0 if AF_UNIX or not yet known; current values are 0 diff --git a/src/include/miscadmin.h b/src/include/miscadmin.h index 69f356f8cdb..d6b32c070c2 100644 --- a/src/include/miscadmin.h +++ b/src/include/miscadmin.h @@ -25,6 +25,7 @@ #include <signal.h> +#include "datatype/timestamp.h" /* for TimestampTZ */ #include "pgtime.h" /* for pg_time_t */ @@ -163,6 +164,7 @@ extern PGDLLIMPORT int max_parallel_workers; extern PGDLLIMPORT int MyProcPid; extern PGDLLIMPORT pg_time_t MyStartTime; +extern PGDLLIMPORT TimestampTz MyStartTimestamp; extern PGDLLIMPORT struct Port *MyProcPort; extern PGDLLIMPORT struct Latch *MyLatch; extern int32 MyCancelKey; diff --git a/src/include/postmaster/postmaster.h b/src/include/postmaster/postmaster.h index 1877eef2391..a40d66e8906 100644 --- a/src/include/postmaster/postmaster.h +++ b/src/include/postmaster/postmaster.h @@ -48,6 +48,7 @@ extern PGDLLIMPORT const char *progname; extern void PostmasterMain(int argc, char *argv[]) pg_attribute_noreturn(); extern void ClosePostmasterPorts(bool am_syslogger); +extern void InitProcessGlobals(void); extern int MaxLivePostmasterChildren(void); |
