I've done a quick write up for reload time reporting from the administration TODO. I was a little paranoid with the locking, but didn't want problems to occur with signals on the postmaster and the read side.
-George
*** ./doc/src/sgml/func.sgml.orig 2008-04-29 23:47:39.378726574 -0400 --- ./doc/src/sgml/func.sgml 2008-04-29 23:51:12.346237119 -0400 *************** *** 10892,10897 **** --- 10892,10903 ---- </row> <row> + <entry><literal><function>pg_postmaster_reload_time</function>()</literal></entry> + <entry><type>timestamp with time zone</type></entry> + <entry>server last reload time</entry> + </row> + + <row> <entry><literal><function>session_user</function></literal></entry> <entry><type>name</type></entry> <entry>session user name</entry> *************** *** 11037,11042 **** --- 11043,11062 ---- </para> <indexterm> + <primary>pg_postmaster_reload_time</primary> + </indexterm> + + <para> + <function>pg_postmaster_reload_time</function> returns the + <type>timestamp with time zone</type> when the + server was last reloaded. + </para> + + <indexterm> + <primary>version</primary> + </indexterm> + + <indexterm> <primary>version</primary> </indexterm> *** ./src/backend/postmaster/postmaster.c.orig 2008-04-29 23:48:07.374455697 -0400 --- ./src/backend/postmaster/postmaster.c 2008-04-29 23:51:12.346237119 -0400 *************** *** 112,117 **** --- 112,118 ---- #include "storage/pg_shmem.h" #include "storage/pmsignal.h" #include "storage/proc.h" + #include "storage/spin.h" #include "tcop/tcopprot.h" #include "utils/builtins.h" #include "utils/datetime.h" *************** *** 390,395 **** --- 391,398 ---- InheritableSocket pgStatSock; pid_t PostmasterPid; TimestampTz PgStartTime; + TimestampTz PgReloadTime; + slock_t PgReloadTimeLock; bool redirection_done; #ifdef WIN32 HANDLE PostmasterHandle; *************** *** 1008,1013 **** --- 1011,1018 ---- * Remember postmaster startup time */ PgStartTime = GetCurrentTimestamp(); + PgReloadTime = PgStartTime; + SpinLockInit(&PgReloadTimeLock); /* PostmasterRandom wants its own copy */ gettimeofday(&random_start_time, NULL); *************** *** 1931,1936 **** --- 1936,1948 ---- /* Update the starting-point file for future children */ write_nondefault_variables(PGC_SIGHUP); #endif + + /* + * Remember postmaster reload time + */ + SpinLockAcquire(&PgReloadTimeLock); + PgReloadTime = GetCurrentTimestamp(); + SpinLockRelease(&PgReloadTimeLock); } PG_SETMASK(&UnBlockSig); *************** *** 4263,4268 **** --- 4275,4282 ---- param->PostmasterPid = PostmasterPid; param->PgStartTime = PgStartTime; + param->PgReloadTime = PgReloadTime; + param->PgReloadTimeLock = PgReloadTimeLock; param->redirection_done = redirection_done; *** ./src/backend/tcop/postgres.c.orig 2008-04-29 23:48:58.866600196 -0400 --- ./src/backend/tcop/postgres.c 2008-04-29 23:51:12.346237119 -0400 *************** *** 58,63 **** --- 58,64 ---- #include "storage/ipc.h" #include "storage/proc.h" #include "storage/sinval.h" + #include "storage/spin.h" #include "tcop/fastpath.h" #include "tcop/pquery.h" #include "tcop/tcopprot.h" *************** *** 3373,3380 **** /* * Remember stand-alone backend startup time */ ! if (!IsUnderPostmaster) PgStartTime = GetCurrentTimestamp(); /* * POSTGRES main processing loop begins here --- 3374,3384 ---- /* * Remember stand-alone backend startup time */ ! if (!IsUnderPostmaster) { PgStartTime = GetCurrentTimestamp(); + PgReloadTime = PgStartTime; + SpinLockInit(&PgReloadTimeLock); + } /* * POSTGRES main processing loop begins here *************** *** 3550,3555 **** --- 3554,3566 ---- { got_SIGHUP = false; ProcessConfigFile(PGC_SIGHUP); + + /* + * Remember postmaster reload time + */ + SpinLockAcquire(&PgReloadTimeLock); + PgReloadTime = GetCurrentTimestamp(); + SpinLockRelease(&PgReloadTimeLock); } /* *** ./src/backend/utils/adt/timestamp.c.orig 2008-04-29 23:49:46.359354923 -0400 --- ./src/backend/utils/adt/timestamp.c 2008-04-29 23:51:12.346237119 -0400 *************** *** 27,32 **** --- 27,33 ---- #include "libpq/pqformat.h" #include "miscadmin.h" #include "parser/scansup.h" + #include "storage/spin.h" #include "utils/array.h" #include "utils/builtins.h" #include "utils/datetime.h" *************** *** 42,47 **** --- 43,50 ---- /* Set at postmaster start */ TimestampTz PgStartTime; + TimestampTz PgReloadTime; + slock_t PgReloadTimeLock; static TimeOffset time2t(const int hour, const int min, const int sec, const fsec_t fsec); *************** *** 1162,1167 **** --- 1165,1180 ---- PG_RETURN_TIMESTAMPTZ(PgStartTime); } + Datum + pgsql_postmaster_reload_time(PG_FUNCTION_ARGS) + { + TimestampTz timestamp; + SpinLockAcquire(&PgReloadTimeLock); + timestamp = PgReloadTime; + SpinLockRelease(&PgReloadTimeLock); + PG_RETURN_TIMESTAMPTZ(timestamp); + } + /* * GetCurrentTimestamp -- get the current operating system time * *** ./src/include/catalog/pg_proc.h.orig 2008-04-29 23:50:10.355694154 -0400 --- ./src/include/catalog/pg_proc.h 2008-04-29 23:51:12.346237119 -0400 *************** *** 3924,3929 **** --- 3924,3932 ---- /* start time function */ DATA(insert OID = 2560 ( pg_postmaster_start_time PGNSP PGUID 12 1 0 f f t f s 0 1184 "" _null_ _null_ _null_ pgsql_postmaster_start_time - _null_ _null_ )); DESCR("postmaster start time"); + /* reload time function */ + DATA(insert OID = 3775 ( pg_postmaster_reload_time PGNSP PGUID 12 1 0 f f t f s 0 1184 "" _null_ _null_ _null_ pgsql_postmaster_reload_time - _null_ _null_ )); + DESCR("postmaster reload time"); /* new functions for Y-direction rtree opclasses */ DATA(insert OID = 2562 ( box_below PGNSP PGUID 12 1 0 f f t f i 2 16 "603 603" _null_ _null_ _null_ box_below - _null_ _null_ )); *** ./src/include/utils/timestamp.h.orig 2008-04-29 23:50:58.348372498 -0400 --- ./src/include/utils/timestamp.h 2008-04-29 23:51:12.346237119 -0400 *************** *** 22,27 **** --- 22,28 ---- #ifdef HAVE_INT64_TIMESTAMP #include "utils/int8.h" #endif + #include "storage/s_lock.h" /* * Timestamp represents absolute time. *************** *** 195,200 **** --- 196,205 ---- /* Set at postmaster start */ extern TimestampTz PgStartTime; + /* Set at postmaster reload */ + extern TimestampTz PgReloadTime; + /* Ensure safe concurrent acess to reload time */ + extern slock_t PgReloadTimeLock; /* *************** *** 304,309 **** --- 309,315 ---- extern Datum clock_timestamp(PG_FUNCTION_ARGS); extern Datum pgsql_postmaster_start_time(PG_FUNCTION_ARGS); + extern Datum pgsql_postmaster_reload_time(PG_FUNCTION_ARGS); /* Internal routines (not fmgr-callable) */
-- Sent via pgsql-patches mailing list (pgsql-patches@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-patches