aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/backend/utils/init/miscinit.c8
-rw-r--r--src/bin/initdb/initdb.c3
2 files changed, 11 insertions, 0 deletions
diff --git a/src/backend/utils/init/miscinit.c b/src/backend/utils/init/miscinit.c
index 865119d2729..f590ecb25e8 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 cb8c7450d9b..e155c6ae2fc 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;