diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c index 41de140ae01..b50776678f7 100644 --- a/src/backend/postmaster/postmaster.c +++ b/src/backend/postmaster/postmaster.c @@ -602,8 +602,8 @@ PostmasterMain(int argc, char *argv[]) * * Note: the seed is pretty predictable from externally-visible facts such * as postmaster start time, so avoid using random() for security-critical - * random values during postmaster startup. At the time of first - * connection, PostmasterRandom will select a hopefully-more-random seed. + * random values during postmaster startup. InitPostmasterChild() will + * set a new seed in child processes. */ srandom((unsigned int) (MyProcPid ^ MyStartTime)); @@ -4315,22 +4315,16 @@ BackendRun(Port *port) char **av; int maxac; int ac; - long secs; - int usecs; int i; /* * Don't want backend to be able to see the postmaster random number - * generator state. We have to clobber the static random_seed *and* start - * a new random sequence in the random() library function. + * generator state. We have to clobber the static random_seed. */ #ifndef HAVE_STRONG_RANDOM random_seed = 0; random_start_time.tv_usec = 0; #endif - /* slightly hacky way to convert timestamptz into integers */ - TimestampDifference(0, port->SessionStartTime, &secs, &usecs); - srandom((unsigned int) (MyProcPid ^ (usecs << 12) ^ secs)); /* * Now, build the argv vector that will be given to PostgresMain. diff --git a/src/backend/utils/init/miscinit.c b/src/backend/utils/init/miscinit.c index f590ecb25e8..d907226ada4 100644 --- a/src/backend/utils/init/miscinit.c +++ b/src/backend/utils/init/miscinit.c @@ -278,6 +278,9 @@ InitPostmasterChild(void) MyStartTime = time(NULL); /* set our start time in case we call elog */ + /* Set a different seed for libc's random() in every backend. */ + srandom((unsigned int) (MyProcPid ^ MyStartTime)); + /* * make sure stderr is in binary mode before anything can possibly be * written to it, in case it's actually the syslogger pipe, so the pipe