Re: Support getrandom() for pg_strong_random() source - Mailing list pgsql-hackers

From Michael Paquier
Subject Re: Support getrandom() for pg_strong_random() source
Date
Msg-id aH86FEl-AWFPv87s@paquier.xyz
Whole thread Raw
In response to Support getrandom() for pg_strong_random() source  (Masahiko Sawada <sawada.mshk@gmail.com>)
Responses Re: Support getrandom() for pg_strong_random() source
List pgsql-hackers
On Mon, Jul 21, 2025 at 11:43:35PM -0700, Masahiko Sawada wrote:
> The patch supports the getrandom() function as a new source of
> pg_strong_random(). The getrandom() function uses the same source as
> the /dev/urandom device but it seems much faster than opening,
> reading, and closing /dev/urandom. Here is the execution time of
> generating 1 million UUIDv4 data measured on my environment:
>
> HEAD(/dev/urandom): 1863.064 ms
> Patched(getrandom()): 516.627 ms

Interesting.  Are there platforms where this is not available?  I'd be
pretty sure that some animals in the buildfarm would not like this
suggestion but I'm saying it anyway.  Perhaps we could even drop
/dev/urandom?

> I guess that while OpenSSL's RAND_bytes() should still be prioritized
> where available it might be a good idea to support getrandom() for
> builds where RAND_bytes() is not available.
>
> Feedback is very welcome.

I am wondering how much non-OpenSSL builds matter these days, TBH, so
I am not sure that this is worth the addition of an extra
configure/meson check and this stuff has its cost just for such
builds.  I am not saying that we should make OpenSSL mandatory, of
course not, but all production instances of Postgres have likely
OpenSSL enabled anyway.  Perhaps some embedded deployments like
--without-openssl, who knows..
--
Michael

Attachment

pgsql-hackers by date:

Previous
From: Michael Paquier
Date:
Subject: Re: Missing NULL check after calling ecpg_strdup
Next
From: Álvaro Herrera
Date:
Subject: Re: Log prefix missing for subscriber log messages received from publisher