Initialize random() in bootstrap/stand-alone postgres and in initdb.
authorNoah Misch <[email protected]>
Mon, 24 Sep 2018 05:56:39 +0000 (22:56 -0700)
committerNoah Misch <[email protected]>
Mon, 24 Sep 2018 05:57:43 +0000 (22:57 -0700)
commit402da7054f34d2c5e3215ca72fc3d08ca2c98090
treeaa19f252f153539783eacd45dd340b360ddc82b5
parent00011a6ae9c71b7f62e98bb285ab6c2f4f6f93b5
Initialize random() in bootstrap/stand-alone postgres and in initdb.

This removes a difference between the standard IsUnderPostmaster
execution environment and that of --boot and --single.  In a stand-alone
backend, "SELECT random()" always started at the same seed.

On a system capable of using posix shared memory, initdb could still
conclude "selecting dynamic shared memory implementation ... sysv".
Crashed --boot or --single postgres processes orphaned shared memory
objects having names that collided with the not-actually-random names
that initdb probed.  The sysv fallback appeared after ten crashes of
--boot or --single postgres.  Since --boot and --single are rare in
production use, systems used for PostgreSQL development are the
principal candidate to notice this symptom.

Back-patch to 9.3 (all supported versions).  PostgreSQL 9.4 introduced
dynamic shared memory, but 9.3 does share the "SELECT random()" problem.

Reviewed by Tom Lane and Kyotaro HORIGUCHI.

Discussion: https://postgr.es/m/20180915221546[email protected]
src/backend/bootstrap/bootstrap.c
src/backend/tcop/postgres.c