Commit b3d58ea7 authored by Tom Lane's avatar Tom Lane

Include dllist.c directly instead of assuming that libpq will provide it.

Whack some semblance of project-conventions-conformance into pg_autovacuum.h.
parent dc19aaa1
PROGRAM = pg_autovacuum PROGRAM = pg_autovacuum
OBJS = pg_autovacuum.o OBJS = pg_autovacuum.o dllist.o
PG_CPPFLAGS = -I$(libpq_srcdir) PG_CPPFLAGS = -I$(libpq_srcdir) -DFRONTEND
PG_LIBS = $(libpq) PG_LIBS = $(libpq)
DOCS = README.pg_autovacuum DOCS = README.pg_autovacuum
EXTRA_CLEAN = dllist.c
ifdef USE_PGXS ifdef USE_PGXS
PGXS = $(shell pg_config --pgxs) PGXS = $(shell pg_config --pgxs)
include $(PGXS) include $(PGXS)
...@@ -15,3 +17,6 @@ top_builddir = ../.. ...@@ -15,3 +17,6 @@ top_builddir = ../..
include $(top_builddir)/src/Makefile.global include $(top_builddir)/src/Makefile.global
include $(top_srcdir)/contrib/contrib-global.mk include $(top_srcdir)/contrib/contrib-global.mk
endif endif
dllist.c: $(top_srcdir)/src/backend/lib/dllist.c
rm -f $@ && $(LN_S) $< .
...@@ -3,13 +3,25 @@ ...@@ -3,13 +3,25 @@
* (c) 2003 Matthew T. O'Connor * (c) 2003 Matthew T. O'Connor
* Revisions by Christopher B. Browne, Liberty RMS * Revisions by Christopher B. Browne, Liberty RMS
* Win32 Service code added by Dave Page * Win32 Service code added by Dave Page
*
* $PostgreSQL: pgsql/contrib/pg_autovacuum/pg_autovacuum.c,v 1.22 2004/10/16 21:50:02 tgl Exp $
*/ */
#include "pg_autovacuum.h" #include "postgres_fe.h"
#include <unistd.h>
#ifdef HAVE_GETOPT_H
#include <getopt.h>
#endif
#include <time.h>
#include <sys/time.h>
#ifdef WIN32 #ifdef WIN32
#include <windows.h> #include <windows.h>
#endif
#include "pg_autovacuum.h"
#ifdef WIN32
unsigned int sleep(); unsigned int sleep();
SERVICE_STATUS ServiceStatus; SERVICE_STATUS ServiceStatus;
...@@ -17,8 +29,62 @@ SERVICE_STATUS_HANDLE hStatus; ...@@ -17,8 +29,62 @@ SERVICE_STATUS_HANDLE hStatus;
int appMode = 0; int appMode = 0;
#endif #endif
FILE *LOGOUTPUT; /* define atooid */
char logbuffer[4096]; #define atooid(x) ((Oid) strtoul((x), NULL, 10))
static cmd_args *args;
static FILE *LOGOUTPUT;
static char logbuffer[4096];
/* The main program loop function */
static int VacuumLoop(int argc, char **argv);
/* Functions for dealing with command line arguements */
static cmd_args *get_cmd_args(int argc, char *argv[]);
static void print_cmd_args(void);
static void free_cmd_args(void);
static void usage(void);
/* Functions for managing database lists */
static Dllist *init_db_list(void);
static db_info *init_dbinfo(char *dbname, Oid oid, long age);
static void update_db_list(Dllist *db_list);
static void remove_db_from_list(Dlelem *db_to_remove);
static void print_db_info(db_info * dbi, int print_table_list);
static void print_db_list(Dllist *db_list, int print_table_lists);
static int xid_wraparound_check(db_info * dbi);
static void free_db_list(Dllist *db_list);
/* Functions for managing table lists */
static tbl_info *init_table_info(PGresult *conn, int row, db_info * dbi);
static void update_table_list(db_info * dbi);
static void remove_table_from_list(Dlelem *tbl_to_remove);
static void print_table_list(Dllist *tbl_node);
static void print_table_info(tbl_info * tbl);
static void update_table_thresholds(db_info * dbi, tbl_info * tbl, int vacuum_type);
static void free_tbl_list(Dllist *tbl_list);
/* A few database helper functions */
static int check_stats_enabled(db_info * dbi);
static PGconn *db_connect(db_info * dbi);
static void db_disconnect(db_info * dbi);
static PGresult *send_query(const char *query, db_info * dbi);
/* Other Generally needed Functions */
#ifndef WIN32
static void daemonize(void);
#endif
static void log_entry(const char *logentry, int level);
#ifdef WIN32
/* Windows Service related functions */
static void ControlHandler(DWORD request);
static int InstallService();
static int RemoveService();
#endif
static void static void
log_entry(const char *logentry, int level) log_entry(const char *logentry, int level)
......
/* pg_autovacuum.hszCmdline /* pg_autovacuum.h
* Header file for pg_autovacuum.c * Header file for pg_autovacuum.c
* (c) 2003 Matthew T. O'Connor * (c) 2003 Matthew T. O'Connor
*
* $PostgreSQL: pgsql/contrib/pg_autovacuum/pg_autovacuum.h,v 1.12 2004/10/16 21:50:02 tgl Exp $
*/ */
#define FRONTEND #ifndef _PG_AUTOVACUUM_H
#define _PG_AUTOVACUUM_H
#include "postgres_fe.h"
#include <unistd.h>
#ifdef HAVE_GETOPT_H
#include <getopt.h>
#endif
#include <time.h>
#include <sys/time.h>
/* These next two lines are correct when pg_autovaccum is compiled
from within the postgresql source tree */
#include "libpq-fe.h" #include "libpq-fe.h"
#include "lib/dllist.h" #include "lib/dllist.h"
/* Had to change the last two lines to compile on
Redhat outside of postgresql source tree */
/*
#include "/usr/include/libpq-fe.h"
#include "/usr/include/pgsql/server/lib/dllist.h"
*/
#define AUTOVACUUM_DEBUG 0 #define AUTOVACUUM_DEBUG 0
#define VACBASETHRESHOLD 1000 #define VACBASETHRESHOLD 1000
...@@ -43,9 +29,6 @@ ...@@ -43,9 +29,6 @@
#define FROZENOID_QUERY "select oid,age(datfrozenxid) from pg_database where datname = 'template1'" #define FROZENOID_QUERY "select oid,age(datfrozenxid) from pg_database where datname = 'template1'"
#define FROZENOID_QUERY2 "select oid,datname,age(datfrozenxid) from pg_database where datname!='template0'" #define FROZENOID_QUERY2 "select oid,datname,age(datfrozenxid) from pg_database where datname!='template0'"
/* define atooid */
#define atooid(x) ((Oid) strtoul((x), NULL, 10))
/* Log levels */ /* Log levels */
enum enum
{ {
...@@ -57,7 +40,7 @@ enum ...@@ -57,7 +40,7 @@ enum
}; };
/* define cmd_args stucture */ /* define cmd_args stucture */
struct cmdargs typedef struct cmdargs
{ {
int vacuum_base_threshold, int vacuum_base_threshold,
analyze_base_threshold, analyze_base_threshold,
...@@ -81,16 +64,13 @@ struct cmdargs ...@@ -81,16 +64,13 @@ struct cmdargs
*host, *host,
*logfile, *logfile,
*port; *port;
}; } cmd_args;
typedef struct cmdargs cmd_args;
/*
/* define cmd_args as global so we can get to them everywhere */ * Might need to add a time value for last time the whole database was
cmd_args *args; * vacuumed. We need to guarantee this happens approx every 1Billion TX's
*/
/* Might need to add a time value for last time the whold database was vacuumed. typedef struct dbinfo
I think we need to guarantee this happens approx every 1Million TX's */
struct dbinfo
{ {
Oid oid; Oid oid;
long age; long age;
...@@ -102,10 +82,9 @@ struct dbinfo ...@@ -102,10 +82,9 @@ struct dbinfo
*username, *username,
*password; *password;
Dllist *table_list; Dllist *table_list;
}; } db_info;
typedef struct dbinfo db_info;
struct tableinfo typedef struct tableinfo
{ {
char *schema_name, char *schema_name,
*table_name; *table_name;
...@@ -125,53 +104,6 @@ struct tableinfo ...@@ -125,53 +104,6 @@ struct tableinfo
curr_vacuum_count; /* Latest values from stats system */ curr_vacuum_count; /* Latest values from stats system */
db_info *dbi; /* pointer to the database that this table db_info *dbi; /* pointer to the database that this table
* belongs to */ * belongs to */
}; } tbl_info;
typedef struct tableinfo tbl_info;
/* The main program loop function */ #endif /* _PG_AUTOVACUUM_H */
static int VacuumLoop(int argc, char **argv);
/* Functions for dealing with command line arguements */
static cmd_args *get_cmd_args(int argc, char *argv[]);
static void print_cmd_args(void);
static void free_cmd_args(void);
static void usage(void);
/* Functions for managing database lists */
static Dllist *init_db_list(void);
static db_info *init_dbinfo(char *dbname, Oid oid, long age);
static void update_db_list(Dllist *db_list);
static void remove_db_from_list(Dlelem *db_to_remove);
static void print_db_info(db_info * dbi, int print_table_list);
static void print_db_list(Dllist *db_list, int print_table_lists);
static int xid_wraparound_check(db_info * dbi);
static void free_db_list(Dllist *db_list);
/* Functions for managing table lists */
static tbl_info *init_table_info(PGresult *conn, int row, db_info * dbi);
static void update_table_list(db_info * dbi);
static void remove_table_from_list(Dlelem *tbl_to_remove);
static void print_table_list(Dllist *tbl_node);
static void print_table_info(tbl_info * tbl);
static void update_table_thresholds(db_info * dbi, tbl_info * tbl, int vacuum_type);
static void free_tbl_list(Dllist *tbl_list);
/* A few database helper functions */
static int check_stats_enabled(db_info * dbi);
static PGconn *db_connect(db_info * dbi);
static void db_disconnect(db_info * dbi);
static PGresult *send_query(const char *query, db_info * dbi);
/* Other Generally needed Functions */
#ifndef WIN32
static void daemonize(void);
#endif
static void log_entry(const char *logentry, int level);
#ifdef WIN32
/* Windows Service related functions */
static void ControlHandler(DWORD request);
static int InstallService();
static int RemoveService();
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment