diff --git a/src/backend/bootstrap/bootstrap.c b/src/backend/bootstrap/bootstrap.c index 5c0fe9b715b..cded57e045a 100644 --- a/src/backend/bootstrap/bootstrap.c +++ b/src/backend/bootstrap/bootstrap.c @@ -202,6 +202,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 cf4d4ec356b..47651c4ceac 100644 --- a/src/backend/tcop/postgres.c +++ b/src/backend/tcop/postgres.c @@ -3620,6 +3620,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);