Dave Page wrote:
> 
> [Resent as the list seems to have rejected yesterdays attempt]
> 
> As per Bruce's request, here's a copy of Andreas' server 
> instrumentation patch for review. I've separated out the 
> dbsize stuff and pg_terminate_backend is also not included.
> 
> This version was generated against CVS today.
> 
> As far as I can tell from review of comments made back to 
> pre-8.0, all security and other concerns raised have been addressed.

Here is a modified version of your patch that adds functions to do
configuration file reload, and log file rotation.

-- 
  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
Index: doc/src/sgml/func.sgml
===================================================================
RCS file: /cvsroot/pgsql/doc/src/sgml/func.sgml,v
retrieving revision 1.275
diff -c -c -r1.275 func.sgml
*** doc/src/sgml/func.sgml      30 Jul 2005 22:53:15 -0000      1.275
--- doc/src/sgml/func.sgml      1 Aug 2005 02:22:48 -0000
***************
*** 9069,9074 ****
--- 9069,9077 ----
     <indexterm zone="functions-admin">
      <primary>pg_cancel_backend</primary>
     </indexterm>
+    <indexterm zone="functions-admin">
+     <primary>pg_reload_conf</primary>
+    </indexterm>
  
     <indexterm zone="functions-admin">
      <primary>signal</primary>
***************
*** 9076,9082 ****
     </indexterm>
  
     <para>
!     The function shown in <xref
      linkend="functions-admin-signal-table"> sends control signals to
      other server processes.  Use of this function is restricted
      to superusers.
--- 9079,9085 ----
     </indexterm>
  
     <para>
!     The functions shown in <xref
      linkend="functions-admin-signal-table"> sends control signals to
      other server processes.  Use of this function is restricted
      to superusers.
***************
*** 9098,9118 ****
         <entry><type>int</type></entry>
         <entry>Cancel a backend's current query</entry>
        </row>
       </tbody>
      </tgroup>
     </table>
  
     <para>
!     This function returns 1 if successful, 0 if not successful.
      The process ID (<literal>pid</literal>) of an active backend can be found
      from the <structfield>procpid</structfield> column in the
      <structname>pg_stat_activity</structname> view, or by listing the 
<command>postgres</command>
      processes on the server with <application>ps</>.
     </para>
! 
!    <indexterm zone="functions-admin">
!     <primary>pg_start_backup</primary>
!    </indexterm>
  
     <indexterm zone="functions-admin">
      <primary>pg_stop_backup</primary>
--- 9101,9129 ----
         <entry><type>int</type></entry>
         <entry>Cancel a backend's current query</entry>
        </row>
+       <row>
+        <entry>
+         <literal><function>pg_reload_conf</function>()</literal>
+         </entry>
+        <entry><type>int</type></entry>
+        <entry>Triggers the server processes to reload configuration 
files</entry>
+       </row>
       </tbody>
      </tgroup>
     </table>
  
     <para>
!     These functions return 1 if successful, 0 if not successful.
      The process ID (<literal>pid</literal>) of an active backend can be found
      from the <structfield>procpid</structfield> column in the
      <structname>pg_stat_activity</structname> view, or by listing the 
<command>postgres</command>
      processes on the server with <application>ps</>.
     </para>
!    <para>
!     <function>pg_reload_conf</> sends a SIGHUP event to the
!     postmaster, and thus triggers a reload of the configuration files
!     in all backend processes.
!    </para>
  
     <indexterm zone="functions-admin">
      <primary>pg_stop_backup</primary>
Index: src/backend/postmaster/postmaster.c
===================================================================
RCS file: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v
retrieving revision 1.461
diff -c -c -r1.461 postmaster.c
*** src/backend/postmaster/postmaster.c 29 Jul 2005 19:30:04 -0000      1.461
--- src/backend/postmaster/postmaster.c 1 Aug 2005 02:22:50 -0000
***************
*** 3393,3398 ****
--- 3393,3403 ----
                }
        }
  
+       if (CheckPostmasterSignal(PMSIGNAL_ROTATE_LOGFILE) && SysLoggerPID != 0)
+       {
+           kill(SysLoggerPID, SIGUSR1);
+       }
+ 
        PG_SETMASK(&UnBlockSig);
  
        errno = save_errno;
