diff options
Diffstat (limited to 'src/bin/scripts')
-rw-r--r-- | src/bin/scripts/createdb | 37 | ||||
-rw-r--r-- | src/bin/scripts/createlang.sh | 67 | ||||
-rw-r--r-- | src/bin/scripts/createuser | 39 | ||||
-rw-r--r-- | src/bin/scripts/dropdb | 26 | ||||
-rw-r--r-- | src/bin/scripts/droplang | 50 | ||||
-rw-r--r-- | src/bin/scripts/dropuser | 23 | ||||
-rw-r--r-- | src/bin/scripts/vacuumdb | 53 |
7 files changed, 146 insertions, 149 deletions
diff --git a/src/bin/scripts/createdb b/src/bin/scripts/createdb index 7a7286c5751..490edb196e5 100644 --- a/src/bin/scripts/createdb +++ b/src/bin/scripts/createdb @@ -11,7 +11,7 @@ # # # IDENTIFICATION -# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/createdb,v 1.5 2000/01/12 13:08:55 ishii Exp $ +# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/createdb,v 1.6 2000/01/12 19:36:36 petere Exp $ # #------------------------------------------------------------------------- @@ -28,6 +28,7 @@ do case "$1" in --help|-\?) usage=t + break ;; # options passed on to psql --host|-h) @@ -89,7 +90,8 @@ do MB=`echo $1 | sed 's/^--encoding=//'` ;; -*) - echo "$CMDNAME: Unrecognized option: $1. Try -? for help." + echo "$CMDNAME: unrecognized option: $1" + echo "Try -? for help." exit 1 ;; *) @@ -104,20 +106,17 @@ do done if [ "$usage" ]; then - echo "" echo "Usage: $CMDNAME [options] dbname [description]" echo "" - echo " -h HOSTNAME, --host=HOSTNAME " - echo " -p PORT, --port=PORT " - echo " -U USERNAME, --username=USERNAME " - echo " -W, --password " - echo " -e, --echo " - echo " -q, --quiet " - echo " -D PATH, --location=PATH " - echo " -E ENCODING --encoding=ENCODING " - echo " -?, --help " - echo "" - exit 1 + echo " -D, --location=PATH Alternative place to store the database" + echo " -E, --encoding=ENCODING Multibyte encoding for the database" + echo " -h, --host=HOSTNAME Database server host" + echo " -p, --port=PORT Database server port" + echo " -U, --username=USERNAME Username to connect as" + echo " -W, --password Prompt for password" +#??? echo " -e, --echo " + echo " -q, --quiet Don't write any messages" + exit 0 fi @@ -126,17 +125,19 @@ then mbcode=`pg_encoding "$MB"` if [ -z "$mbcode" ] then - echo "$CMDNAME: \"$MB\" is not a valid encoding name." + echo "$CMDNAME: \"$MB\" is not a valid encoding name" exit 1 fi fi if [ -z "$dbname" ]; then - echo "$CMDNAME: Missing required argument database name. Try -? for help." + echo "$CMDNAME: missing required argument database name" + echo "Try -? for help." exit 1 fi +# escape the quotes dbpath=`echo $dbpath | sed "s/'/\\\\\'/g"` dbname=`echo $dbname | sed 's/\"/\\\"/g'` @@ -147,7 +148,7 @@ withstring= psql $PSQLOPT -d template1 -c "CREATE DATABASE \"$dbname\"$withstring" if [ $? -ne 0 ]; then - echo "$CMDNAME: Database creation failed." + echo "$CMDNAME: database creation failed" exit 1 fi @@ -158,7 +159,7 @@ 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. (Database was created.)" + echo "$CMDNAME: comment creation failed (database was created)" exit 1 fi diff --git a/src/bin/scripts/createlang.sh b/src/bin/scripts/createlang.sh index b5eac5762e2..404a8bd53a7 100644 --- a/src/bin/scripts/createlang.sh +++ b/src/bin/scripts/createlang.sh @@ -8,7 +8,7 @@ # # # IDENTIFICATION -# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/createlang.sh,v 1.4 1999/12/17 18:05:32 momjian Exp $ +# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/createlang.sh,v 1.5 2000/01/12 19:36:36 petere Exp $ # #------------------------------------------------------------------------- @@ -32,16 +32,6 @@ else fi -# ---------- -# Find the default PGLIB directory -# ---------- -postconfig_result="`sh -c postconfig 2>/dev/null`" -if [ "$postconfig_result" ]; then - set -a - eval "$postconfig_result" - set +a -fi - # ---------- # Get options, language name and dbname @@ -51,6 +41,7 @@ do case "$1" in --help|-\?) usage=t + break ;; --list|-l) list=t @@ -115,6 +106,11 @@ do PGLIB=`echo $1 | sed 's/^--pglib=//'` ;; + -*) + echo "$CMDNAME: unrecognized option: $1" + echo "Try -? for help." + exit 1 + ;; *) langname="$1" if [ "$2" ]; then @@ -130,18 +126,15 @@ if [ "$usage" ]; then echo "" echo "Usage: $CMDNAME [options] [langname [dbname]]" echo "" - echo " -h HOSTNAME, --host=HOSTNAME " - echo " -p PORT, --port=PORT " - echo " -U USERNAME, --username=USERNAME " - echo " -l, --list " - echo " -W, --password " - echo " -d DBNAME, --database=DBNAME " - echo " -e, --echo " - echo " -D PATH, --location=PATH " - echo " -L PGLIB --pglib=PGLIB " - echo " -?, --help " - echo "" - exit 1 + echo " -h, --host=HOSTNAME Database server host" + echo " -p, --port=PORT Database server port" + echo " -U, --username=USERNAME Username to connect as" + echo " -W, --password Prompt for password" + echo " -d, --dbname=DBNAME Database to install language in" + echo " -e, --echo Create some output about what is happening" + echo " -L, --pglib=PGLIB Find language interpreter in directory PGLIB" + echo " -l, --list Show a list of currently installed languages" + exit 0 fi if [ "$list" ]; then @@ -154,7 +147,8 @@ fi # Check that we have a database # ---------- if [ -z "$dbname" ]; then - echo "$CMDNAME: Missing required argument database name. Try -? for help." + echo "$CMDNAME: missing required argument database name" + echo "Try -? for help." exit 1 fi @@ -163,9 +157,10 @@ fi # Check that we have PGLIB # ---------- if [ -z "$PGLIB" ]; then - echo "Cannot determine the PostgreSQL lib directory (PGLIB). You must" - echo "identify it either with a --pglib option or by setting the PGLIB" - echo "environment variable." + echo "$CMDNAME: missing required argument PGLIB directory" + echo "(This is the directory where the interpreter for the procedural" + echo "language is stored. Traditionally, these are installed in whatever" + echo "'lib' directory was specified at configure time.)" exit 1 fi @@ -191,7 +186,7 @@ case "$langname" in trusted="TRUSTED " handler="pltcl_call_handler";; *) - echo "$CMDNAME: Unsupported language '$langname'." + echo "$CMDNAME: unsupported language '$langname'" echo "Supported languages are 'plpgsql' and 'pltcl'." exit 1 ;; @@ -203,7 +198,7 @@ esac # in PGLIB # ---------- if [ ! -f $PGLIB/${langname}__DLSUFFIX__ ]; then - echo "Cannot find the file $PGLIB/${langname}__DLSUFFIX__." + echo "$CMDNAME: cannot find the file $PGLIB/${langname}__DLSUFFIX__" echo "" echo "This file contains the call handler for $lancomp. By default," echo "only PL/pgSQL is built and installed; other languages must be" @@ -228,12 +223,12 @@ PSQL="psql -A -t $PSQLOPT -d $dbname -c" # ---------- res=`$PSQL "SELECT oid FROM pg_language WHERE lanname = '$langname'"` if [ $? -ne 0 ]; then - echo "Language installation failed." + echo "$CMDNAME: external error" exit 1 fi if [ "$res" ]; then - echo "The language '$langname' is already installed in database $dbname." - exit 2 + echo "$CMDNAME: '$langname' is already installed in database $dbname" + exit 1 fi # ---------- @@ -241,9 +236,7 @@ fi # ---------- res=`$PSQL "SELECT oid FROM pg_proc WHERE proname = '$handler'"` if [ ! -z "$res" ]; then - echo "The language $lancomp isn't created up to now but there is" - echo "already a function named '$handler' declared." - echo "Language installation aborted." + echo "$CMDNAME: A function named '$handler' already exists. Installation aborted." exit 1 fi @@ -252,12 +245,12 @@ fi # ---------- $PSQL "CREATE FUNCTION $handler () RETURNS OPAQUE AS '$PGLIB/${langname}__DLSUFFIX__' LANGUAGE 'C'" if [ $? -ne 0 ]; then - echo "Language installation failed." + echo "$CMDNAME: language installation failed" exit 1 fi $PSQL "CREATE ${trusted}PROCEDURAL LANGUAGE '$langname' HANDLER $handler LANCOMPILER '$lancomp'" if [ $? -ne 0 ]; then - echo "Language installation failed." + echo "$CMDNAME: language installation failed" exit 1 fi diff --git a/src/bin/scripts/createuser b/src/bin/scripts/createuser index ae4f3dff321..dd184c9a4e8 100644 --- a/src/bin/scripts/createuser +++ b/src/bin/scripts/createuser @@ -8,7 +8,7 @@ # # # IDENTIFICATION -# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/createuser,v 1.4 1999/12/16 20:10:02 momjian Exp $ +# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/createuser,v 1.5 2000/01/12 19:36:36 petere Exp $ # # Note - this should NOT be setuid. # @@ -41,6 +41,7 @@ do case "$1" in --help|-\?) usage=t + break ;; # options passed on to psql --host|-h) @@ -110,7 +111,8 @@ do PwPrompt=t ;; -*) - echo "$CMDNAME: Unrecognized option: $1. Try -? for help." + echo "$CMDNAME: unrecognized option: $1" + echo "Try -? for help." exit 1 ;; *) @@ -121,29 +123,26 @@ do done if [ "$usage" ]; then - echo "" echo "Usage: $CMDNAME [options] [username]" echo "" - echo " -h HOSTNAME, --host=HOSTNAME " - echo " -p PORT, --port=PORT " - echo " -d, --createdb " - echo " -D, --no-createdb " - echo " -a, --adduser " - echo " -A, --no-adduser " - echo " -i SYSID, --sysid=SYSID " - echo " -P, --pwprompt " - echo " -U USERNAME, --username=USERNAME (for connect to db)" - echo " -W, --password (for connect to db)" - echo " -e, --echo " - echo " -q, --quiet " - echo " -?, --help " - echo "" - exit 1 + echo " -d, --createdb User can create new databases" + echo " -D, --no-createdb User cannot create databases" + echo " -a, --adduser User can add new users" + echo " -A, --no-adduser User cannot add new users" + echo " -i, --sysid=SYSID Select sysid for new user" + echo " -P, --pwprompt Assign a password to new user" + echo " -h, --host=HOSTNAME Database server host" + echo " -p, --port=PORT Database server port" + echo " -U, --username=USERNAME Username to connect as (not the one to create)" + echo " -W, --password Prompt for password to connect" +#??? echo " -e, --echo " + echo " -q, --quiet Don't write any messages" + 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." + echo "$CMDNAME: user sysid must be a positive number" exit 1 fi fi @@ -204,7 +203,7 @@ SUBQUERY= psql $PSQLOPT -d template1 -c "$QUERY" if [ $? -ne 0 ]; then - echo "$CMDNAME: Creation of user \"$NewUser\" failed." + echo "$CMDNAME: creation of user \"$NewUser\" failed" exit 1 fi diff --git a/src/bin/scripts/dropdb b/src/bin/scripts/dropdb index 58b4076ebb9..a8396103170 100644 --- a/src/bin/scripts/dropdb +++ b/src/bin/scripts/dropdb @@ -10,7 +10,7 @@ # # # IDENTIFICATION -# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/dropdb,v 1.4 1999/12/16 20:10:02 momjian Exp $ +# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/dropdb,v 1.5 2000/01/12 19:36:36 petere Exp $ # #------------------------------------------------------------------------- @@ -96,23 +96,21 @@ done if [ "$usage" ]; then - echo "" echo "Usage: $CMDNAME [options] dbname" echo "" - echo " -h HOSTNAME, --host=HOSTNAME " - echo " -p PORT, --port=PORT " - echo " -u USERNAME, --username=USERNAME " - echo " -W, --password " - echo " -e, --echo " - echo " -q, --quiet " - echo " -i, --interactive " - echo " -?, --help " - echo "" - exit 1 + echo " -h, --host=HOSTNAME Database server host" + echo " -p, --port=PORT Database server port" + echo " -U, --username=USERNAME Username to connect as" + echo " -W, --password Prompt for password" + echo " -i, --interactive Prompt before deleting anything" +#??? echo " -e, --echo " + echo " -q, --quiet Don't write any messages" + exit 0 fi if [ -z "$dbname" ]; then - echo "$CMDNAME: Missing required argument database name. Try -? for help." + echo "$CMDNAME: missing required argument database name" + echo "Try -? for help." exit 1 fi @@ -131,7 +129,7 @@ dbname=`echo $dbname | sed 's/\"/\\\"/g'` psql $PSQLOPT -d template1 -c "DROP DATABASE \"$dbname\"" if [ $? -ne 0 ]; then - echo "$CMDNAME: Database removal failed." + echo "$CMDNAME: database removal failed" exit 1 fi diff --git a/src/bin/scripts/droplang b/src/bin/scripts/droplang index 8fbfd3b9ec0..a6b6efd3631 100644 --- a/src/bin/scripts/droplang +++ b/src/bin/scripts/droplang @@ -8,7 +8,7 @@ # # # IDENTIFICATION -# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/droplang,v 1.4 1999/12/16 20:10:02 momjian Exp $ +# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/droplang,v 1.5 2000/01/12 19:36:36 petere Exp $ # #------------------------------------------------------------------------- @@ -40,6 +40,7 @@ do case "$1" in --help|-\?) usage=t + break ;; --list|-l) list=t @@ -94,6 +95,11 @@ do dbname=`echo $1 | sed 's/^--database=//'` ;; + -*) + echo "$CMDNAME: unrecognized option: $1" + echo "Try -? for help." + exit 1 + ;; *) langname="$1" if [ "$2" ]; then @@ -108,18 +114,16 @@ done if [ "$usage" ]; then echo "" - echo "Usage: $CMDNAME [options] [language [dbname]]" + echo "Usage: $CMDNAME [options] [langname [dbname]]" echo "" - echo " -h HOSTNAME, --host=HOSTNAME " - echo " -p PORT, --port=PORT " - echo " -u USERNAME, --username=USERNAME " - echo " -W, --password " - echo " -d DBNAME --database=DBNAME " - echo " -e, --echo " - echo " -q, --quiet " - echo " -?, --help " - echo "" - exit 1 + echo " -h, --host=HOSTNAME Database server host" + echo " -p, --port=PORT Database server port" + echo " -U, --username=USERNAME Username to connect as" + echo " -W, --password Prompt for password" + echo " -d, --dbname=DBNAME Database to remove language from" + echo " -e, --echo Create some output about what is happening" + echo " -l, --list Show a list of currently installed languages" + exit 0 fi @@ -133,7 +137,8 @@ fi # Check that we have a database # ---------- if [ -z "$dbname" ]; then - echo "$CMDNAME: Missing required argument database name. Try -? for help." + echo "$CMDNAME: missing required argument database name" + echo "Try -? for help." exit 1 fi @@ -159,8 +164,8 @@ case "$langname" in handler="pltcl_call_handler" ;; *) - echo "$CMDNAME: Unsupported language '$langname'." - echo " Supported languages are 'plpgsql' and 'pltcl'." + echo "$CMDNAME: unsupported language '$langname'" + echo "Supported languages are 'plpgsql' and 'pltcl'." exit 1 ;; esac @@ -180,11 +185,11 @@ PSQL="psql -A -t $PSQLOPT -d $dbname -c" # ---------- res=`$PSQL "SELECT oid FROM pg_language WHERE lanname = '$langname'"` if [ $? -ne 0 ]; then - echo "Language removal failed." + echo "$CMDNAME: external error" exit 1 fi if [ -z "$res" ]; then - echo "The language '$langname' isn't installed in database $dbname." + echo "$CMDNAME: '$langname' is not installed in database $dbname" exit 1 fi @@ -194,13 +199,12 @@ fi # ---------- res=`$PSQL "SELECT COUNT(proname) FROM pg_proc P, pg_language L WHERE P.prolang = L.oid AND L.lanname = '$langname'"` if [ $? -ne 0 ]; then - echo "Language removal failed." + echo "$CMDNAME: external error" exit 1 fi if [ $res -ne 0 ]; then - echo "There are $res functions/trigger procedures declared in language" - echo "$lancomp." - echo "Language not removed." + echo "$CMDNAME: There are $res functions/trigger procedures declared in language" + echo "$lancomp. Language not removed." exit 1 fi @@ -209,12 +213,12 @@ fi # ---------- $PSQL "DROP PROCEDURAL LANGUAGE '$langname'" if [ $? -ne 0 ]; then - echo "Language removal failed." + echo "$CMDNAME: language removal failed" exit 1 fi $PSQL "DROP FUNCTION $handler()" if [ $? -ne 0 ]; then - echo "Language removal failed." + echo "$CMDNAME: language removal failed" exit 1 fi diff --git a/src/bin/scripts/dropuser b/src/bin/scripts/dropuser index a5d743eadcd..add007290b0 100644 --- a/src/bin/scripts/dropuser +++ b/src/bin/scripts/dropuser @@ -8,7 +8,7 @@ # # # IDENTIFICATION -# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/dropuser,v 1.4 1999/12/16 20:10:02 momjian Exp $ +# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/dropuser,v 1.5 2000/01/12 19:36:36 petere Exp $ # # Note - this should NOT be setuid. # @@ -36,6 +36,7 @@ do case "$1" in --help|-\?) usage=t + break ;; # options passed on to psql --host|-h) @@ -99,16 +100,14 @@ if [ "$usage" ]; then echo "" echo "Usage: $CMDNAME [options] [username]" echo "" - echo " -h HOSTNAME, --host=HOSTNAME " - echo " -p PORT, --port=PORT " - echo " -u USERNAME, --username=USERNAME (for connect to db)" - echo " -W, --password " - echo " -e, --echo " - echo " -q, --quiet " - echo " -i, --interactive " - echo " -?, --help " - echo "" - exit 1 + echo " -h, --host=HOSTNAME Database server host" + echo " -p, --port=PORT Database server port" + echo " -U, --username=USERNAME Username to connect as (not the one to drop)" + echo " -W, --password Prompt for password to connect" + echo " -i, --interactive Prompt before deleting anything" +#??? echo " -e, --echo " + echo " -q, --quiet Don't write any messages" + exit 0 fi # Prompt for username if missing @@ -135,7 +134,7 @@ DelUser=`echo $DelUser | sed 's/\"/\\\"/g'` psql $PSQLOPT -d template1 -c "DROP USER \"$DelUser\"" if [ $? -ne 0 ]; then - echo "$CMDNAME: Deletion of user \"$DelUser\" failed." + echo "$CMDNAME: deletion of user \"$DelUser\" failed" exit 1 fi diff --git a/src/bin/scripts/vacuumdb b/src/bin/scripts/vacuumdb index 234a26b2caf..92c0ce9cc94 100644 --- a/src/bin/scripts/vacuumdb +++ b/src/bin/scripts/vacuumdb @@ -11,7 +11,7 @@ # # # IDENTIFICATION -# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/vacuumdb,v 1.7 1999/12/18 08:46:44 momjian Exp $ +# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/vacuumdb,v 1.8 2000/01/12 19:36:36 petere Exp $ # #------------------------------------------------------------------------- @@ -29,6 +29,7 @@ do case "$1" in --help|-\?) usage=t + break ;; # options passed on to psql --host|-h) @@ -86,7 +87,7 @@ do --analyze|-z) analyze="ANALYZE " ;; - --alldb|-a) + --all|-a) alldb=Y ;; --table|-t) @@ -103,7 +104,8 @@ do ;; -*) - echo "$CMDNAME: Unrecognized option: $1. Try -? for help." + echo "$CMDNAME: unrecognized option: $1" + echo "Try -? for help." exit 1 ;; *) @@ -114,42 +116,43 @@ do done if [ "$usage" ]; then - echo "" echo "Usage: $CMDNAME [options] [dbname]" echo "" - echo " -h HOSTNAME, --host=HOSTNAME " - echo " -p PORT, --port=PORT " - echo " -u USERNAME, --username=USERNAME " - echo " -W, --password " - echo " -d DBNAME, --database=DBNAME " - echo " -z, --analyze " - echo " -a, --alldb " - echo " -t TABLE[(columns)], --table=TABLE[(columns)]" - echo " -v, --verbose " - echo " -e, --echo " - echo " -q, --quiet " - echo " -?, --help " - echo "" - exit 1 + echo " -h, --host=HOSTNAME Database server host" + echo " -p, --port=PORT Database server port" + echo " -U, --username=USERNAME Username to connect as" + echo " -W, --password Prompt for password" + echo " -d, --dbname=DBNAME Database to vacuum" + echo " -a, --all Vacuum all databases" + echo " -z, --analyze Update optimizer hints" + echo " -t, --table='TABLE[(columns)]' Vacuum specific table only" + echo " -v, --verbose Write a lot of output" +#??? echo " -e, --echo " + echo " -q, --quiet Don't write any output" + exit 0 fi -if [ ! -z "$alldb" ]; then - dbname="`psql $PASSWDOPT $AUTHOPT $PGHOSTOPT $PGPORTOPT -q -t -A -d template1 -c 'SELECT datname FROM pg_database'`" +if [ "$alldb" ]; then + if [ "$dbname" -o "$table" ]; then + echo "$CMDNAME: cannot vacuum all databases and a specific one at the same time" + exit 1 + fi + dbname="`psql $PSQLOPT -q -t -A -d template1 -c 'SELECT datname FROM pg_database'`" fi if [ -z "$dbname" ]; then - echo "$CMDNAME: Missing required argument database name. Try -? for help." + echo "$CMDNAME: missing required argument database name" + echo "Try -? for help." exit 1 fi for db in $dbname do - psql $PASSWDOPT -tq $AUTHOPT $PGHOSTOPT $PGPORTOPT -c "vacuum $verbose $analyze $table" $db + psql $PSQLOPT -c "vacuum $verbose $analyze $table" -d $dbname done -if [ $? -ne 0 ] -then - echo "$CMDNAME: Vacuum failed." +if [ $? -ne 0 ]; then + echo "$CMDNAME: vacuum failed" exit 1 fi |