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 03b28c3604a..98c2c1949d4 100644
--- a/src/backend/utils/init/miscinit.c
+++ b/src/backend/utils/init/miscinit.c
@@ -320,6 +320,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 ae22e7d9fb8..a9bbc8985ea 100644
--- a/src/bin/initdb/initdb.c
+++ b/src/bin/initdb/initdb.c
@@ -922,6 +922,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;