Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gcKl2-0001hz-5M for pgsql-hackers@arkaria.postgresql.org; Thu, 27 Dec 2018 01:46:44 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gcKl0-0001df-HY for pgsql-hackers@arkaria.postgresql.org; Thu, 27 Dec 2018 01:46:42 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gcKl0-0001dY-4a for pgsql-hackers@lists.postgresql.org; Thu, 27 Dec 2018 01:46:42 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gcKkx-0004GJ-LW for pgsql-hackers@postgresql.org; Thu, 27 Dec 2018 01:46:40 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id wBR1kPEi032697; Wed, 26 Dec 2018 20:46:25 -0500 From: Tom Lane To: Michael Paquier cc: Alvaro Herrera , Adrien Nayrat , Thomas Munro , Dmitry Dolgov <9erthalion6@gmail.com>, Tomas Vondra , vik.fearing@2ndquadrant.com, Robert Haas , David Rowley , Pg Hackers Subject: Re: random() (was Re: New GUC to sample log queries) In-reply-to: <20181227013458.GF2106@paquier.xyz> References: <20181129214850.kiq6mvofsgplqjdr@alvherre.pgsql> <3859.1545849900@sss.pgh.pa.us> <20181227013458.GF2106@paquier.xyz> Comments: In-reply-to Michael Paquier message dated "Thu, 27 Dec 2018 10:34:58 +0900" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <32695.1545875185.1@sss.pgh.pa.us> Date: Wed, 26 Dec 2018 20:46:25 -0500 Message-ID: <32696.1545875185@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Michael Paquier writes: > On Wed, Dec 26, 2018 at 01:45:00PM -0500, Tom Lane wrote: >> A quick grep says that there's a dozen or so callers, so this patch >> certainly isn't the only offender ... but should we make an effort >> to convert them all to use, say, pg_erand48()? I think all the >> existing callers could happily share a process-wide random state, >> so we could make a wrapper that's no harder to use than random(). > Another possibility would be to extend a bit more the use of > pg_strong_random(), though it is designed to really be used in cases > like authentication where the random bytes are strong for > cryptography. pg_erand48() would be a good step forward. I think pg_strong_random is overkill, and overly expensive, for most if not all of the existing callers of random(). We already changed the ones where it's important to be strong ... One thing I was wondering is if we should try to enforce a policy like this by putting, say, #define random() pg_random() into port.h or so. That would have the advantages of not having to touch any existing calls and not having to worry too much about future patches breaking the policy. On the other hand, it's conceivable that third-party extensions might get annoyed with us for hijacking a libc function. Thoughts? regards, tom lane