Re: [PATCHES] log session end - again

2004-02-03 Thread Andrew Dunstan


Peter Eisentraut wrote:

Andrew Dunstan wrote:
 

This patch brings up to date what I did last year (now unfortunately
bitrotted) to allow the logging of the end of a session, enabled by
the config setting "log_session_end - true". It produces lines like
these:
   

If we log "session" end, shouldn't we also log "session" start, rather 
than "connection" start?  It seems there should be some symmetry here, 
also for the configuration parameter names.

 

OK, this version of the patch uses the config parameter name 
"log_disconnections" for the sake of symmetry, and changes the message 
wording slightly accordingly.

cheers

andrew
Index: doc/src/sgml/runtime.sgml
===
RCS file: /projects/cvsroot/pgsql-server/doc/src/sgml/runtime.sgml,v
retrieving revision 1.235
diff -c -r1.235 runtime.sgml
*** doc/src/sgml/runtime.sgml   27 Jan 2004 16:51:43 -  1.235
--- doc/src/sgml/runtime.sgml   2 Feb 2004 19:08:42 -
***
*** 1825,1830 
--- 1825,1844 
  
  
   
+   log_disconnections (boolean)
+   
+
+This outputs a line to the server logs similar to LOG_CONNECTIONS 
+but at the end of a session, and including the duration of the 
+session.This is off by default. This option can only be set at 
+server start or in the postgresql.conf 
+configuration file.
+
+   
+  
+ 
+ 
+  
log_duration (boolean)

 
Index: src/backend/postmaster/postmaster.c
===
RCS file: /projects/cvsroot/pgsql-server/src/backend/postmaster/postmaster.c,v
retrieving revision 1.364
diff -c -r1.364 postmaster.c
*** src/backend/postmaster/postmaster.c 28 Jan 2004 21:02:40 -  1.364
--- src/backend/postmaster/postmaster.c 2 Feb 2004 19:08:43 -
***
*** 2438,2443 
--- 2438,2450 
 * Signal handlers setting is moved to tcop/postgres...
 */
  
+   /* save start time for end of session reporting */
+   gettimeofday(&(port->session_start),NULL);
+ 
+   /* set these to empty in case they are needed before we set them up */
+   port->remote_host = "";
+   port->remote_port = "";
+ 
/* Save port etc. for ps status */
MyProcPort = port;
  
***
*** 2492,2497 
--- 2499,2510 
snprintf(tmphost, sizeof(tmphost), "%s:%s", remote_host, remote_port);
StrNCpy(remote_host, tmphost, sizeof(remote_host));
}
+ 
+   /*
+* save remote_host and remote_port in port stucture
+*/
+   port->remote_host = strdup(remote_host);
+   port->remote_port = strdup(remote_port);
  
/*
 * Ready to begin client interaction.  We will give up and exit(0)
Index: src/backend/tcop/postgres.c
===
RCS file: /projects/cvsroot/pgsql-server/src/backend/tcop/postgres.c,v
retrieving revision 1.387
diff -c -r1.387 postgres.c
*** src/backend/tcop/postgres.c 28 Jan 2004 21:02:40 -  1.387
--- src/backend/tcop/postgres.c 2 Feb 2004 19:08:43 -
***
*** 84,89 
--- 84,92 
  bool  Warn_restart_ready = false;
  bool  InError = false;
  
+ /* flag for logging end of session */
+ boolLog_disconnections = false;
+ 
  /*
   * Flags for expensive function optimization -- JMH 3/9/92
   */
***
*** 149,154 
--- 152,158 
  static void finish_xact_command(void);
  static void SigHupHandler(SIGNAL_ARGS);
  static void FloatExceptionHandler(SIGNAL_ARGS);
+ static void log_session_end(void);
  
  
  /* 
***
*** 2406,2412 
--- 2410,2419 
 * other output options.
 */
if (debug_flag >= 1)
+   {
SetConfigOption("log_connections", "true", debug_context, gucsource);
+   SetConfigOption("log_disconnections", "true", debug_context, 
gucsource);
+   }
if (debug_flag >= 2)
SetConfigOption("log_statement", "true", debug_context, gucsource);
if (debug_flag >= 3)
***
*** 2435,2440 
--- 2442,2453 
gucopts = lnext(gucopts);
SetConfigOption(name, value, PGC_BACKEND, PGC_S_CLIENT);
}
+ 
+   /*
+* set up handler to log session end.
+*/
+   if (IsUnderPostmaster && Log_disconnections)
+   on_proc_exit(log_session_end,0);
}
  
/*
***
*** 3172,3175 
--- 3185,3246 
 errdetail("%s", str.data)));
  
pfree(str.data);
+ }
+ 
+ /*
+  * on_proc_exit handler to log end of session
+  */
+ static void 
+ log_session_end(void)
+ {
+   Port * port = MyProcPort;
+   struct timeval 

Re: [PATCHES] log session end - again

2004-02-02 Thread Peter Eisentraut
Andrew Dunstan wrote:
> This patch brings up to date what I did last year (now unfortunately
> bitrotted) to allow the logging of the end of a session, enabled by
> the config setting "log_session_end - true". It produces lines like
> these:

If we log "session" end, shouldn't we also log "session" start, rather 
than "connection" start?  It seems there should be some symmetry here, 
also for the configuration parameter names.


---(end of broadcast)---
TIP 4: Don't 'kill -9' the postmaster