Index: src/backend/postmaster/syslogger.c
===================================================================
RCS file: /cvsroot/pgsql/src/backend/postmaster/syslogger.c,v
retrieving revision 1.18
diff -c -c -r1.18 syslogger.c
*** src/backend/postmaster/syslogger.c  21 Jul 2005 18:06:12 -0000      1.18
--- src/backend/postmaster/syslogger.c  1 Aug 2005 02:22:50 -0000
***************
*** 101,106 ****
--- 101,107 ----
   * Flags set by interrupt handlers for later service in the main loop.
   */
  static volatile sig_atomic_t got_SIGHUP = false;
+ static volatile sig_atomic_t rotation_requested = false;
  
  
  /* Local subroutines */
***************
*** 117,122 ****
--- 118,124 ----
  static char *logfile_getname(pg_time_t timestamp);
  static void set_next_rotation_time(void);
  static void sigHupHandler(SIGNAL_ARGS);
+ static void sigUsr1Handler(SIGNAL_ARGS);
  
  
  /*
***************
*** 200,206 ****
        pqsignal(SIGQUIT, SIG_IGN);
        pqsignal(SIGALRM, SIG_IGN);
        pqsignal(SIGPIPE, SIG_IGN);
!       pqsignal(SIGUSR1, SIG_IGN);
        pqsignal(SIGUSR2, SIG_IGN);
  
        /*
--- 202,208 ----
        pqsignal(SIGQUIT, SIG_IGN);
        pqsignal(SIGALRM, SIG_IGN);
        pqsignal(SIGPIPE, SIG_IGN);
!       pqsignal(SIGUSR1, sigUsr1Handler);  /* request log rotation */
        pqsignal(SIGUSR2, SIG_IGN);
  
        /*
***************
*** 235,241 ****
        /* main worker loop */
        for (;;)
        {
-               bool            rotation_requested = false;
                bool            time_based_rotation = false;
  
  #ifndef WIN32
--- 237,242 ----
***************
*** 726,731 ****
--- 727,734 ----
        char       *filename;
        FILE       *fh;
  
+       rotation_requested = false;
+ 
        /*
         * When doing a time-based rotation, invent the new logfile name based
         * on the planned rotation time, not current time, to avoid "slippage"
***************
*** 876,878 ****
--- 879,888 ----
  {
        got_SIGHUP = true;
  }
+ 
+ /* SIGUSR1: set flag to rotate logfile */
+ static void
+ sigUsr1Handler(SIGNAL_ARGS)
+ {
+       rotation_requested = true;
+ }
Index: src/backend/utils/adt/misc.c
===================================================================
RCS file: /cvsroot/pgsql/src/backend/utils/adt/misc.c,v
retrieving revision 1.45
diff -c -c -r1.45 misc.c
*** src/backend/utils/adt/misc.c        4 Jul 2005 04:51:50 -0000       1.45
--- src/backend/utils/adt/misc.c        1 Aug 2005 02:22:52 -0000
***************
*** 21,31 ****
--- 21,34 ----
  #include "commands/dbcommands.h"
  #include "miscadmin.h"
  #include "storage/procarray.h"
+ #include "storage/pmsignal.h"
  #include "storage/fd.h"
  #include "utils/builtins.h"
+ #include "utils/elog.h"
  #include "funcapi.h"
  #include "catalog/pg_type.h"
  #include "catalog/pg_tablespace.h"
+ #include "postmaster/syslogger.h"
  
  #define atooid(x)  ((Oid) strtoul((x), NULL, 10))
  
***************
*** 107,112 ****
--- 110,160 ----
        PG_RETURN_INT32(pg_signal_backend(PG_GETARG_INT32(0), SIGINT));
  }
  
