Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit bd18c50

Browse files
committed
I have updated my pg_autovacuum program (formerly pg_avd, the name
changed as per discussion on the patches list). This version should be a good bit better. It addresses all the issues pointed out by Neil Conway. Vacuum and Analyze are now handled separately. It now monitors for xid wraparound. The number of database connections and queries has been significantly reduced compared the previous version. I have moved it from bin to contrib. More detail on the changes are in the TODO file. I have not tested the xid wraparound code as I have to let my AthlonXP 1600 run select 1 in a tight loop for approx. two days in order to perform the required 500,000,000 xacts. Matthew T. O'Connor
1 parent 41d1738 commit bd18c50

File tree

7 files changed

+955
-1
lines changed

7 files changed

+955
-1
lines changed

contrib/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Header: /cvsroot/pgsql/contrib/Makefile,v 1.40 2002/10/21 00:12:46 momjian Exp $
1+
# $Header: /cvsroot/pgsql/contrib/Makefile,v 1.41 2003/03/20 18:14:46 momjian Exp $
22

33
subdir = contrib
44
top_builddir = ..
@@ -25,6 +25,7 @@ WANTED_DIRS = \
2525
miscutil \
2626
noupdate \
2727
oid2name \
28+
pg_autovacuum \
2829
pg_dumplo \
2930
pg_logger \
3031
pgbench \

contrib/README

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,10 @@ oracle -
132132
Converts Oracle database schema to PostgreSQL
133133
by Gilles Darold <gilles@darold.net>
134134

135+
pg_autovacuum -
136+
Automatically performs vacuum
137+
by Matthew T. O'Connor <matthew@zeut.net>
138+
135139
pg_dumplo -
136140
Dump large objects
137141
by Karel Zak <zakkr@zf.jcu.cz>

contrib/pg_autovacuum/Makefile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
subdir = contrib/pg_autovacuum
3+
top_builddir = ../..
4+
include $(top_builddir)/src/Makefile.global
5+
6+
PROGRAM = pg_autovacuum
7+
OBJS = pg_autovacuum.o
8+
9+
PG_CPPFLAGS = -I$(libpq_srcdir)
10+
PG_LIBS = $(libpq)
11+
12+
DOCS = README.pg_autovacuum
13+
14+
include $(top_srcdir)/contrib/contrib-global.mk

