1- /* pg_autovacuum.hszCmdline
1+ /* pg_autovacuum.h
22 * Header file for pg_autovacuum.c
33 * (c) 2003 Matthew T. O'Connor
4+ *
5+ * $PostgreSQL: pgsql/contrib/pg_autovacuum/pg_autovacuum.h,v 1.12 2004/10/16 21:50:02 tgl Exp $
46 */
57
6- #define FRONTEND
8+ #ifndef _PG_AUTOVACUUM_H
9+ #define _PG_AUTOVACUUM_H
710
8- #include "postgres_fe.h"
9-
10- #include <unistd.h>
11- #ifdef HAVE_GETOPT_H
12- #include <getopt.h>
13- #endif
14- #include <time.h>
15- #include <sys/time.h>
16-
17- /* These next two lines are correct when pg_autovaccum is compiled
18- from within the postgresql source tree */
1911#include "libpq-fe.h"
2012#include "lib/dllist.h"
21- /* Had to change the last two lines to compile on
22- Redhat outside of postgresql source tree */
23- /*
24- #include "/usr/include/libpq-fe.h"
25- #include "/usr/include/pgsql/server/lib/dllist.h"
26- */
2713
2814#define AUTOVACUUM_DEBUG 0
2915#define VACBASETHRESHOLD 1000
4329#define FROZENOID_QUERY "select oid,age(datfrozenxid) from pg_database where datname = 'template1'"
4430#define FROZENOID_QUERY2 "select oid,datname,age(datfrozenxid) from pg_database where datname!='template0'"
4531
46- /* define atooid */
47- #define atooid (x ) ((Oid) strtoul((x), NULL, 10))
48-
4932/* Log levels */
5033enum
5134{
5740};
5841
5942/* define cmd_args stucture */
60- struct cmdargs
43+ typedef struct cmdargs
6144{
6245int vacuum_base_threshold ,
6346analyze_base_threshold ,
@@ -81,16 +64,13 @@ struct cmdargs
8164* host ,
8265* logfile ,
8366* port ;
84- };
85- typedef struct cmdargs cmd_args ;
67+ }cmd_args ;
8668
87-
88- /* define cmd_args as global so we can get to them everywhere */
89- cmd_args * args ;
90-
91- /* Might need to add a time value for last time the whold database was vacuumed.
92- I think we need to guarantee this happens approx every 1Million TX's */
93- struct dbinfo
69+ /*
70+ * Might need to add a time value for last time the whole database was
71+ * vacuumed. We need to guarantee this happens approx every 1Billion TX's
72+ */
73+ typedef struct dbinfo
9474{
9575Oid oid ;
9676long age ;
@@ -102,10 +82,9 @@ struct dbinfo
10282* username ,
10383* password ;
10484Dllist * table_list ;
105- };
106- typedef struct dbinfo db_info ;
85+ }db_info ;
10786
108- struct tableinfo
87+ typedef struct tableinfo
10988{
11089char * schema_name ,
11190* table_name ;
@@ -125,53 +104,6 @@ struct tableinfo
125104curr_vacuum_count ;/* Latest values from stats system */
126105db_info * dbi ;/* pointer to the database that this table
127106 * belongs to */
128- };
129- typedef struct tableinfo tbl_info ;
107+ }tbl_info ;
130108
131- /* The main program loop function */
132- static int VacuumLoop (int argc ,char * * argv );
133-
134- /* Functions for dealing with command line arguements */
135- static cmd_args * get_cmd_args (int argc ,char * argv []);
136- static void print_cmd_args (void );
137- static void free_cmd_args (void );
138- static void usage (void );
139-
140- /* Functions for managing database lists */
141- static Dllist * init_db_list (void );
142- static db_info * init_dbinfo (char * dbname ,Oid oid ,long age );
143- static void update_db_list (Dllist * db_list );
144- static void remove_db_from_list (Dlelem * db_to_remove );
145- static void print_db_info (db_info * dbi ,int print_table_list );
146- static void print_db_list (Dllist * db_list ,int print_table_lists );
147- static int xid_wraparound_check (db_info * dbi );
148- static void free_db_list (Dllist * db_list );
149-
150- /* Functions for managing table lists */
151- static tbl_info * init_table_info (PGresult * conn ,int row ,db_info * dbi );
152- static void update_table_list (db_info * dbi );
153- static void remove_table_from_list (Dlelem * tbl_to_remove );
154- static void print_table_list (Dllist * tbl_node );
155- static void print_table_info (tbl_info * tbl );
156- static void update_table_thresholds (db_info * dbi ,tbl_info * tbl ,int vacuum_type );
157- static void free_tbl_list (Dllist * tbl_list );
158-
159- /* A few database helper functions */
160- static int check_stats_enabled (db_info * dbi );
161- static PGconn * db_connect (db_info * dbi );
162- static void db_disconnect (db_info * dbi );
163- static PGresult * send_query (const char * query ,db_info * dbi );
164-
165- /* Other Generally needed Functions */
166- #ifndef WIN32
167- static void daemonize (void );
168- #endif
169- static void log_entry (const char * logentry ,int level );
170-
171- #ifdef WIN32
172- /* Windows Service related functions */
173- static void ControlHandler (DWORD request );
174- static int InstallService ();
175- static int RemoveService ();
176-
177- #endif
109+ #endif /* _PG_AUTOVACUUM_H */