"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