contrib/pg_autovacuum/README

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
pg_autovacuum README
2+
3+
pg_autovacuum is a libpq client program that monitors all the databases of a
4+
postgresql server. It uses the stats collector to monitor insert, update and
5+
delete activity. When an individual table exceeds it's insert or delete
6+
threshold (more detail on thresholds below) then that table is vacuumed or
7+
analyzed. This allows postgresql to keep the fsm and table statistics up to
8+
date without having to schedule periodic vacuums with cron regardless of need.
9+
10+
The primary benefit of pg_autovacuum is that the FSM and table statistic information
11+
are updated as needed. When a table is actively changed pg_autovacuum performs the
12+
necessary vacuums and analyzes, when a table is inactive, no cycles are wasted
13+
performing vacuums and analyzes that are not needed.
14+
15+
A secondary benefit of pg_autovacuum is that it guarantees that a database wide
16+
vacuum is performed prior to xid wraparound. This is important as failing to do
17+
so can result in major data loss.
18+
19+
INSTALL:
20+
To use pg_autovacuum, uncompress the tar.gz into the contrib directory and modify the
21+
contrib/Makefile to include the pg_autovacuum directory. pg_autovacuum will then be made as
22+
part of the standard postgresql install.
23+
24+
make sure that the folowing are set in postgresql.conf
25+
stats_start_collector = true
26+
stats_row_level = true
27+
28+
start up the postmaster
29+
then, just execute the pg_autovacuum executable.
30+
31+
32+
Command line arguments:
33+
pg_autovacuum has the following optional arguments:
34+
-d debug: 0 silent, 1 basic info, 2 more debug info, etc...
35+
-s sleep base value: see "Sleeping" below.
36+
-S sleep scaling factor: see "Sleeping" below.
37+
-t tuple base threshold: see Vacuuming.
38+
-T tuple scaling factor: see Vacuuming.
39+
-U username: Username pg_autovacuum will use to connect with, if not specified the
40+
current username is used
41+
-P password: Password pg_autovacuum will use to connect with.
42+
-H host: host name or IP to connect too.
43+
-p port: port used for connection.
44+
-h help: list of command line options.
45+
46+
All arguments have default values defined in pg_autovacuum.h. At the time of this
47+
writing they are:
48+
#define AUTOVACUUM_DEBUG 1
49+
#define BASETHRESHOLD 100
50+
#define SCALINGFACTOR 2
51+
#define SLEEPVALUE 3
52+
#define SLEEPSCALINGFACTOR 2
53+
#define UPDATE_INTERVAL 2
54+
55+
56+
Vacuum and Analyze:
57+
pg_autovacuum performes either a vacuums analyze or just analyze depending on the table activity.
58+
If the number of (inserts + updates) > insertThreshold, then an only an analyze is performed.
59+
If the number of (deletes + updates ) > deleteThreshold, then a vacuum analyze is performed.
60+
deleteThreshold is equal to: tuple_base_value + (tuple_scaling_factor * "number of tuples in the table")
61+
insertThreshold is equal to: 0.5 * tuple_base_value + (tuple_scaling_factor * "number of tuples in the table")
62+
The insertThreshold is half the deleteThreshold because it's a much lighter operation (approx 5%-10% of vacuum),
63+
so running it more often costs us little in performance degredation.
64+
65+
Sleeping:
66+
pg_autovacuum sleeps after it is done checking all the databases. It does this so as
67+
to limit the amount of system resources it consumes. This also allows the system
68+
administrator to configure pg_autovacuum to be more or less aggressive. Reducing the
69+
sleep time will cause pg_autovacuum to respond more quickly to changes, be they database
70+
addition / removal, table addition / removal, or just normal table activity. However,
71+
setting these values to high can have a negative net effect on the server. If a table
72+
gets vacuumed 5 times during the course of a large update, it might take much longer
73+
than if it was vacuumed only once.
74+
The total time it sleeps is equal to:
75+
base_sleep_value + sleep_scaling_factor * "duration of the previous loop"
76+
77+
What it monitors:
78+
pg_autovacuum dynamically generates a list of databases and tables to monitor, in
79+
addition it will dynamically add and remove databases and tables that are
80+
removed from the database server while pg_autovacuum is running.

contrib/pg_autovacuum/TODO

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
Todo Items for pg_autovacuum client
2+
3+
_Allow it to detach from the tty
4+
5+
_create a FSM export function and see if I can use it for pg_autovacuum
6+
7+
_look into possible benifits of pgstattuple contrib work
8+
9+
_Continue trying to reduce server load created by polling.
10+
11+
Done:
12+
_Check if required pg_stats are enables, if not exit with error
13+
14+
_Reduce the number connections and queries to the server
15+
_Make database adding and removal part of the normal loop
16+
_make table adding and removal part of the normal loop
17+
18+
_Separate logic for vacuum and analyze
19+
20+
_all pg_autovacuum specific functions are now static
21+
22+
_correct usage of snprintf
23+
24+
_reworked database and table update functions, now they
25+
use the existing database connection and only one query
26+
27+
_fixed -h option output
28+
29+
_cleanup of 'constant == variable' used much more consistently now.
30+
31+
_Guarantee database wide vacuum prior to Xid wraparound
32+
33+
_change name to pg_autovacuum
34+
35+
_Add proper table and database removal functions so that we can properly
36+
clear up before we exit, and make sure we don't leak memory when removing tables and such.

0 commit comments

Comments
 (0)