diff --git a/src/backend/utils/init/miscinit.c b/src/backend/utils/init/miscinit.c index 865119d272..f590ecb25e 100644 --- a/src/backend/utils/init/miscinit.c +++ b/src/backend/utils/init/miscinit.c @@ -325,6 +325,14 @@ InitStandaloneProcess(const char *argv0) MyStartTime = time(NULL); /* set our start time in case we call elog */ + /* + * Initialize random() for the first time, like PostmasterMain() would. + * In a regular IsUnderPostmaster backend, BackendRun() computes a + * high-entropy seed before any user query. Fewer distinct initial seeds + * can occur here. + */ + srandom((unsigned int) (MyProcPid ^ MyStartTime)); + /* Initialize process-local latch support */ InitializeLatchSupport(); MyLatch = &LocalLatchData; diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c index cb8c7450d9..e155c6ae2f 100644 --- a/src/bin/initdb/initdb.c +++ b/src/bin/initdb/initdb.c @@ -923,6 +923,9 @@ choose_dsm_implementation(void) #ifdef HAVE_SHM_OPEN int ntries = 10; + /* Initialize random(); this function is its only user in this program. */ + srandom((unsigned int) (getpid() ^ time(NULL))); + while (ntries > 0) { uint32 handle;