Re: How to get postmaster shut down time in postgres? - Mailing list pgsql-general

From Tom Lane
Subject Re: How to get postmaster shut down time in postgres?
Date
Msg-id 31954.1528133472@sss.pgh.pa.us
Whole thread Raw
In response to Re: How to get postmaster shut down time in postgres?  ("David G. Johnston" <david.g.johnston@gmail.com>)
Responses Re: How to get postmaster shut down time in postgres?
Re: How to get postmaster shut down time in postgres?
Re: How to get postmaster shut down time in postgres?
List pgsql-general
"David G. Johnston" <david.g.johnston@gmail.com> writes:
> On Mon, Jun 4, 2018 at 6:44 AM, pavan95 <pavan.postgresdba@gmail.com> 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


pgsql-general by date:

Previous
From: Justin Clift
Date:
Subject: Re: Code of Conduct plan
Next
From: Rich Shepard
Date:
Subject: Re: Microsoft buys GitHub, is this a threat to open-source