Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1gASwX-0004QT-L2 for pgsql-hackers@arkaria.postgresql.org; Thu, 11 Oct 2018 04:51:25 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gASwV-0006Cv-Sr for pgsql-hackers@arkaria.postgresql.org; Thu, 11 Oct 2018 04:51:23 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1gASwV-0006Co-Lo for pgsql-hackers@lists.postgresql.org; Thu, 11 Oct 2018 04:51:23 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1gASwP-0001yc-4Z for pgsql-hackers@postgresql.org; Thu, 11 Oct 2018 04:51:23 +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 w9B4pCIj009880; Thu, 11 Oct 2018 00:51:12 -0400 From: Tom Lane To: Thomas Munro cc: Pg Hackers Subject: Re: DSM segment handle generation in background workers In-reply-to: References: <17043.1539046409@sss.pgh.pa.us> Comments: In-reply-to Thomas Munro message dated "Thu, 11 Oct 2018 16:18:40 +1300" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <9878.1539233472.1@sss.pgh.pa.us> Date: Thu, 11 Oct 2018 00:51:12 -0400 Message-ID: <9879.1539233472@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Thomas Munro writes: >> Ok, here is a sketch patch with a new function InitRandomSeeds() to do >> that. It is called from PostmasterMain(), InitPostmasterChild() and >> InitStandaloneProcess() for consistency. > Here's a version I propose to push to master and 11 tomorrow, if there > are no objections. The comment adjacent to the change in InitStandaloneProcess bothers me. In particular, it points out that what BackendRun() is currently doing creates more entropy in the process's random seed than what you have here: MyStartTime is only good to the nearest second, whereas the code you removed from BackendRun() factors in fractional seconds to whatever the precision of GetCurrentTimestamp is. This does not seem like an improvement. I'm inclined to think we should refactor a bit more aggressively so that, rather than dumbing backends down to the standard of other processes, we make them all use the better method. A reasonable way to approach this would be to invent a global variable MyStartTimestamp beside MyStartTime, and initialize both of them in the places that currently initialize the latter, using code like that in BackendInitialize: /* save process start time */ port->SessionStartTime = GetCurrentTimestamp(); MyStartTime = timestamptz_to_time_t(port->SessionStartTime); and then this new InitRandomSeeds function could adopt BackendRun's seed initialization method instead of the stupider way. Possibly it'd be sane to merge the MyStartTime* initializations and the srandom resets into one function, not sure. regards, tom lane