summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/backend/bootstrap/bootstrap.c8
-rw-r--r--src/backend/tcop/postgres.c8
-rw-r--r--src/bin/initdb/initdb.c3
3 files changed, 19 insertions, 0 deletions
diff --git a/src/backend/bootstrap/bootstrap.c b/src/backend/bootstrap/bootstrap.c
index 0e14b9272b5..0943a59d660 100644
--- a/src/backend/bootstrap/bootstrap.c
+++ b/src/backend/bootstrap/bootstrap.c
@@ -197,6 +197,14 @@ AuxiliaryProcessMain(int argc, char *argv[])
MyStartTime = time(NULL);
+ /*
+ * 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));
+
/* Compute paths, if we didn't inherit them from postmaster */
if (my_exec_path[0] == '\0')
{
diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c
index 5903b228905..98180ed52ab 100644
--- a/src/backend/tcop/postgres.c
+++ b/src/backend/tcop/postgres.c
@@ -3611,6 +3611,14 @@ PostgresMain(int argc, char *argv[],
MyProcPid = getpid();
MyStartTime = time(NULL);
+
+ /*
+ * 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));
}
SetProcessingMode(InitProcessing);
diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c
index 6de22ba65e1..fb16897adf0 100644
--- a/src/bin/initdb/initdb.c
+++ b/src/bin/initdb/initdb.c
@@ -1055,6 +1055,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;