Index: doc/src/sgml/func.sgml
===================================================================
RCS file: /cvsroot/pgsql/doc/src/sgml/func.sgml,v
retrieving revision 1.276
diff -c -c -r1.276 func.sgml
*** doc/src/sgml/func.sgml 2 Aug 2005 16:11:56 -0000 1.276
--- doc/src/sgml/func.sgml 12 Aug 2005 03:18:29 -0000
***************
*** 9061,9066 ****
--- 9061,9069 ----
pg_cancel_backend
+
+ pg_reload_conf
+
signal
***************
*** 9068,9074 ****
! The function shown in sends control signals to
other server processes. Use of this function is restricted
to superusers.
--- 9071,9077 ----
! The functions shown in sends control signals to
other server processes. Use of this function is restricted
to superusers.
***************
*** 9090,9115 ****
int
Cancel a backend's current query
! This function returns 1 if successful, 0 if not successful.
The process ID (pid) of an active backend can be found
from the procpid column in the
pg_stat_activity view, or by listing the postgres
processes on the server with ps>.
pg_start_backup
-
pg_stop_backup
-
backup
--- 9093,9128 ----
int
Cancel a backend's current query
+
+
+ pg_reload_conf()
+
+ int
+ Causes server processes to reload their configuration files
+
! These functions return 1 if successful, 0 if not successful.
The process ID (pid) of an active backend can be found
from the procpid column in the
pg_stat_activity view, or by listing the postgres
processes on the server with ps>.
+
+ pg_reload_conf> sends a SIGHUP signal to the
+ postmaster, causing the reload of the configuration files
+ in all backend processes.
+
pg_start_backup
pg_stop_backup
backup
***************
*** 9309,9314 ****
--- 9322,9434 ----
appropriate.
+
+ The functions shown in provide native file access to
+ files on the machine hosting the server. Only files relative to
+ the cluster directory are allowed, and the logfile directory,
+ because the logfile directory might be stored outside the
+ cluster directory. Use of these functions is restricted to
+ superusers.
+
+
+
+ Generic File Access Functions
+
+
+ Name Return Type Description
+
+
+
+
+
+
+ pg_file_length(filename_text)
+
+ pg_file_length
+
+
+ int8
+ Returns the file length
+
+
+
+ pg_ls_dir(dirname_text,fullpath_bool)
+
+ pg_ls_dir
+
+
+ setof text
+ List the contents of a directory
+
+
+
+ pg_read_file(filename_text,
+ offset_int8,length_int8)
+
+ text
+ Returns the contents of a text file
+
+
+
+ pg_stat_file(filename_text)
+
+ record
+ Returns information about the file
+
+
+
+
+
+
+ pg_read_file
+
+
+ pg_read_file()> returns part of a textfile, starting
+ at the given offset, returning length bytes. If offset is negative,
+ it is treated relative to the end of the file.
+
+
+
+ pg_stat_file
+
+
+ pg_stat_file()> returns a record containing the
+ length, last accessed timestamp, last modified timestamp,
+ creation timestamp, and a flag indicating if it is a directory.
+
+
+
+ The function shown in forces the server
+ logfile to be rotated if redirect_stderr>
+ is used for logging. Use of this functions is restricted
+ to superusers.
+
+
+
+ Backend Logfile Functions
+
+
+ Name Return Type Description
+
+
+
+
+
+
+ pg_rotate_logfile()
+
+ pg_rotate_logfile
+
+
+ int
+ Rotate logfile
+
+
+
+
+
Index: src/backend/postmaster/postmaster.c
===================================================================
RCS file: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v
retrieving revision 1.462
diff -c -c -r1.462 postmaster.c
*** src/backend/postmaster/postmaster.c 11 Aug 2005 21:11:44 -0000 1.462
--- src/backend/postmaster/postmaster.c 12 Aug 2005 03:18:32 -0000
***************
*** 3394,3399 ****
--- 3394,3402 ----
}
}
+ 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 12 Aug 2005 03:18:33 -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/Makefile
===================================================================
RCS file: /cvsroot/pgsql/src/backend/utils/adt/Makefile,v
retrieving revision 1.58
diff -c -c -r1.58 Makefile
*** src/backend/utils/adt/Makefile 29 Jul 2005 14:46:57 -0000 1.58
--- src/backend/utils/adt/Makefile 12 Aug 2005 03:18:33 -0000
***************
*** 24,30 ****
tid.o timestamp.o varbit.o varchar.o varlena.o version.o xid.o \
network.o mac.o inet_net_ntop.o inet_net_pton.o \
ri_triggers.o pg_lzcompress.o pg_locale.o formatting.o \
! ascii.o quote.o pgstatfuncs.o encode.o dbsize.o
like.o: like.c like_match.c
--- 24,30 ----
tid.o timestamp.o varbit.o varchar.o varlena.o version.o xid.o \
network.o mac.o inet_net_ntop.o inet_net_pton.o \
ri_triggers.o pg_lzcompress.o pg_locale.o formatting.o \
! ascii.o quote.o pgstatfuncs.o encode.o dbsize.o genfile.o
like.o: like.c like_match.c
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 12 Aug 2005 03:18:33 -0000
***************
*** 21,34 ****
--- 21,43 ----
#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))
+ typedef struct
+ {
+ char *location;
+ DIR *dirdesc;
+ } directory_fctx;
+
/*
* Check if data is Null
***************
*** 107,112 ****
--- 116,166 ----
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("must be superuser to 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_rotate_logfile(PG_FUNCTION_ARGS)
+ {
+ if (!superuser())
+ ereport(ERROR,
+ (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
+ (errmsg("must be superuser to 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.380
diff -c -c -r1.380 pg_proc.h
*** src/include/catalog/pg_proc.h 2 Aug 2005 16:11:57 -0000 1.380
--- src/include/catalog/pg_proc.h 12 Aug 2005 03:18:41 -0000
***************
*** 3049,3054 ****
--- 3049,3071 ----
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 = 2621 ( pg_reload_conf PGNSP PGUID 12 f f t f v 0 23 "" _null_ _null_ _null_ pg_reload_conf - _null_ ));
+ DESCR("Reload configuration files");
+
+ DATA(insert OID = 2622 ( pg_rotate_logfile PGNSP PGUID 12 f f t f v 0 23 "" _null_ _null_ _null_ pg_rotate_logfile - _null_ ));
+ DESCR("Rotate log file");
+
+
+ DATA(insert OID = 2623 ( pg_stat_file PGNSP PGUID 12 f f t f v 1 2249 "25" _null_ _null_ _null_ pg_stat_file - _null_ ));
+ DESCR("Return file information");
+ DATA(insert OID = 2624 ( pg_file_length PGNSP PGUID 14 f f t f v 1 20 "25" _null_ _null_ _null_ "SELECT len FROM pg_stat_file($1) AS s(len int8, c timestamp, a timestamp, m timestamp, i bool)" - _null_ ));
+ DESCR("Return file length");
+ DATA(insert OID = 2625 ( pg_read_file PGNSP PGUID 12 f f t f v 3 25 "25 20 20" _null_ _null_ _null_ pg_read_file - _null_ ));
+ DESCR("Read text from a file");
+ DATA(insert OID = 2626 ( pg_ls_dir PGNSP PGUID 12 f f t t v 1 25 "25" _null_ _null_ _null_ pg_ls_dir - _null_ ));
+ DESCR("List all file in a directory");
+
+
/* Aggregates (moved here from pg_aggregate for 7.3) */
DATA(insert OID = 2100 ( avg PGNSP PGUID 12 t f f f i 1 1700 "20" _null_ _null_ _null_ aggregate_dummy - _null_ ));
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 12 Aug 2005 03:18:42 -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 12 Aug 2005 03:18:42 -0000
***************
*** 374,385 ****
--- 374,392 ----
extern Datum pg_complete_relation_size_name(PG_FUNCTION_ARGS);
extern Datum pg_size_pretty(PG_FUNCTION_ARGS);
+ /* genfile.c */
+ extern Datum pg_stat_file(PG_FUNCTION_ARGS);
+ extern Datum pg_read_file(PG_FUNCTION_ARGS);
+ extern Datum pg_ls_dir(PG_FUNCTION_ARGS);
+
/* misc.c */
extern Datum nullvalue(PG_FUNCTION_ARGS);
extern Datum nonnullvalue(PG_FUNCTION_ARGS);
extern Datum current_database(PG_FUNCTION_ARGS);
extern Datum pg_cancel_backend(PG_FUNCTION_ARGS);
+ extern Datum pg_reload_conf(PG_FUNCTION_ARGS);
extern Datum pg_tablespace_databases(PG_FUNCTION_ARGS);
+ extern Datum pg_rotate_logfile(PG_FUNCTION_ARGS);
/* not_in.c */
extern Datum int4notin(PG_FUNCTION_ARGS);