Skip to content

Commit b3d58ea

Browse files
committed
Include dllist.c directly instead of assuming that libpq will provide it.
Whack some semblance of project-conventions-conformance into pg_autovacuum.h.
1 parent dc19aaa commit b3d58ea

File tree

3 files changed

+92
-89
lines changed

3 files changed

+92
-89
lines changed

contrib/pg_autovacuum/Makefile

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
PROGRAM = pg_autovacuum
2-
OBJS = pg_autovacuum.o
2+
OBJS = pg_autovacuum.o dllist.o
33

4-
PG_CPPFLAGS = -I$(libpq_srcdir)
4+
PG_CPPFLAGS = -I$(libpq_srcdir) -DFRONTEND
55
PG_LIBS = $(libpq)
66

77
DOCS = README.pg_autovacuum
88

9+
EXTRA_CLEAN = dllist.c
10+
911
ifdef USE_PGXS
1012
PGXS = $(shell pg_config --pgxs)
1113
include $(PGXS)
@@ -15,3 +17,6 @@ top_builddir = ../..
1517
include $(top_builddir)/src/Makefile.global
1618
include $(top_srcdir)/contrib/contrib-global.mk
1719
endif
20+
21+
dllist.c: $(top_srcdir)/src/backend/lib/dllist.c
22+
rm -f $@ && $(LN_S) $< .

contrib/pg_autovacuum/pg_autovacuum.c

Lines changed: 69 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,88 @@
33
* (c) 2003 Matthew T. O'Connor
44
* Revisions by Christopher B. Browne, Liberty RMS
55
* Win32 Service code added by Dave Page
6+
*
7+
* $PostgreSQL: pgsql/contrib/pg_autovacuum/pg_autovacuum.c,v 1.22 2004/10/16 21:50:02 tgl Exp $
68
*/
79

8-
#include "pg_autovacuum.h"
10+
#include "postgres_fe.h"
911

12+
#include <unistd.h>
13+
#ifdef HAVE_GETOPT_H
14+
#include <getopt.h>
15+
#endif
16+
#include <time.h>
17+
#include <sys/time.h>
1018
#ifdef WIN32
1119
#include <windows.h>
20+
#endif
1221

22+
#include "pg_autovacuum.h"
23+
24+
#ifdef WIN32
1325
unsigned int sleep();
1426

1527
SERVICE_STATUS ServiceStatus;
1628
SERVICE_STATUS_HANDLE hStatus;
1729
int appMode = 0;
1830
#endif
1931

20-
FILE *LOGOUTPUT;
21-
char logbuffer[4096];
32+
/* define atooid */
33+
#define atooid(x) ((Oid) strtoul((x), NULL, 10))
34+
35+
36+
static cmd_args *args;
37+
static FILE *LOGOUTPUT;
38+
static char logbuffer[4096];
39+
40+
41+
/* The main program loop function */
42+
static int VacuumLoop(int argc, char **argv);
43+
44+
/* Functions for dealing with command line arguements */
45+
static cmd_args *get_cmd_args(int argc, char *argv[]);
46+
static void print_cmd_args(void);
47+
static void free_cmd_args(void);
48+
static void usage(void);
49+
50+
/* Functions for managing database lists */
51+
static Dllist *init_db_list(void);
52+
static db_info *init_dbinfo(char *dbname, Oid oid, long age);
53+
static void update_db_list(Dllist *db_list);
54+
static void remove_db_from_list(Dlelem *db_to_remove);
55+
static void print_db_info(db_info * dbi, int print_table_list);
56+
static void print_db_list(Dllist *db_list, int print_table_lists);
57+
static int xid_wraparound_check(db_info * dbi);
58+
static void free_db_list(Dllist *db_list);
59+
60+
/* Functions for managing table lists */
61+
static tbl_info *init_table_info(PGresult *conn, int row, db_info * dbi);
62+
static void update_table_list(db_info * dbi);
63+
static void remove_table_from_list(Dlelem *tbl_to_remove);
64+
static void print_table_list(Dllist *tbl_node);
65+
static void print_table_info(tbl_info * tbl);
66+
static void update_table_thresholds(db_info * dbi, tbl_info * tbl, int vacuum_type);
67+
static void free_tbl_list(Dllist *tbl_list);
68+
69+
/* A few database helper functions */
70+
static int check_stats_enabled(db_info * dbi);
71+
static PGconn *db_connect(db_info * dbi);
72+
static void db_disconnect(db_info * dbi);
73+
static PGresult *send_query(const char *query, db_info * dbi);
74+
75+
/* Other Generally needed Functions */
76+
#ifndef WIN32
77+
static void daemonize(void);
78+
#endif
79+
static void log_entry(const char *logentry, int level);
80+
81+
#ifdef WIN32
82+
/* Windows Service related functions */
83+
static void ControlHandler(DWORD request);
84+
static int InstallService();
85+
static int RemoveService();
86+
#endif
87+
2288

2389
static void
2490
log_entry(const char *logentry, int level)

contrib/pg_autovacuum/pg_autovacuum.h

Lines changed: 16 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,15 @@
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
@@ -43,9 +29,6 @@
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 */
5033
enum
5134
{
@@ -57,7 +40,7 @@ enum
5740
};
5841

5942
/* define cmd_args stucture */
60-
struct cmdargs
43+
typedef struct cmdargs
6144
{
6245
int vacuum_base_threshold,
6346
analyze_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
{
9575
Oid oid;
9676
long age;
@@ -102,10 +82,9 @@ struct dbinfo
10282
*username,
10383
*password;
10484
Dllist *table_list;
105-
};
106-
typedef struct dbinfo db_info;
85+
} db_info;
10786

108-
struct tableinfo
87+
typedef struct tableinfo
10988
{
11089
char *schema_name,
11190
*table_name;
@@ -125,53 +104,6 @@ struct tableinfo
125104
curr_vacuum_count; /* Latest values from stats system */
126105
db_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 */

0 commit comments

Comments
 (0)