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 1fPtKG-0002Hg-Hg for pgsql-general@arkaria.postgresql.org; Mon, 04 Jun 2018 17:31:24 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fPtKE-0002wt-1J for pgsql-general@arkaria.postgresql.org; Mon, 04 Jun 2018 17:31:22 +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 1fPtKD-0002wj-Oy for pgsql-general@lists.postgresql.org; Mon, 04 Jun 2018 17:31:21 +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 1fPtK6-00048O-E2 for pgsql-general@postgresql.org; Mon, 04 Jun 2018 17:31:21 +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 w54HVCaU031955; Mon, 4 Jun 2018 13:31:12 -0400 From: Tom Lane To: "David G. Johnston" cc: pavan95 , pgsql-general Subject: Re: How to get postmaster shut down time in postgres? In-reply-to: References: <1528118250600-0.post@n3.nabble.com> <1528119860207-0.post@n3.nabble.com> Comments: In-reply-to "David G. Johnston" message dated "Mon, 04 Jun 2018 07:33:35 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <31953.1528133472.1@sss.pgh.pa.us> Content-Transfer-Encoding: 8bit Date: Mon, 04 Jun 2018 13:31:12 -0400 Message-ID: <31954.1528133472@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk "David G. Johnston" writes: > On Mon, Jun 4, 2018 at 6:44 AM, pavan95 wrote: >> The main reason for my requirement is to find the time swing between server >> stop and start. > Not all server stops are logged/evented (i.e., crashes), though by > definition all successful starts are (or at least can be).​ Yeah, the server-crash case is the one that makes this requirement hard to solve internally to the server. In a normal ("smart") shutdown, there might be a case for letting something happen just before we begin the final shutdown sequence, but there's no such hook at present. Anyway, that still leaves a definitional question --- are you looking for the time that shutdown begins, or when it's done? By definition, the latter is too late to make a table entry. One thing you might consider is running pg_controldata just before you start the server, and noting its report of "pg_control last modified". That would either be the shutdown-done point in a non-crash case, or (probably) the last checkpoint time in a crash case. As others mentioned, checking for the time of the last message in the postmaster log would likely provide a more accurate result, but it's also a lot more complicated. regards, tom lane