aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas G. Lockhart <lockhart@fourpalms.org>1998-11-14 01:58:15 +0000
committerThomas G. Lockhart <lockhart@fourpalms.org>1998-11-14 01:58:15 +0000
commit9f07f8f40f787037f393a727ecf51d5883dbf7ca (patch)
tree19e2ef85147ffbcb1afc080b0cf6208ad1d52982 /src
parent69ff5b9c7e6296d879d1f338464a420e89a69bcd (diff)
downloadpostgresql-9f07f8f40f787037f393a727ecf51d5883dbf7ca.tar.gz
postgresql-9f07f8f40f787037f393a727ecf51d5883dbf7ca.zip
Add "vacuumdb" utility to make it easier to clean databases.
Also supports the "analyze" mode, with or without specifying tables and columns.
Diffstat (limited to 'src')
-rw-r--r--src/bin/vacuumdb/Makefile24
-rw-r--r--src/bin/vacuumdb/vacuumdb98
2 files changed, 122 insertions, 0 deletions
diff --git a/src/bin/vacuumdb/Makefile b/src/bin/vacuumdb/Makefile
new file mode 100644
index 00000000000..98ab129e891
--- /dev/null
+++ b/src/bin/vacuumdb/Makefile
@@ -0,0 +1,24 @@
+#-------------------------------------------------------------------------
+#
+# Makefile--
+# Makefile for bin/vacuumdb
+#
+# Copyright (c) 1994, Regents of the University of California
+#
+#
+# IDENTIFICATION
+# $Header: /cvsroot/pgsql/src/bin/vacuumdb/Attic/Makefile,v 1.1 1998/11/14 01:58:14 thomas Exp $
+#
+#-------------------------------------------------------------------------
+
+SRCDIR= ../..
+include ../../Makefile.global
+
+all: vacuumdb
+
+install: vacuumdb
+ $(INSTALL) $(INSTL_EXE_OPTS) $< $(BINDIR)/$<
+
+clean:
+
+dep depend:
diff --git a/src/bin/vacuumdb/vacuumdb b/src/bin/vacuumdb/vacuumdb
new file mode 100644
index 00000000000..dc9ec366513
--- /dev/null
+++ b/src/bin/vacuumdb/vacuumdb
@@ -0,0 +1,98 @@
+#!/bin/sh
+#-------------------------------------------------------------------------
+#
+# vacuumdb--
+# vacuum a postgres database
+#
+# this program runs the monitor with the "-c" option to vacuum
+# the requested database.
+#
+# Copyright (c) 1994, Regents of the University of California
+#
+#
+# IDENTIFICATION
+# $Header: /cvsroot/pgsql/src/bin/vacuumdb/Attic/vacuumdb,v 1.1 1998/11/14 01:58:15 thomas Exp $
+#
+#-------------------------------------------------------------------------
+
+CMDNAME=`basename $0`
+
+if [ -z "$USER" ]; then
+ if [ -z "$LOGNAME" ]; then
+ if [ -z "`whoami`" ]; then
+ echo "$CMDNAME: cannot determine user name"
+ exit 1
+ fi
+ else
+ USER=$LOGNAME
+ export USER
+ fi
+fi
+
+dbname=$USER
+
+PASSWDOPT="";
+
+while test -n "$1"
+do
+ case $1 in
+ --help) usage=1;;
+ --analyze) analyze="analyze";;
+ --table) table=$2; shift;;
+ --verbose) verbose="verbose";;
+
+ -a) AUTHSYS=$2; shift;;
+ -h) PGHOST=$2; shift;;
+ -p) PGPORT=$2; shift;;
+ -t) table=$2; shift;;
+ -u) PASSWDOPT=$1;;
+ -v) verbose="verbose";;
+ -z) analyze="analyze";;
+ -*) echo "$CMDNAME: unrecognized parameter $1"; usage=1;;
+ *) dbname=$1;;
+ esac
+ shift;
+done
+
+if [ "$usage" ]; then
+ echo "Usage: $CMDNAME -a <authtype> -h <server> -p <portnumber> --analyze --verbose [--table 'table[(cols)]'] [dbname]"
+ exit 1
+fi
+
+if [ -z "$AUTHSYS" ]; then
+ AUTHOPT=""
+else
+ AUTHOPT="-a $AUTHSYS"
+fi
+
+if [ -z "$PGHOST" ]; then
+ PGHOSTOPT=""
+else
+ PGHOSTOPT="-h $PGHOST"
+fi
+
+if [ -z "$PGPORT" ]; then
+ PGPORTOPT=""
+else
+ PGPORTOPT="-p $PGPORT"
+fi
+
+if [ -z "$dbpath" ]; then
+ location=""
+else
+# if [ ! -d "$dbpath"/base ]; then
+# echo "$CMDNAME: database creation failed on $dbname."
+# echo "directory $dbpath/base not found."
+# exit 1
+# fi
+ location="with location = '$dbpath'"
+fi
+
+psql $PASSWDOPT -tq $AUTHOPT $PGHOSTOPT $PGPORTOPT -c "vacuum $verbose $analyze $table" $dbname
+
+if [ $? -ne 0 ]; then
+ echo "$CMDNAME: database vacuum failed on $dbname."
+ exit 1
+fi
+
+exit 0