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 1fGRSD-0007hi-Cp for pgsql-hackers@arkaria.postgresql.org; Wed, 09 May 2018 15:56:33 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fGRSB-00061W-ON for pgsql-hackers@arkaria.postgresql.org; Wed, 09 May 2018 15:56:31 +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 1fGRSB-00061M-HT for pgsql-hackers@lists.postgresql.org; Wed, 09 May 2018 15:56:31 +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 1fGRS7-0006sM-IP for pgsql-hackers@postgresql.org; Wed, 09 May 2018 15:56:31 +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 w49FuDNG008874; Wed, 9 May 2018 11:56:13 -0400 From: Tom Lane To: Alvaro Herrera cc: Robert Haas , Dagfinn Ilmari =?iso-8859-1?Q?Manns=E5ker?= , John Naylor , Andres Freund , Andreas Karlsson , "pgsql-hackers@postgresql.org" Subject: Re: [HACKERS] Cutting initdb's runtime (Perl question embedded) In-reply-to: <20180509153924.32kvslqeqdyco7c5@alvherre.pgsql> References: <20180509153924.32kvslqeqdyco7c5@alvherre.pgsql> Comments: In-reply-to Alvaro Herrera message dated "Wed, 09 May 2018 12:39:24 -0300" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <8872.1525881373.1@sss.pgh.pa.us> Date: Wed, 09 May 2018 11:56:13 -0400 Message-ID: <8873.1525881373@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Alvaro Herrera writes: > Tom Lane wrote: >> Robert Haas writes: >>> Who says we need a portable way? If we had something that worked on >>> Linux and macOS, it would cover most developer environments. I wonder >>> if readlink("/etc/localtime", buf, sz) might be a viable approach. >> I wondered about that, but I'm afraid it's often a hardlink not a >> symlink. Still, we could try it. > In Debian systems, it's a symlink. Apparently in RHEL6 and older it's a > copy or hardlink, and the file /etc/sysconfig/clock contains a ZONE > variable that points to the right zone. Yeah, on my RHEL6 box, $ ls -l /etc/localtime -rw-r--r--. 1 root root 3519 May 4 2010 /etc/localtime The mod date's a little astonishing, considering this system was built in 2013. It is *not* a hardlink, or even an exact match, to anything under /usr/share/zoneinfo, though perhaps it was originally. Also: $ cat /etc/sysconfig/clock # The time zone of the system is defined by the contents of /etc/localtime. # This file is only for evaluation by system-config-date, do not rely on its # contents elsewhere. ZONE="America/New York" I'm inclined to respect the comment, especially since I see they are not spelling the zone name canonically anyway (note space not underscore); so looking at this wouldn't work without some ill-defined heuristics. However, more modern Red Hat systems seem to have /etc/localtime as a symlink, so checking it would work there, and also macOS seems to do it that way for as far back as I can check. > This comment is insightful: > https://github.com/HowardHinnant/date/issues/269#issuecomment-353792132 > It's talking about this code: > https://github.com/HowardHinnant/date/blob/master/src/tz.cpp#L3652 Interesting. Not sure if we want to try all those files. But I'll take a look at whipping up something that checks /etc/localtime. regards, tom lane