Seems posting to this list from the office didn't work...
The patch is attached as requested - this is just a quick hack, written to
do what I needed at the time.. consider it just as a starting point for
further work.
I've tested it on Solaris 9 with Sun's compiler (Sun Studio 8 Compilers)
but unfortunately don't have the time or facilities for more extensive
tests on other OS's.
Cheers,
Mark
On Thu, 15 Jan 2004, Matthew T. O'Connor wrote:
> Christopher Kings-Lynne wrote:
>
> > What's the best way to do log rolling with pg_autovacuum? It doesn't
> > seem to have any syslog options, etc. Using 'tee' maybe?
>
>
> I got an email from Mark Hollow saying that he had implemented a syslog
> patch for pg_autovacuum. Don't know how good it is, but it might be a
> start.
>
> Mark can you post it to the list?
>
> Matthew
>
> ---------------------------(end of broadcast)---------------------------
> TIP 9: the planner will ignore your desire to choose an index scan if your
> joining column's datatypes do not match
>
Index: pg_autovacuum.c
===================================================================
RCS file: /projects/cvsroot/pgsql-server/contrib/pg_autovacuum/pg_autovacuum.c,v
retrieving revision 1.13
diff -r1.13 pg_autovacuum.c
4a5
> * Basic syslog facility added by Mark Hollow <[EMAIL PROTECTED]>
12a14,27
> /* logging macros */
> #define LOG(M, F) log_entry(M, LOG_INFO, F)
> #define DEBUG(M, F) log_entry(M, LOG_DEBUG, F)
>
> /* log_entry. if fl is true & we're logging to a file (not syslog)
> * then flush the output buffer.
> */
> void
> log_entry(const char *logentry, int level, int fl)
> {
> if(args->logtype == LOGTYPE_FILE) log_file(logentry, fl);
> if(args->logtype == LOGTYPE_SYSLOG) log_syslog(logentry, level);
> }
>
14c29
< log_entry(const char *logentry)
---
> log_file(const char *logentry, int fl)
23a39,48
>
> /* Flush log? */
> if(fl) fflush(LOGOUTPUT);
> }
>
> /* log to syslog
> void
> log_syslog(const char *logentry, int level)
> {
> syslog(level, logentry);
37,38c62
< log_entry("Error: cannot disassociate from controlling TTY");
< fflush(LOGOUTPUT);
---
> LOG("Error: cannot disassociate from controlling TTY", 1);
52,53c76
< log_entry("Error: cannot disassociate from controlling TTY");
< fflush(LOGOUTPUT);
---
> LOG("Error: cannot disassociate from controlling TTY", 1);
68,69c91
< log_entry("init_table_info: Cannot get memory");
< fflush(LOGOUTPUT);
---
> LOG("init_table_info: Cannot get memory", 1);
82,83c104
< log_entry("init_table_info: malloc failed on new_tbl->schema_name");
< fflush(LOGOUTPUT);
---
> LOG("init_table_info: malloc failed on new_tbl->schema_name", 1);
94,95c115
< log_entry("init_table_info: malloc failed on new_tbl->table_name");
< fflush(LOGOUTPUT);
---
> LOG("init_table_info: malloc failed on new_tbl->table_name", 1);
285c305
< log_entry(logbuffer);
---
> DEBUG(logbuffer, 0);
289c309
< fflush(LOGOUTPUT);
---
> if(LOGOUTPUT != NULL) fflush(LOGOUTPUT);
308,309c328
< log_entry(logbuffer);
< fflush(LOGOUTPUT);
---
> DEBUG(logbuffer, 1);
363c382
< log_entry(logbuffer);
---
> DEBUG(logbuffer, 0);
365c384
< log_entry(logbuffer);
---
> DEBUG(logbuffer, 0);
367c386
< log_entry(logbuffer);
---
> DEBUG(logbuffer, 0);
370c389
< log_entry(logbuffer);
---
> DEBUG(logbuffer, 0);
373c392
< log_entry(logbuffer);
---
> DEBUG(logbuffer, 0);
376,377c395
< log_entry(logbuffer);
< fflush(LOGOUTPUT);
---
> DEBUG(logbuffer, 1);
395,396c413
< log_entry("init_db_list(): Error creating db_list for db: template1.");
< fflush(LOGOUTPUT);
---
> LOG("init_db_list(): Error creating db_list for db: template1.", 1);
470,471c487
< log_entry("updating the database list");
< fflush(LOGOUTPUT);
---
> LOG("updating the database list", 1);
556c572
< log_entry(logbuffer);
---
> DEBUG(logbuffer, 0);
560c576
< fflush(LOGOUTPUT);
---
> if(LOGOUTPUT != NULL) fflush(LOGOUTPUT);
614,615c630
< log_entry(logbuffer);
< fflush(LOGOUTPUT);
---
> DEBUG(logbuffer, 1);
683c698
< log_entry(logbuffer);
---
> LOG(logbuffer, 0);
686c701
< log_entry(logbuffer);
---
> LOG(logbuffer, 0);
688c703
< log_entry(" conn is valid, we are connected");
---
> LOG(" conn is valid, we are connected", 1);
690c705
< log_entry(" conn is null, we are not connected.");
---
> LOG(" conn is null, we are not connected.", 1);
692d706
< fflush(LOGOUTPUT);
713,714c727
< log_entry(logbuffer);
< fflush(LOGOUTPUT);
---
> LOG(logbuffer, 1);
755c768
< log_entry(query);
---
> DEBUG(query, 0);
764c777
< log_entry(logbuffer);
---
> LOG(logbuffer, 0);
766,767c779
< log_entry(logbuffer);
< fflush(LOGOUTPUT);
---
> LOG(logbuffer, 1);
776c788
< log_entry(logbuffer);
---
> LOG(logbuffer, 0);
778,779c790
< log_entry(logbuffer);
< fflush(LOGOUTPUT);
---
> LOG(logbuffer, 1);
816a828
> args->logtype = 0;
817a830
> args->logfacility = LOG_LOCAL0;
824c837
< while ((c = getopt(argc, argv, "s:S:v:V:a:A:d:U:P:H:L:p:hD")) != -1)
---
> while ((c = getopt(argc, argv, "s:S:v:V:a:A:d:U:P:H:l:L:p:hD")) != -1)
860a874,891
> case 'l':
> args->logtype = LOGTYPE_SYSLOG;
> if(strcmp(optarg, "user") == 0) args->logfacility =
> LOG_USER;
> if(strcmp(optarg, "mail") == 0) args->logfacility =
> LOG_MAIL;
> if(strcmp(optarg, "daemon") == 0) args->logfacility =
> LOG_DAEMON;
> if(strcmp(optarg, "auth") == 0) args->logfacility =
> LOG_AUTH;
> if(strcmp(optarg, "lpr") == 0) args->logfacility =
> LOG_LPR;
> if(strcmp(optarg, "news") == 0) args->logfacility =
> LOG_NEWS;
> if(strcmp(optarg, "uucp") == 0) args->logfacility =
> LOG_UUCP;
> if(strcmp(optarg, "cron") == 0) args->logfacility =
> LOG_CRON;
> if(strcmp(optarg, "local0") == 0) args->logfacility =
> LOG_LOCAL0;
> if(strcmp(optarg, "local1") == 0) args->logfacility =
> LOG_LOCAL1;
> if(strcmp(optarg, "local2") == 0) args->logfacility =
> LOG_LOCAL2;
> if(strcmp(optarg, "local3") == 0) args->logfacility =
> LOG_LOCAL3;
> if(strcmp(optarg, "local4") == 0) args->logfacility =
> LOG_LOCAL4;
> if(strcmp(optarg, "local5") == 0) args->logfacility =
> LOG_LOCAL5;
> if(strcmp(optarg, "local6") == 0) args->logfacility =
> LOG_LOCAL6;
> break;
862a894
> args->logtype = LOGTYPE_FILE;
919c951,952
< fprintf(stderr, " [-L] logfile (default=none)\n");
---
> fprintf(stderr, " [-l] syslog facility (default=local0)\n");
> fprintf(stderr, " [-L] logfile (default=none, overrides -o syslog)\n");
933c966
< log_entry(logbuffer);
---
> DEBUG(logbuffer, 0);
935c968
< log_entry(logbuffer);
---
> DEBUG(logbuffer, 0);
937c970
< log_entry(logbuffer);
---
> DEBUG(logbuffer, 0);
939c972
< log_entry(logbuffer);
---
> DEBUG(logbuffer, 0);
941c974
< log_entry(logbuffer);
---
> DEBUG(logbuffer, 0);
943c976
< log_entry(logbuffer);
---
> DEBUG(logbuffer, 0);
945c978
< log_entry(logbuffer);
---
> DEBUG(logbuffer, 0);
948c981
< log_entry(logbuffer);
---
> DEBUG(logbuffer, 0);
950c983
< log_entry(logbuffer);
---
> DEBUG(logbuffer, 0);
952c985
< log_entry(logbuffer);
---
> DEBUG(logbuffer, 0);
954c987
< log_entry(logbuffer);
---
> DEBUG(logbuffer, 0);
956c989
< log_entry(logbuffer);
---
> DEBUG(logbuffer, 0);
958c991
< log_entry(logbuffer);
---
> DEBUG(logbuffer, 0);
960,962c993
< log_entry(logbuffer);
<
< fflush(LOGOUTPUT);
---
> DEBUG(logbuffer, 1);
992c1023
< if (args->logfile)
---
> if ((args->logtype == 0) && args->logfile)
1000a1032,1036
> else if (args->logtype == 1)
> {
> openlog("pg_autovacuum", LOG_PID, args->logfacility);
> LOGOUTPUT == NULL;
> }
1002a1039
>
1013,1015c1050,1051
< log_entry("Error: GUC variable stats_row_level must be enabled.");
< log_entry(" Please fix the problems and try again.");
< fflush(LOGOUTPUT);
---
> LOG("Error: GUC variable stats_row_level must be enabled.", 0);
> LOG(" Please fix the problems and try again.", 1);
1035,1037c1071,1072
< log_entry("Error: Cannot connect to template1,
exiting.");
< fflush(LOGOUTPUT);
< fclose(LOGOUTPUT);
---
> LOG("Error: Cannot connect to template1, exiting.", 1);
> if(LOGOUTPUT != NULL) fclose(LOGOUTPUT);
1107,1108c1142
<
log_entry(logbuffer);
<
fflush(LOGOUTPUT);
---
>
> DEBUG(logbuffer, 1);
1121,1122c1155
<
log_entry(logbuffer);
<
fflush(LOGOUTPUT);
---
>
> DEBUG(logbuffer, 1);
1163,1164c1196
< log_entry(logbuffer);
< fflush(LOGOUTPUT);
---
> DEBUG(logbuffer, 1);
Index: pg_autovacuum.h
===================================================================
RCS file: /projects/cvsroot/pgsql-server/contrib/pg_autovacuum/pg_autovacuum.h,v
retrieving revision 1.8
diff -r1.8 pg_autovacuum.h
25a26,29
> #include <syslog.h>
> #define LOGTYPE_FILE 0
> #define LOGTYPE_SYSLOG 1
>
51c55,57
< daemonize;
---
> daemonize,
> logtype,
> logfacility;
139c145,147
< static void log_entry(const char *logentry);
---
> static void log_entry(const char *logentry, int level, int flush);
> static void log_file(const char *logentry, int flush);
> static void log_syslog(const char *logentry, int level);
---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?
http://archives.postgresql.org