|
| 1 | +#!/bin/sh |
| 2 | +#------------------------------------------------------------------------- |
| 3 | +# |
| 4 | +# vacuumdb-- |
| 5 | +# vacuum a postgres database |
| 6 | +# |
| 7 | +# this program runs the monitor with the "-c" option to vacuum |
| 8 | +# the requested database. |
| 9 | +# |
| 10 | +# Copyright (c) 1994, Regents of the University of California |
| 11 | +# |
| 12 | +# |
| 13 | +# IDENTIFICATION |
| 14 | +# $Header: /cvsroot/pgsql/src/bin/vacuumdb/Attic/vacuumdb,v 1.1 1998/11/14 01:58:15 thomas Exp $ |
| 15 | +# |
| 16 | +#------------------------------------------------------------------------- |
| 17 | + |
| 18 | +CMDNAME=`basename $0` |
| 19 | + |
| 20 | +if [ -z "$USER" ]; then |
| 21 | + if [ -z "$LOGNAME" ]; then |
| 22 | + if [ -z "`whoami`" ]; then |
| 23 | + echo "$CMDNAME: cannot determine user name" |
| 24 | + exit 1 |
| 25 | + fi |
| 26 | + else |
| 27 | + USER=$LOGNAME |
| 28 | + export USER |
| 29 | + fi |
| 30 | +fi |
| 31 | + |
| 32 | +dbname=$USER |
| 33 | + |
| 34 | +PASSWDOPT=""; |
| 35 | + |
| 36 | +while test -n "$1" |
| 37 | +do |
| 38 | + case $1 in |
| 39 | + --help) usage=1;; |
| 40 | + --analyze) analyze="analyze";; |
| 41 | + --table) table=$2; shift;; |
| 42 | + --verbose) verbose="verbose";; |
| 43 | + |
| 44 | + -a) AUTHSYS=$2; shift;; |
| 45 | + -h) PGHOST=$2; shift;; |
| 46 | + -p) PGPORT=$2; shift;; |
| 47 | + -t) table=$2; shift;; |
| 48 | + -u) PASSWDOPT=$1;; |
| 49 | + -v) verbose="verbose";; |
| 50 | + -z) analyze="analyze";; |
| 51 | + -*) echo "$CMDNAME: unrecognized parameter $1"; usage=1;; |
| 52 | + *) dbname=$1;; |
| 53 | + esac |
| 54 | + shift; |
| 55 | +done |
| 56 | + |
| 57 | +if [ "$usage" ]; then |
| 58 | + echo "Usage: $CMDNAME -a <authtype> -h <server> -p <portnumber> --analyze --verbose [--table 'table[(cols)]'] [dbname]" |
| 59 | + exit 1 |
| 60 | +fi |
| 61 | + |
| 62 | +if [ -z "$AUTHSYS" ]; then |
| 63 | + AUTHOPT="" |
| 64 | +else |
| 65 | + AUTHOPT="-a $AUTHSYS" |
| 66 | +fi |
| 67 | + |
| 68 | +if [ -z "$PGHOST" ]; then |
| 69 | + PGHOSTOPT="" |
| 70 | +else |
| 71 | + PGHOSTOPT="-h $PGHOST" |
| 72 | +fi |
| 73 | + |
| 74 | +if [ -z "$PGPORT" ]; then |
| 75 | + PGPORTOPT="" |
| 76 | +else |
| 77 | + PGPORTOPT="-p $PGPORT" |
| 78 | +fi |
| 79 | + |
| 80 | +if [ -z "$dbpath" ]; then |
| 81 | + location="" |
| 82 | +else |
| 83 | +# if [ ! -d "$dbpath"/base ]; then |
| 84 | +# echo "$CMDNAME: database creation failed on $dbname." |
| 85 | +# echo "directory $dbpath/base not found." |
| 86 | +# exit 1 |
| 87 | +# fi |
| 88 | + location="with location = '$dbpath'" |
| 89 | +fi |
| 90 | + |
| 91 | +psql $PASSWDOPT -tq $AUTHOPT $PGHOSTOPT $PGPORTOPT -c "vacuum $verbose $analyze $table" $dbname |
| 92 | + |
| 93 | +if [ $? -ne 0 ]; then |
| 94 | + echo "$CMDNAME: database vacuum failed on $dbname." |
| 95 | + exit 1 |
| 96 | +fi |
| 97 | + |
| 98 | +exit 0 |
0 commit comments