+ 
+ Datum
+ pg_reload_conf(PG_FUNCTION_ARGS)
+ {
+       if (!superuser()) 
+               ereport(ERROR,
+                               (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
+                                (errmsg("only superuser can signal the 
postmaster"))));
+ 
+       if (kill(PostmasterPid, SIGHUP))
+       {
+               ereport(WARNING,
+                               (errmsg("failed to send signal to postmaster: 
%m")));
+ 
+               PG_RETURN_INT32(0);
+       }
+ 
+       PG_RETURN_INT32(1);
+ }
+ 
+ 
+ /*
+  * Rotate log file
+  */
+ Datum
+ pg_logfile_rotate(PG_FUNCTION_ARGS)
+ {
+       if (!superuser()) 
+               ereport(ERROR,
+                               (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
+                                (errmsg("only superuser can rotate log 
files"))));
+ 
+     if (!Redirect_stderr)
+       {
+           ereport(NOTICE,
+                               (errcode(ERRCODE_WARNING),
+                                errmsg("no logfile configured; rotation not 
supported")));
+               PG_RETURN_INT32(0);
+       }
+ 
+       SendPostmasterSignal(PMSIGNAL_ROTATE_LOGFILE);
+ 
+       PG_RETURN_INT32(0);
+ }
+ 
  #ifdef NOT_USED
  
  /* Disabled in 8.0 due to reliability concerns; FIXME someday */
Index: src/include/catalog/pg_proc.h
===================================================================
RCS file: /cvsroot/pgsql/src/include/catalog/pg_proc.h,v
retrieving revision 1.379
diff -c -c -r1.379 pg_proc.h
*** src/include/catalog/pg_proc.h       29 Jul 2005 14:47:01 -0000      1.379
--- src/include/catalog/pg_proc.h       1 Aug 2005 02:22:58 -0000
***************
*** 3048,3053 ****
--- 3048,3057 ----
  DESCR("Prepare for taking an online backup");
  DATA(insert OID = 2173 ( pg_stop_backup                       PGNSP PGUID 12 
f f t f v 0 25 "" _null_ _null_ _null_ pg_stop_backup - _null_ ));
  DESCR("Finish taking an online backup");
+ DATA(insert OID = 1136 ( pg_reload_conf         PGNSP PGUID 12 f f t f v 0 23 
"" _null_ _null_ _null_ pg_reload_conf - _null_ ));
+ DESCR("Reloads configuration files");
+ DATA(insert OID = 1137 ( pg_logfile_rotate            PGNSP PGUID 12 f f t f 
v 0 23 "" _null_ _null_ _null_ pg_logfile_rotate - _null_ ));
+ DESCR("rotate log file");
  
  /* Aggregates (moved here from pg_aggregate for 7.3) */
  
Index: src/include/storage/pmsignal.h
===================================================================
RCS file: /cvsroot/pgsql/src/include/storage/pmsignal.h,v
retrieving revision 1.12
diff -c -c -r1.12 pmsignal.h
*** src/include/storage/pmsignal.h      28 Jun 2005 19:51:25 -0000      1.12
--- src/include/storage/pmsignal.h      1 Aug 2005 02:22:59 -0000
***************
*** 25,30 ****
--- 25,31 ----
        PMSIGNAL_PASSWORD_CHANGE,       /* pg_auth file has changed */
        PMSIGNAL_WAKEN_CHILDREN,        /* send a SIGUSR1 signal to all 
backends */
        PMSIGNAL_WAKEN_ARCHIVER,        /* send a NOTIFY signal to xlog 
archiver */
+       PMSIGNAL_ROTATE_LOGFILE,        /* send SIGUSR1 to syslogger to rotate 
logfile */
  
        NUM_PMSIGNALS                           /* Must be last value of enum! 
*/
  } PMSignalReason;
Index: src/include/utils/builtins.h
===================================================================
RCS file: /cvsroot/pgsql/src/include/utils/builtins.h,v
retrieving revision 1.262
diff -c -c -r1.262 builtins.h
*** src/include/utils/builtins.h        29 Jul 2005 14:47:04 -0000      1.262
--- src/include/utils/builtins.h        1 Aug 2005 02:22:59 -0000
***************
*** 380,385 ****
--- 380,387 ----
  extern Datum current_database(PG_FUNCTION_ARGS);
  extern Datum pg_cancel_backend(PG_FUNCTION_ARGS);
  extern Datum pg_tablespace_databases(PG_FUNCTION_ARGS);
+ extern Datum pg_reload_conf(PG_FUNCTION_ARGS);
+ extern Datum pg_logfile_rotate(PG_FUNCTION_ARGS);
  
  /* not_in.c */
  extern Datum int4notin(PG_FUNCTION_ARGS);
---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
       choose an index scan if your joining column's datatypes do not
       match

Reply via email to