From 197e4af9d5da180190a0f2be851b095dba57d9cd Mon Sep 17 00:00:00 2001 From: Thomas Munro Date: Fri, 19 Oct 2018 13:59:14 +1300 Subject: 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 --- src/backend/tcop/postgres.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/backend/tcop/postgres.c') diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c index e4c6e3d406e..6e13d14fcd0 100644 --- a/src/backend/tcop/postgres.c +++ b/src/backend/tcop/postgres.c @@ -4632,7 +4632,7 @@ log_disconnections(int code, Datum arg) minutes, seconds; - TimestampDifference(port->SessionStartTime, + TimestampDifference(MyStartTimestamp, GetCurrentTimestamp(), &secs, &usecs); msecs = usecs / 1000; -- cgit v1.2.3