Create a database by typing
-$ createdb
+$ createdb test
Connect to the new database:
-$ psql
+$ psql test
Remove the test database (unless you will want to use it later for other tests):
-$ destroydb
+$ dropdb test
After running the regression tests, type
-$ destroydb regression
+$ dropdb regression
$ cd /usr/src/pgsql/postgresql-6.5.3/src/test/regress
$ gmake clean
template1=> create database foo;
-CREATEDB
+CREATE DATABASE
(Get in the habit of including those SQL semicolons. Psql won't execute
mydb, you can destroy it using the following Unix command:
-% destroydb dbname
+% dropdb dbname
This action physically removes all of the Unix files
If you are the database administrator for the database
mydb, you can destroy it using the following Unix command:
-% destroydb mydb
+% dropdb mydb
This action physically removes all of the Unix files
associated with the database and cannot be undone, so
- -D, --dbpath datadir
+ -D, --location datadir
Specifies the alternate database location for this database installation.
Specifies the name of the database to be created. The name must be
- unique among all
Postgres databases in this installation.
+ unique among all
PostgreSQL databases in this installation.
- createdb: Comment creation failed.
+ createdb: Comment creation failed. (Database was created.)
The comment/description for the database could not be created.
To create the database demo
using the postmaster on host eden, port 5000, using the LATIN1
- encoding scheme and look at the underlying query:
+ encoding scheme with a look at the underlying query:
$ createdb -p 5000 -h eden -E LATIN1 -e demo
-QUERY: CREATE DATABASE "demo" WITH ENCODING = 'LATIN1'
+CREATE DATABASE "demo" WITH ENCODING = 'LATIN1'
CREATE DATABASE
+
+ -i, --sysid uid
+
+ Allows you to pick a non-default user id for the new user. This is not
+ necessary, but some people like it.
+
+
+
+
username
The options -h, -p, and -e,
- are passed on literally to . If you
- need the
psql options
-U and
- -W as well, you can uncomment the
- respective lines in the source. They are disabled by default because of the potential
- conceptual confusion between existing and new users.
+ are passed on literally to . The
+ are available as well, but their use can be confusing in this context.
$ createuser -p 5000 -h eden -D -A -e joe
-QUERY: CREATE USER "joe" NOCREATEDB NOCREATEUSER
+CREATE USER "joe" NOCREATEDB NOCREATEUSER
CREATE USER
user from the database,
along with any databases owned by the user. It
does not remove tables, views, or triggers owned by the
- named user in databases not owned by the user. This statement
- can be used in place of the
dropuser
- script, regardless of how the user was created.
+ named user in databases not owned by the user.
$ dropdb -p 5000 -h eden -i -e demo
Database "demo" will be permanently deleted.
Are you sure? (y/n) y
-QUERY: DROP DATABASE "demo"
+DROP DATABASE "demo"
DROP DATABASE
The options -h, -p, and -e,
- are passed on literally to . If you
- need the
psql options
-U and
- -W as well, you can uncomment the
- respective lines in the source. They are disabled by default because of the potential
- conceptual confusion between existing and new users.
+ are passed on literally to . The
+ are available as well, but they can be confusing in this context.
$ dropuser -p 5000 -h eden -i -e joe
User "joe" and any owned databases will be permanently deleted.
Are you sure? (y/n) y
-QUERY: DROP USER "joe"
+DROP USER "joe"
DROP USER
VACUUM [ VERBOSE ] [ ANALYZE ] [ table ]
-VACUUM [ VERBOSE ] ANALYZE [ ER">tBLE> [ (column [, ...] ) ] ]
+VACUUM [ VERBOSE ] ANALYZE [ table> [ (column [, ...] ) ] ]
- Clean and analyze a
Postgres database
+ Clean and analyze a
PostgreSQL database
- 1998-10-04
+ 1999-12-04
-vacuumdb [ --analyze | -z ] [ --verbose | -v ] [ dbname ]
-vacuumdb [ -h host ] [ -p port ]
- [ --table 'table [ ( column [,...] ) ]' ]
- [ dbname ]
+vacuumdb [ connection options ] [ --analyze | -z ] [ --verbose | -v ]
+ [ --table 'table [ ( column [,...] ) ]' ] [ [-d] dbname ]
- 1998-10-04
+ 1999-12-04
Inputs
- dbname
+ [-d, --dbname] dbname
Specifies the name of the database to be cleaned or analyzed.
- dbname
- defaults to the value of the
- USER
- environment variable.
- --analyze
- -z
+ -z, --analyze
Calculate statistics on the database for use by the optimizer.
- --verbose
- -v
+ -v, --verbose
Print detailed information during processing.
- --table table [ (column [,...]) ]
- -t table [ (column [,...]) ]
+ -t, --table table [ (column [,...]) ]
Clean or analyze table only.
Column names may be specified only in conjunction with
the option.
+
+ If you specify columns to vacuum, you probably have to escape the parentheses
+ from the shell.
+
+
- -h host
+ -h, --host host
Specifies the hostname of the machine on which the
- is running. Defaults to using a local Unix domain socket
- rather than an IP connection..
+ is running.
- -p port
+ -p, --port port
Specifies the Internet TCP/IP port or local Unix domain socket file
extension on which the
postmaster
- is listening for connections. The port number defaults to 5432,
- or the value of the PGPORT
- environment variable (if set).
+ is listening for connections.
+
+
+
+
+
+ -U, --username username
+
+ Username to connect as.
+
+
+
+
+
+ -W, --password
+
+ Force password prompt.
+
+
+
+
+
+ -e, --echo
+
+ Echo the commands that
vacuumdb generates
+ and sends to the backend.
- -u
+ -q, --quiet
- Use password authentication.
- Prompts for
- username
- and password.
+ Do not display a response.
- 1998-10-04
+ 1999-12-04
Outputs
-
vacuumdb executes a
VACUUM command
- on the specified database, so has not explicit external output.
-
-
-ERROR: Can't vacuum columns, only tables. You can 'vacuum analyze' columns.
-vacuumdb: database vacuum failed on dbname.
-
+ VACUUM
- The non-analyze mode requires cleaning full tables or databases.
- Individual columns may be specified only when analyzing a specific table.
+ Everything went well.
-
-Connection to database 'template1' failed.
-connectDB() failed: Is the postmaster running and accepting connections
-at 'UNIX Socket' on port 'port'?
-
+ vacuumdb: Vacuum failed.
-
vacuumdb could not attach to the
- process on the specified host and port. If you see this message,
- ensure that the
postmaster
- is running on the proper host and that you have specified the proper
- port. If your site uses an authentication system, ensure that you
- have obtained the required authentication credentials.
+ Something went wrong.
vacuumdb is only a wrapper
+ script. See
+ and for a detailed
+ discussion of error messages and potential problems.
-
-
-Connection to database 'dbname' failed.
-FATAL 1: SetUserId: user 'username' is not in 'pg_shadow'
-
-
- You do not have a valid entry in the relation pg_shadow
- and and will not be allowed to access
Postgres.
- Contact your
Postgres administrator.
-
-
-
-
-
vacuumdb internally executes a
- If you have problems running
vacuumdb,
- make sure you are able to run VACUUM on the database using, for
-
-
+
+
- 1998-10-04
+ 1999-12-04
Description
vacuumdb is a utility for cleaning a
vacuumdb will also generate internal statistics
used by the
Postgres query optimizer.
-
-
-
-
- 1998-10-04
-
-
- Notes
-
- See for more details.
+
vacuumdb is a shell script wrapper around the
+ backend command
+ via
+ the
PostgreSQL interactive terminal
+ . There is no effective
+ difference between vacuuming databases via this or other methods.
+
psql must be found by the script and
+ a database server must be running at the targeted host. Also, any default
+ settings and environment variables available to
psql
+ and the
libpq front-end library do apply.
+
-
+
1998-10-04
Usage
+
- To clean a database of the same name as the user:
-
-% vacuumdb
-
+ To clean the database test:
+$ vacuumdb test
+
To analyze a database named bigdb for the optimizer:
-
-% vacuumdb --analyze bigdb
-
+$ vacuumdb --analyze bigdb
+
+
To analyze a single column bar in table foo
in a database named xyzzy for the optimizer:
-
-% vacuumdb --analyze --verbose --table 'foo(bar)' xyzzy
-
+$ vacuumdb --analyze --verbose --table 'foo(bar)' xyzzy
+
+
After running the tests and examining the results, type
- destroydb regression
+ dropdb regression
cd /usr/src/pgsql/src/test/regress
gmake clean
createuser enables specific users to access
-
destroyuser removes users and
+
dropuser removes users and
prevents them from accessing
Postgres.
% createdb -D PGDATA2 test
-% destroydb test
+% dropdb test
If you are the database administrator for the database
mydb, you can destroy it using the following Unix command:
-% destroydb mydb
+% dropdb mydb
This action physically removes all of the Unix files
associated with the database and cannot be undone, so
#!/bin/sh
#-------------------------------------------------------------------------
#
-# createdb.sh--
+# createdb--
# create a postgres database
#
# This program runs psql with the "-c" option to create
#
#
# IDENTIFICATION
-# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/createdb,v 1.1 1999/12/04 04:53:21 momjian Exp $
+# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/createdb,v 1.2 1999/12/07 22:41:44 momjian Exp $
#
#-------------------------------------------------------------------------
PSQLOPT=
dbname=
dbcomment=
+dbpath=
while [ $# -gt 0 ]
do
--host|-h)
PSQLOPT="$PSQLOPT -h $2"
shift;;
+ -h*)
+ PSQLOPT="$PSQLOPT $1"
+ ;;
+ --host=*)
+ PSQLOPT="$PSQLOPT -h "`echo $1 | sed 's/^--host=//'`
+ ;;
--port|-p)
PSQLOPT="$PSQLOPT -p $2"
shift;;
+ -p*)
+ PSQLOPT="$PSQLOPT $1"
+ ;;
+ --port=*)
+ PSQLOPT="$PSQLOPT -p "`echo $1 | sed 's/^--port=//'`
+ ;;
--user|--username|-U)
- PSQLOPT="$PSQLOPT -U $2"
+ PSQLOPT="$PSQLOPT -U '$2'"
shift;;
+ -U*)
+ PSQLOPT="$PSQLOPT $1"
+ ;;
+ --user=*)
+ PSQLOPT="$PSQLOPT -U "`echo $1 | sed 's/^--user=//'`
+ ;;
+ --username=*)
+ PSQLOPT="$PSQLOPT -U "`echo $1 | sed 's/^--username=//'`
+ ;;
--password|-W)
PSQLOPT="$PSQLOPT -W"
;;
PSQLOPT="$PSQLOPT -o /dev/null"
;;
# options converted into SQL command
- --dbpath|-D)
+ --location|-D)
dbpath="$2"
shift;;
+ -D*)
+ dbpath=`echo $1 | sed 's/^-D//'`
+ ;;
+ --location=*)
+ dbpath=`echo $1 | sed 's/^--location=//'`
+ ;;
--encoding|-E)
MB=$2
- shift
- if [ -z `pg_encoding $MB` ]; then
- echo "$CMDNAME: $MB is not a valid encoding name"
- exit 1
- fi
- ;;
-
+ shift;;
+ -E*)
+ MB=`echo $1 | sed 's/^-E//'`
+ ;;
+ --encoding=*)
+ MB=`echo $1 | sed 's/^--encoding=//'`
+ ;;
-*)
echo "$CMDNAME: Unrecognized option: $1. Try -? for help."
exit 1
if [ "$usage" ]; then
- echo "Usage: $CMDNAME [-h
] [-p ] [-D ] \\"
- echo " [-E ] [-U ] [-W] dbname [description]"
+ echo "Usage: $CMDNAME [-h server] [-p port] [-D path] \\"
+ echo " [-E encoding] [-U username] dbname [description]"
exit 0
fi
+
+if [ "$MB" -a -z "`pg_encoding '$MB'`" ]; then
+ echo "$CMDNAME: \"$MB\" is not a valid encoding name."
+ exit 1
+fi
+
if [ -z "$dbname" ]; then
echo "$CMDNAME: Missing required argument database name. Try -? for help."
exit 1
fi
+dbpath=`echo $dbpath | sed "s/'/\\\\\'/g"`
+dbname=`echo $dbname | sed 's/\"/\\\"/g'`
+
withstring=
[ "$dbpath" ] && withstring="$withstring LOCATION = '$dbpath'"
[ "$MB" ] && withstring="$withstring ENCODING = '$MB'"
# Insert comment as well, if requested
[ -z "$dbcomment" ] && exit 0
-psql $PSQLOPT -d template1 -c "COMMENT ON DATABASE \"$dbname\" IS \'$dbcomment\'"
+dbcomment=`echo $dbcomment | sed "s/'/\\\\\'/g"`
+
+psql $PSQLOPT -d template1 -c "COMMENT ON DATABASE \"$dbname\" IS '$dbcomment'"
if [ $? -ne 0 ]; then
- echo "$CMDNAME: Comment creation failed."
+ echo "$CMDNAME: Comment creation failed. (Database was created.)"
exit 1
fi
-exit 0
\ No newline at end of file
+exit 0
#
#
# IDENTIFICATION
-# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/createlang.sh,v 1.1 1999/12/05 20:02:48 momjian Exp $
+# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/createlang.sh,v 1.2 1999/12/07 22:41:44 momjian Exp $
#
#-------------------------------------------------------------------------
#
#
# IDENTIFICATION
-# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/createuser,v 1.2 1999/12/05 20:52:54 momjian Exp $
+# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/createuser,v 1.3 1999/12/07 22:41:44 momjian Exp $
#
# Note - this should NOT be setuid.
#
ECHO_C='\c'
fi
+
while [ $# -gt 0 ]
do
case "$1" in
--host|-h)
PSQLOPT="$PSQLOPT -h $2"
shift;;
+ -h*)
+ PSQLOPT="$PSQLOPT $1"
+ ;;
+ --host=*)
+ PSQLOPT="$PSQLOPT -h "`echo $1 | sed 's/^--host=//'`
+ ;;
--port|-p)
PSQLOPT="$PSQLOPT -p $2"
shift;;
-# Uncomment these lines if you need the -U and -W options.
-# They are confusing in this context, however.
-# --user|--username|-U)
-# PSQLOPT="$PSQLOPT -U $2"
-# shift;;
-# --password|-W)
-# PSQLOPT="$PSQLOPT -W"
-# ;;
+ -p*)
+ PSQLOPT="$PSQLOPT $1"
+ ;;
+ --port=*)
+ PSQLOPT="$PSQLOPT -p "`echo $1 | sed 's/^--port=//'`
+ ;;
+# Note: These two specify the user to connect as (like in psql),
+# not the user you're creating.
+ --user|--username|-U)
+ PSQLOPT="$PSQLOPT -U '$2'"
+ shift;;
+ -U*)
+ PSQLOPT="$PSQLOPT $1"
+ ;;
+ --user=*)
+ PSQLOPT="$PSQLOPT -U "`echo $1 | sed 's/^--user=//'`
+ ;;
+ --username=*)
+ PSQLOPT="$PSQLOPT -U "`echo $1 | sed 's/^--username=//'`
+ ;;
+ --password|-W)
+ PSQLOPT="$PSQLOPT -W"
+ ;;
--echo|-e)
PSQLOPT="$PSQLOPT -e"
;;
--no-adduser|-A)
CanAddUser=f
;;
+ --sysid|-i)
+ SysID=$2
+ shift;;
+ --sysid=*)
+ SysID=`echo $1 | sed 's/^--sysid=//'`
+ ;;
+ -i*)
+ SysID=`echo $1 | sed 's/^-i//'`
+ ;;
--pwprompt|--pw|-P)
PwPrompt=t
;;
# Help
if [ "$usage" ]; then
- echo "Usage: $CMDNAME [-h
] [-p ] [-d|-D] [-a|-A] [-P] [username]"
+ echo "Usage: $CMDNAME [-h server] [-p port] [-d|-D] [-a|-A] [-P] [-i id] [username]"
exit 0
fi
+if [ "$SysID" ]; then
+ if [ "$SysID" != "`echo $SysID | sed 's/[^0-9]//g'`" ]; then
+ echo "$CMDNAME: User sysid must be a positive number."
+ exit 1
+ fi
+fi
+
# Get missing user attributes
if [ -z "$NewUser" ]; then
fi
if [ "$PwPrompt" ]; then
- $ECHO_N "Enter password for user $NewUser: "$ECHO_C
+ $ECHO_N "Enter password for user \"$NewUser\": "$ECHO_C
read Password
fi
if [ -z "$CanCreateDb" ]; then
- $ECHO_N "Is the new user allowed to create databases? (y/n) "$ECHO_C
+ $ECHO_N "Shall the new user be allowed to create databases? (y/n) "$ECHO_C
read REPLY
[ $? -ne 0 ] && exit 1
if [ $REPLY = "y" -o $REPLY = "Y" ]; then
#
# build SQL command
#
+NewUser=`echo $NewUser | sed 's/\"/\\\"/g'`
+Password=`echo $Password | sed 's/\"/\\\"/g'`
+
QUERY="CREATE USER \"$NewUser\""
-[ "$Password" ] && QUERY="$QUERY WITH PASSWORD \"$Password\""
+SUBQUERY=
+[ "$SysID" ] && SUBQUERY="$SUBQUERY SYSID $SysID"
+[ "$Password" ] && SUBQUERY="$SUBQUERY PASSWORD \"$Password\""
+[ "$SUBQUERY" ] && QUERY="$QUERY WITH $SUBQUERY"
+
[ "$CanCreateDb" = t ] && QUERY="$QUERY CREATEDB"
[ "$CanCreateDb" = f ] && QUERY="$QUERY NOCREATEDB"
[ "$CanAddUser" = t ] && QUERY="$QUERY CREATEUSER"
#
#
# IDENTIFICATION
-# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/dropdb,v 1.2 1999/12/05 20:52:54 momjian Exp $
+# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/dropdb,v 1.3 1999/12/07 22:41:44 momjian Exp $
#
#-------------------------------------------------------------------------
ECHO_C='\c'
fi
+
while [ $# -gt 0 ]
do
case "$1" in
--host|-h)
PSQLOPT="$PSQLOPT -h $2"
shift;;
+ -h*)
+ PSQLOPT="$PSQLOPT $1"
+ ;;
+ --host=*)
+ PSQLOPT="$PSQLOPT -h "`echo $1 | sed 's/^--host=//'`
+ ;;
--port|-p)
PSQLOPT="$PSQLOPT -p $2"
shift;;
+ -p*)
+ PSQLOPT="$PSQLOPT $1"
+ ;;
+ --port=*)
+ PSQLOPT="$PSQLOPT -p "`echo $1 | sed 's/^--port=//'`
+ ;;
--user|--username|-U)
- PSQLOPT="$PSQLOPT -U $2"
+ PSQLOPT="$PSQLOPT -U '$2'"
shift;;
+ -U*)
+ PSQLOPT="$PSQLOPT $1"
+ ;;
+ --user=*)
+ PSQLOPT="$PSQLOPT -U "`echo $1 | sed 's/^--user=//'`
+ ;;
+ --username=*)
+ PSQLOPT="$PSQLOPT -U "`echo $1 | sed 's/^--username=//'`
+ ;;
--password|-W)
PSQLOPT="$PSQLOPT -W"
;;
if [ "$usage" ]; then
- echo "Usage: $CMDNAME [-h
] [-p ] [-U ] [-W] [-i] dbname"
+ echo "Usage: $CMDNAME [-h server] [-p port] [-U username] [-i] dbname"
exit 0
fi
fi
+dbname=`echo $dbname | sed 's/\"/\\\"/g'`
+
psql $PSQLOPT -d template1 -c "DROP DATABASE \"$dbname\""
if [ $? -ne 0 ]; then
echo "$CMDNAME: Database removal failed."
#
#
# IDENTIFICATION
-# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/droplang,v 1.2 1999/12/05 20:52:54 momjian Exp $
+# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/droplang,v 1.3 1999/12/07 22:41:44 momjian Exp $
#
#-------------------------------------------------------------------------
echo=
list=
+# Check for echo -n vs echo \c
+
+if echo '\c' | grep -s c >/dev/null 2>&1
+then
+ ECHO_N="echo -n"
+ ECHO_C=""
+else
+ ECHO_N="echo"
+ ECHO_C='\c'
+fi
+
# ----------
# Get options, language name and dbname
#-------------------------------------------------------------------------
#
# dropuser--
-# Utility for remocing a user from the PostgreSQL database.
+# Utility for removing a user from the PostgreSQL database.
#
# Copyright (c) 1994, Regents of the University of California
#
#
# IDENTIFICATION
-# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/dropuser,v 1.2 1999/12/05 20:52:54 momjian Exp $
+# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/dropuser,v 1.3 1999/12/07 22:41:44 momjian Exp $
#
# Note - this should NOT be setuid.
#
CMDNAME=`basename $0`
PSQLOPT=
forcedel=t
+DelUser=
# Check for echo -n vs echo \c
ECHO_C='\c'
fi
+
while [ $# -gt 0 ]
do
case "$1" in
--host|-h)
PSQLOPT="$PSQLOPT -h $2"
shift;;
+ -h*)
+ PSQLOPT="$PSQLOPT $1"
+ ;;
+ --host=*)
+ PSQLOPT="$PSQLOPT -h "`echo $1 | sed 's/^--host=//'`
+ ;;
--port|-p)
PSQLOPT="$PSQLOPT -p $2"
shift;;
-# Uncomment these lines if you need the -U and -W options.
-# They are confusing in this context, however.
-# --user|--username|-U)
-# PSQLOPT="$PSQLOPT -U $2"
-# shift;;
-# --password|-W)
-# PSQLOPT="$PSQLOPT -W"
-# ;;
+ -p*)
+ PSQLOPT="$PSQLOPT $1"
+ ;;
+ --port=*)
+ PSQLOPT="$PSQLOPT -p "`echo $1 | sed 's/^--port=//'`
+ ;;
+# Note: These two specify the user to connect as (like in psql),
+# not the user you're dropping.
+ --user|--username|-U)
+ PSQLOPT="$PSQLOPT -U '$2'"
+ shift;;
+ -U*)
+ PSQLOPT="$PSQLOPT $1"
+ ;;
+ --user=*)
+ PSQLOPT="$PSQLOPT -U "`echo $1 | sed 's/^--user=//'`
+ ;;
+ --username=*)
+ PSQLOPT="$PSQLOPT -U "`echo $1 | sed 's/^--username=//'`
+ ;;
+ --password|-W)
+ PSQLOPT="$PSQLOPT -W"
+ ;;
--echo|-e)
PSQLOPT="$PSQLOPT -e"
;;
# Help
if [ "$usage" ]; then
- echo "Usage: $CMDNAME [-h
] [-p ] [-i] [username]"
+ echo "Usage: $CMDNAME [-h server] [-p port] [-i] [username]"
exit 0
fi
if [ -z "$DelUser" ]; then
$ECHO_N "Enter name of user to delete: "$ECHO_C
- read NewUser
+ read DelUser
[ $? -ne 0 ] && exit 1
fi
fi
+DelUser=`echo $DelUser | sed 's/\"/\\\"/g'`
+
psql $PSQLOPT -d template1 -c "DROP USER \"$DelUser\""
if [ $? -ne 0 ]; then
#
#
# IDENTIFICATION
-# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/vacuumdb,v 1.2 1999/12/05 20:02:49 momjian Exp $
+# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/vacuumdb,v 1.3 1999/12/07 22:41:44 momjian Exp $
#
#-------------------------------------------------------------------------
verbose=
analyze=
table=
+dbname=
while [ $# -gt 0 ]
do
--host|-h)
PSQLOPT="$PSQLOPT -h $2"
shift;;
+ -h*)
+ PSQLOPT="$PSQLOPT $1"
+ ;;
+ --host=*)
+ PSQLOPT="$PSQLOPT -h "`echo $1 | sed 's/^--host=//'`
+ ;;
--port|-p)
PSQLOPT="$PSQLOPT -p $2"
shift;;
+ -p*)
+ PSQLOPT="$PSQLOPT $1"
+ ;;
+ --port=*)
+ PSQLOPT="$PSQLOPT -p "`echo $1 | sed 's/^--port=//'`
+ ;;
--user|--username|-U)
- PSQLOPT="$PSQLOPT -U $2"
+ PSQLOPT="$PSQLOPT -U '$2'"
shift;;
+ -U*)
+ PSQLOPT="$PSQLOPT $1"
+ ;;
+ --user=*)
+ PSQLOPT="$PSQLOPT -U "`echo $1 | sed 's/^--user=//'`
+ ;;
+ --username=*)
+ PSQLOPT="$PSQLOPT -U "`echo $1 | sed 's/^--username=//'`
+ ;;
--password|-W)
PSQLOPT="$PSQLOPT -W"
;;
--quiet|-q)
PSQLOPT="$PSQLOPT -o /dev/null"
;;
+ --dbname|--database|-d)
+ dbname="$2"
+ shift;;
-d*)
dbname=`echo $1 | sed 's/^-d//'`
;;
;;
# options converted into SQL command
--analyze|-z)
- analyze="analyze"
+ analyze="ANALYZE "
;;
--table|-t)
- table=$2
+ table="$2"
shift;;
+ -t*)
+ table=`echo $1 | sed 's/^-t//'`
+ ;;
+ --table=*)
+ table=`echo $1 | sed 's/^--table=//'`
+ ;;
--verbose|-v)
- verbose="verbose"
+ verbose="VERBOSE "
;;
-*)
echo "$CMDNAME: Unrecognized option: $1. Try -? for help."
exit 1
;;
-
- *)
+ *)
dbname="$1"
;;
esac
if [ "$usage" ]; then
- echo "Usage: $CMDNAME [-h
] [-p ] [-U ] [-W] [-d ] \\"
+ echo "Usage: $CMDNAME [-h server] [-p port] [-U username] [-d dbname] \\"
echo " [-z|--analyze] [-v|--verbose] [-t|--table 'table[(columns)]'] [dbname]"
exit 0
fi
exit 1
fi
-psql $PSQLOPT -d "$dbname" -c "VACUUM $verbose $analyze $table"
+psql $PSQLOPT -d "$dbname" -c "VACUUM $verbose$analyze$table"
if [ $? -ne 0 ]; then
- echo "$CMDNAME: Database vacuum failed."
+ echo "$CMDNAME: Vacuum failed."
exit 1
fi