On Wed, Apr 30, 2008 at 8:16 AM, Alvaro Herrera <[EMAIL PROTECTED]> wrote: > George Gensure escribió: > > > > 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. > > I'd say too much -- postmaster runs with signals blocked all the time > (except during select()) so this is not necessary there. > > Regarding the locking on backends, I admit I am not sure if this is > really a problem enough that you need a spinlock for it. Anyway we tend > not to use spinlocks too much -- probably an LWLock would be more > apropos, if a lock is really needed. (A bigger question is whether the > reload time should be local for each backend, or exposed globally > through MyProc. I don't think it's interesting enough to warrant that, > but perhaps others think differently.) > > Lastly, I didn't read the patch close enough to tell if it would work on > both the EXEC_BACKEND case and the regular one. > > -- > Alvaro Herrera http://www.CommandPrompt.com/ > The PostgreSQL Company - Command Prompt, Inc. >
I've reworked the patch in response to comments. The new function name is pg_conf_load_time() I'm now using LWLocks only on the backend in order to protect the PgReloadTime from mid copy reads. This may prove to be unnecessary, since the code to handle HUPs seems to be executed synchronously on the backend, but I'll let someone else tell me its safe before removing it. -George
*** ./doc/src/sgml/func.sgml.orig 2008-04-29 23:47:39.378726574 -0400 --- ./doc/src/sgml/func.sgml 2008-04-30 11:31:38.434893712 -0400 *************** *** 10892,10897 **** --- 10892,10903 ---- </row> <row> + <entry><literal><function>pg_conf_load_time</function>()</literal></entry> + <entry><type>timestamp with time zone</type></entry> + <entry>config load 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_conf_load_time</primary> + </indexterm> + + <para> + <function>pg_conf_load_time</function> returns the + <type>timestamp with time zone</type> when the + config was last loaded for this session. + </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-30 12:02:05.156215936 -0400 *************** *** 390,395 **** --- 390,396 ---- InheritableSocket pgStatSock; pid_t PostmasterPid; TimestampTz PgStartTime; + TimestampTz PgReloadTime; bool redirection_done; #ifdef WIN32 HANDLE PostmasterHandle; *************** *** 1008,1013 **** --- 1009,1015 ---- * Remember postmaster startup time */ PgStartTime = GetCurrentTimestamp(); + PgReloadTime = PgStartTime; /* PostmasterRandom wants its own copy */ gettimeofday(&random_start_time, NULL); *************** *** 1931,1936 **** --- 1933,1943 ---- /* Update the starting-point file for future children */ write_nondefault_variables(PGC_SIGHUP); #endif + + /* + * Remember config load time + */ + PgReloadTime = GetCurrentTimestamp(); } PG_SETMASK(&UnBlockSig); *************** *** 4263,4268 **** --- 4270,4276 ---- param->PostmasterPid = PostmasterPid; param->PgStartTime = PgStartTime; + param->PgReloadTime = PgReloadTime; 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-30 12:21:40.476913468 -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" *************** *** 3375,3380 **** --- 3376,3382 ---- */ if (!IsUnderPostmaster) PgStartTime = GetCurrentTimestamp(); + PgReloadTime = PgStartTime; /* * POSTGRES main processing loop begins here *************** *** 3550,3555 **** --- 3552,3564 ---- { got_SIGHUP = false; ProcessConfigFile(PGC_SIGHUP); + + /* + * Remember config load time + */ + LWLockAcquire(ReloadTimeLock, LW_EXCLUSIVE); + PgReloadTime = GetCurrentTimestamp(); + LWLockRelease(ReloadTimeLock); } /* *** ./src/backend/utils/adt/timestamp.c.orig 2008-04-29 23:49:46.359354923 -0400 --- ./src/backend/utils/adt/timestamp.c 2008-04-30 12:23:52.456779063 -0400 *************** *** 42,47 **** --- 42,49 ---- /* Set at postmaster start */ TimestampTz PgStartTime; + /* Set at configuration reload */ + TimestampTz PgReloadTime; static TimeOffset time2t(const int hour, const int min, const int sec, const fsec_t fsec); *************** *** 1162,1167 **** --- 1164,1179 ---- PG_RETURN_TIMESTAMPTZ(PgStartTime); } + Datum + pgsql_conf_load_time(PG_FUNCTION_ARGS) + { + TimestampTz timestamp; + LWLockAcquire(ReloadTimeLock, LW_SHARED); + timestamp = PgReloadTime; + LWLockRelease(ReloadTimeLock); + 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-30 11:30:24.446181191 -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_conf_load_time PGNSP PGUID 12 1 0 f f t f s 0 1184 "" _null_ _null_ _null_ pgsql_conf_load_time - _null_ _null_ )); + DESCR("configuration load 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-30 12:23:49.957160380 -0400 *************** *** 195,200 **** --- 195,202 ---- /* Set at postmaster start */ extern TimestampTz PgStartTime; + /* Set at configuration reload */ + extern TimestampTz PgReloadTime; /* *************** *** 304,309 **** --- 306,312 ---- extern Datum clock_timestamp(PG_FUNCTION_ARGS); extern Datum pgsql_postmaster_start_time(PG_FUNCTION_ARGS); + extern Datum pgsql_conf_load_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