[PATCHES] pg_postmaster_reload_time() patch

2008-04-29 Thread George Gensure
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
+entryliteralfunctionpg_postmaster_reload_time/function()/literal/entry
+entrytypetimestamp with time zone/type/entry
+entryserver last reload time/entry
+   /row
+ 
+   row
 entryliteralfunctionsession_user/function/literal/entry
 entrytypename/type/entry
 entrysession user name/entry
***
*** 11037,11042 
--- 11043,11062 
 /para
  
 indexterm
+ primarypg_postmaster_reload_time/primary
+/indexterm
+ 
+para
+  functionpg_postmaster_reload_time/function returns the
+  typetimestamp with time zone/type when the
+  server was last reloaded.
+/para
+ 
+indexterm
+ primaryversion/primary
+/indexterm
+ 
+indexterm
  primaryversion/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);
+ 	

Re: [PATCHES] pg_postmaster_reload_time() patch

2008-04-30 Thread George Gensure
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 Herrerahttp://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
+entryliteralfunctionpg_conf_load_time/function()/literal/entry
+entrytypetimestamp with time zone/type/entry
+entryconfig load time/entry
+   /row
+ 
+   row
 entryliteralfunctionsession_user/function/literal/entry
 entrytypename/type/entry
 entrysession user name/entry
***
*** 11037,11042 
--- 11043,11062 
 /para
  
 indexterm
+ primarypg_conf_load_time/primary
+/indexterm
+ 
+para
+  functionpg_conf_load_time/function returns the
+  typetimestamp with time zone/type when the
+  config was last loaded for this session.
+/para
+ 
+indexterm
+ primaryversion/primary
+/indexterm
+ 
+indexterm
  primaryversion/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

Re: [PATCHES] pg_postmaster_reload_time() patch

2008-05-02 Thread George Gensure
On Wed, Apr 30, 2008 at 12:58 PM, George Gensure [EMAIL PROTECTED] wrote:
 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


So if nobody's got any further objections, could this patch be applied?

-George

-- 
Sent via pgsql-patches mailing list (pgsql-patches@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-patches


Re: [PATCHES] pg_postmaster_reload_time() patch

2008-05-02 Thread George Gensure
On Fri, May 2, 2008 at 10:31 AM, Alvaro Herrera
[EMAIL PROTECTED] wrote:
 George Gensure escribió:


   So if nobody's got any further objections, could this patch be applied?

  It's in the queue:

  http://wiki.postgresql.org/wiki/CommitFest:May

  --


 Alvaro Herrerahttp://www.CommandPrompt.com/
  The PostgreSQL Company - Command Prompt, Inc.


Thanks!

-George

-- 
Sent via pgsql-patches mailing list (pgsql-patches@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-patches