How to determine date / time of last postmaster restart

Started by adeyover 20 years ago8 messages
#1adey
adey11@gmail.com

Please let me know if there is a way to determine when the Postmaster was
last restarted?
This is for tuning. I have stats_reset_on_server_start turned on, but I
don't know when last the Postmaster was started, so I can't determine the
period my current system stats cover.

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: adey (#1)
Re: How to determine date / time of last postmaster restart

adey <adey11@gmail.com> writes:

Please let me know if there is a way to determine when the Postmaster was
last restarted?

The last postmaster start time, or the last database reset? These are
not the same if any backends have crashed since the postmaster started.
For determining stats lifespan I think you need the latter.

Offhand I think the file timestamp of $PGDATA/postmaster.opts would do
for the postmaster start time, and postmaster.pid for the other (I think
postmaster.pid is updated during a reset).

PG 8.1 will have a function to return postmaster start time, but not
database reset time. I wonder if this is misdefined --- if you are
trying to measure database uptime, the last reset would be more
appropriate to track.

regards, tom lane

#3Jim C. Nasby
jnasby@pervasive.com
In reply to: Tom Lane (#2)
Re: [HACKERS] How to determine date / time of last postmaster restart

On Tue, Sep 06, 2005 at 08:22:34PM -0400, Tom Lane wrote:

PG 8.1 will have a function to return postmaster start time, but not
database reset time. I wonder if this is misdefined --- if you are
trying to measure database uptime, the last reset would be more
appropriate to track.

Is it too late to add a function that returns last reset time as well?
That would cover all bases and force some less confusing naming.
--
Jim C. Nasby, Sr. Engineering Consultant jnasby@pervasive.com
Pervasive Software http://pervasive.com work: 512-231-6117
vcard: http://jim.nasby.net/pervasive.vcf cell: 512-569-9461

#4Peter Eisentraut
peter_e@gmx.net
In reply to: adey (#1)
Re: How to determine date / time of last postmaster restart

adey wrote:

Please let me know if there is a way to determine when the Postmaster
was last restarted?

If you have configured your server log to contain timestamps, that is
your best bet to look. In any case, the server log will tell when the
last shutdown was, so you can at least narrow down the time frame. You
can also use pg_controldata to check the time of last change to
pg_control (which is changed when the server starts).

--
Peter Eisentraut
http://developer.postgresql.org/~petere/

#5Alvaro Herrera
alvherre@alvh.no-ip.org
In reply to: Jim C. Nasby (#3)
Re: [HACKERS] How to determine date / time of last postmaster restart

On Wed, Sep 07, 2005 at 12:38:44AM -0500, Jim C. Nasby wrote:

On Tue, Sep 06, 2005 at 08:22:34PM -0400, Tom Lane wrote:

PG 8.1 will have a function to return postmaster start time, but not
database reset time. I wonder if this is misdefined --- if you are
trying to measure database uptime, the last reset would be more
appropriate to track.

Is it too late to add a function that returns last reset time as well?
That would cover all bases and force some less confusing naming.

This would be one more vote in favour of initdb before next beta.
(pltemplate being the other one.) We should set a threshold in order to
be able to decide ...

--
Alvaro Herrera -- Valdivia, Chile Architect, www.EnterpriseDB.com
"Use it up, wear it out, make it do, or do without"

#6Tom Lane
tgl@sss.pgh.pa.us
In reply to: Alvaro Herrera (#5)
Re: [HACKERS] How to determine date / time of last postmaster restart

Alvaro Herrera <alvherre@alvh.no-ip.org> writes:

On Wed, Sep 07, 2005 at 12:38:44AM -0500, Jim C. Nasby wrote:

Is it too late to add a function that returns last reset time as well?
That would cover all bases and force some less confusing naming.

This would be one more vote in favour of initdb before next beta.
(pltemplate being the other one.) We should set a threshold in order to
be able to decide ...

It looks like we'll be initdb'ing to add pltemplate, so if someone wants
to submit a proposed patch for this ...

regards, tom lane

#7Jim C. Nasby
jnasby@pervasive.com
In reply to: Tom Lane (#6)
Re: [HACKERS] How to determine date / time of last postmaster restart

On Wed, Sep 07, 2005 at 09:22:55PM -0400, Tom Lane wrote:

Alvaro Herrera <alvherre@alvh.no-ip.org> writes:

On Wed, Sep 07, 2005 at 12:38:44AM -0500, Jim C. Nasby wrote:

Is it too late to add a function that returns last reset time as well?
That would cover all bases and force some less confusing naming.

This would be one more vote in favour of initdb before next beta.
(pltemplate being the other one.) We should set a threshold in order to
be able to decide ...

It looks like we'll be initdb'ing to add pltemplate, so if someone wants
to submit a proposed patch for this ...

I might be able to do some of it; where would I need to capture reload
time?

Also, I'm thinking of leaving pg_postmaster_start_time as-is and adding
pg_postmaster_reload_time. Thoughts?

For reference, here's the original commit:
http://archives.postgresql.org/pgsql-committers/2005-06/msg00181.php
--
Jim C. Nasby, Sr. Engineering Consultant jnasby@pervasive.com
Pervasive Software http://pervasive.com work: 512-231-6117
vcard: http://jim.nasby.net/pervasive.vcf cell: 512-569-9461

#8Bruce Momjian
pgman@candle.pha.pa.us
In reply to: Alvaro Herrera (#5)
Re: [HACKERS] How to determine date / time of last postmaster

Alvaro Herrera wrote:

On Wed, Sep 07, 2005 at 12:38:44AM -0500, Jim C. Nasby wrote:

On Tue, Sep 06, 2005 at 08:22:34PM -0400, Tom Lane wrote:

PG 8.1 will have a function to return postmaster start time, but not
database reset time. I wonder if this is misdefined --- if you are
trying to measure database uptime, the last reset would be more
appropriate to track.

Is it too late to add a function that returns last reset time as well?
That would cover all bases and force some less confusing naming.

This would be one more vote in favour of initdb before next beta.
(pltemplate being the other one.) We should set a threshold in order to
be able to decide ...

Added to TODO:

* Add function to report the time of the most recent server
reload

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073