vacuumdb
上传用户:blenddy
上传日期:2007-01-07
资源大小:6495k
文件大小:2k
源码类别:

数据库系统

开发平台:

Unix_Linux

  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: /usr/local/cvsroot/pgsql/src/bin/vacuumdb/vacuumdb,v 1.1 1998/11/14 01:58:15 thomas Exp $
  15. #
  16. #-------------------------------------------------------------------------
  17. CMDNAME=`basename $0`
  18. if [ -z "$USER" ]; then
  19. if [ -z "$LOGNAME" ]; then
  20. if [ -z "`whoami`" ]; then
  21. echo "$CMDNAME: cannot determine user name"
  22. exit 1
  23. fi
  24. else
  25. USER=$LOGNAME
  26. export USER
  27. fi
  28. fi
  29. dbname=$USER
  30. PASSWDOPT="";
  31. while test -n "$1"
  32. do
  33. case $1 in
  34. --help) usage=1;;
  35. --analyze) analyze="analyze";;
  36. --table) table=$2; shift;;
  37. --verbose) verbose="verbose";;
  38. -a) AUTHSYS=$2; shift;;
  39. -h) PGHOST=$2; shift;;
  40. -p) PGPORT=$2; shift;;
  41. -t) table=$2; shift;;
  42. -u) PASSWDOPT=$1;;
  43. -v) verbose="verbose";;
  44. -z) analyze="analyze";;
  45. -*) echo "$CMDNAME: unrecognized parameter $1"; usage=1;;
  46.  *) dbname=$1;;
  47. esac
  48. shift;
  49. done
  50. if [ "$usage" ]; then
  51. echo "Usage: $CMDNAME -a <authtype> -h <server> -p <portnumber> --analyze --verbose [--table 'table[(cols)]'] [dbname]"
  52. exit 1
  53. fi
  54. if [ -z "$AUTHSYS" ]; then
  55. AUTHOPT=""
  56. else
  57. AUTHOPT="-a $AUTHSYS"
  58. fi
  59. if [ -z "$PGHOST" ]; then
  60. PGHOSTOPT=""
  61. else
  62. PGHOSTOPT="-h $PGHOST"
  63. fi
  64. if [ -z "$PGPORT" ]; then
  65. PGPORTOPT=""
  66. else
  67. PGPORTOPT="-p $PGPORT"
  68. fi
  69. if [ -z "$dbpath" ]; then
  70. location=""
  71. else
  72. # if [ ! -d "$dbpath"/base ]; then
  73. # echo "$CMDNAME: database creation failed on $dbname."
  74. # echo "directory $dbpath/base not found."
  75. # exit 1
  76. # fi
  77. location="with location = '$dbpath'"
  78. fi
  79. psql $PASSWDOPT -tq $AUTHOPT $PGHOSTOPT $PGPORTOPT -c "vacuum $verbose $analyze $table" $dbname
  80. if [ $? -ne 0 ]; then
  81. echo "$CMDNAME: database vacuum failed on $dbname."
  82. exit 1
  83. fi
  84. exit 0