From 65e00518431652be36cfa676a3e216315e4dd659 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Wed, 19 Jan 2000 20:08:36 +0000 Subject: [PATCH] another round of user interface cleanups removed pg_id fixed a few bugs in the scripts --- doc/src/sgml/ref/createlang.sgml | 15 +------ doc/src/sgml/ref/droplang.sgml | 15 +------ src/bin/Makefile | 4 +- src/bin/initdb/initdb.sh | 4 +- src/bin/initlocation/initlocation.sh | 4 +- src/bin/ipcclean/ipcclean.sh | 4 +- src/bin/pg_dump/pg_dump.c | 4 +- src/bin/pg_id/Makefile | 46 -------------------- src/bin/pg_id/pg_id.c | 63 ---------------------------- src/bin/psql/common.c | 4 +- src/bin/psql/help.c | 4 +- src/bin/psql/startup.c | 10 ++++- src/bin/scripts/createdb | 30 +++++++------ src/bin/scripts/createlang.sh | 56 +++++++++++-------------- src/bin/scripts/createuser | 28 +++++++------ src/bin/scripts/dropdb | 29 +++++++------ src/bin/scripts/droplang | 43 ++++++++----------- src/bin/scripts/dropuser | 33 ++++++++------- src/bin/scripts/vacuumdb | 47 +++++++++++---------- 19 files changed, 161 insertions(+), 282 deletions(-) delete mode 100644 src/bin/pg_id/Makefile delete mode 100644 src/bin/pg_id/pg_id.c diff --git a/doc/src/sgml/ref/createlang.sgml b/doc/src/sgml/ref/createlang.sgml index 309a80266d..71de026884 100644 --- a/doc/src/sgml/ref/createlang.sgml +++ b/doc/src/sgml/ref/createlang.sgml @@ -1,5 +1,5 @@ @@ -114,16 +114,6 @@ createlang [ connection options ] - - - -e, --echo - - - Echo the commands that createlang generates - and sends to the backend. - - - - @@ -142,9 +132,6 @@ createlang [ connection options ] - for details. Check also under for more possibilities. - - No output is generated if createlang succeeds. - diff --git a/doc/src/sgml/ref/droplang.sgml b/doc/src/sgml/ref/droplang.sgml index e367ed254c..65b2cea8bd 100644 --- a/doc/src/sgml/ref/droplang.sgml +++ b/doc/src/sgml/ref/droplang.sgml @@ -1,5 +1,5 @@ @@ -114,16 +114,6 @@ droplang [ connection options ] --l - - -e, --echo - - - Echo the commands that droplang generates - and sends to the backend. - - - - @@ -142,9 +132,6 @@ droplang [ connection options ] --l for details. Check also under for more possibilities. - - No output is generated if droplang succeeds. - diff --git a/src/bin/Makefile b/src/bin/Makefile index a845b6148c..451fab4bff 100644 --- a/src/bin/Makefile +++ b/src/bin/Makefile @@ -1,13 +1,13 @@ #------------------------------------------------------------------------- # # Makefile -# Makefile for src/bin (utility programs) +# Makefile for src/bin (client programs) # # Copyright (c) 1994, Regents of the University of California # # # IDENTIFICATION -# $Header: /cvsroot/pgsql/src/bin/Makefile,v 1.23 2000/01/19 02:58:59 petere Exp $ +# $Header: /cvsroot/pgsql/src/bin/Makefile,v 1.24 2000/01/19 20:08:23 petere Exp $ # #------------------------------------------------------------------------- diff --git a/src/bin/initdb/initdb.sh b/src/bin/initdb/initdb.sh index 02818be924..6db416e1c1 100644 --- a/src/bin/initdb/initdb.sh +++ b/src/bin/initdb/initdb.sh @@ -26,7 +26,7 @@ # # # IDENTIFICATION -# $Header: /cvsroot/pgsql/src/bin/initdb/Attic/initdb.sh,v 1.80 2000/01/18 00:03:35 petere Exp $ +# $Header: /cvsroot/pgsql/src/bin/initdb/Attic/initdb.sh,v 1.81 2000/01/19 20:08:24 petere Exp $ # #------------------------------------------------------------------------- @@ -235,7 +235,7 @@ if [ "$usage" ]; then echo " -d, --debug Generate lots of debugging output" echo " -n, --noclean Do not clean up after errors" echo - echo "Report bugs to ." + echo "Report bugs to ." exit 0 fi diff --git a/src/bin/initlocation/initlocation.sh b/src/bin/initlocation/initlocation.sh index 07b9ed69e2..277d6cbf2b 100644 --- a/src/bin/initlocation/initlocation.sh +++ b/src/bin/initlocation/initlocation.sh @@ -8,7 +8,7 @@ # # # IDENTIFICATION -# $Header: /cvsroot/pgsql/src/bin/initlocation/Attic/initlocation.sh,v 1.4 2000/01/18 00:03:36 petere Exp $ +# $Header: /cvsroot/pgsql/src/bin/initlocation/Attic/initlocation.sh,v 1.5 2000/01/19 20:08:25 petere Exp $ # #------------------------------------------------------------------------- @@ -68,7 +68,7 @@ if [ "$usage" ]; then echo "Usage:" echo " $CMDNAME " echo "" - echo "Report bugs to ." + echo "Report bugs to ." exit 0 fi diff --git a/src/bin/ipcclean/ipcclean.sh b/src/bin/ipcclean/ipcclean.sh index 616ec3c964..87acbecc8a 100644 --- a/src/bin/ipcclean/ipcclean.sh +++ b/src/bin/ipcclean/ipcclean.sh @@ -1,6 +1,6 @@ #!/bin/sh # -# $Header: /cvsroot/pgsql/src/bin/ipcclean/Attic/ipcclean.sh,v 1.3 2000/01/18 00:03:36 petere Exp $ +# $Header: /cvsroot/pgsql/src/bin/ipcclean/Attic/ipcclean.sh,v 1.4 2000/01/19 20:08:27 petere Exp $ # CMDNAME=`basename $0` @@ -13,7 +13,7 @@ if [ "$1" = '-?' -o "$1" = "--help" ]; then echo echo "Note: Since the utilities underlying this script are very different" echo "from platform to platform, chances are that it might not work on" - echo "yours. If that is the case, please write to " + echo "yours. If that is the case, please write to " echo "so that your platform can be supported in the future." exit 0 fi diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 157aba864d..e2ebcbcb0c 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -21,7 +21,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.136 2000/01/19 02:58:59 petere Exp $ + * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.137 2000/01/19 20:08:30 petere Exp $ * * Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb * @@ -167,7 +167,7 @@ help(const char *progname) ); #endif puts("If no database name is not supplied, then the PGDATABASE environment\nvariable value is used.\n"); - puts("Report bugs to ."); + puts("Report bugs to ."); } diff --git a/src/bin/pg_id/Makefile b/src/bin/pg_id/Makefile deleted file mode 100644 index 0919f2ffc4..0000000000 --- a/src/bin/pg_id/Makefile +++ /dev/null @@ -1,46 +0,0 @@ -#------------------------------------------------------------------------- -# -# Makefile.inc-- -# Makefile for bin/pg_id -# -# Copyright (c) 1994, Regents of the University of California -# -# -# IDENTIFICATION -# $Header: /cvsroot/pgsql/src/bin/pg_id/Attic/Makefile,v 1.12 1999/01/17 06:19:10 momjian Exp $ -# -#------------------------------------------------------------------------- - -SRCDIR= ../.. -include ../../Makefile.global - -OBJS= pg_id.o - -# -# And where libpq goes, so goes the authentication stuff... -# -ifdef KRBVERS -LDFLAGS+= $(KRBLIBS) -CFLAGS+= $(KRBFLAGS) -endif - -all: pg_id - -pg_id: $(OBJS) $(LIBPQDIR)/libpq.a - $(CC) -o pg_id -L$(LIBPQDIR) $(OBJS) -lpq $(LDFLAGS) - -$(LIBPQDIR)/libpq.a: - $(MAKE) -C $(LIBPQDIR) libpq.a - -install: pg_id - $(INSTALL) $(INSTL_EXE_OPTS) pg_id$(X) $(BINDIR)/pg_id$(X) - -depend dep: - $(CC) -MM $(CFLAGS) *.c >depend - -clean: - rm -f pg_id$(X) $(OBJS) - -ifeq (depend,$(wildcard depend)) -include depend -endif diff --git a/src/bin/pg_id/pg_id.c b/src/bin/pg_id/pg_id.c deleted file mode 100644 index 70da5f5d5d..0000000000 --- a/src/bin/pg_id/pg_id.c +++ /dev/null @@ -1,63 +0,0 @@ -/*------------------------------------------------------------------------- - * - * pg_id.c - * Print the user ID for the login name passed as argument, - * or the real user ID of the caller if no argument. If the - * login name doesn't exist, print "NOUSER" and exit 1. - * - * Copyright (c) 1994, Regents of the University of California - * - * - * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/bin/pg_id/Attic/pg_id.c,v 1.9 1999/07/19 02:27:09 momjian Exp $ - * - *------------------------------------------------------------------------- - */ -#include -#include -#include -#include -#include - -#include "postgres.h" -#ifdef HAVE_GETOPT_H -#include -#endif - -int -main(int argc, char **argv) -{ - struct passwd *pw; - int ch; - extern int optind; - - while ((ch = getopt(argc, argv, "")) != EOF) - switch (ch) - { - case '?': - default: - fprintf(stderr, "usage: pg_id [login]\n"); - exit(1); - } - argc -= optind; - argv += optind; - - if (argc > 0) - { - if (argc > 1) - { - fprintf(stderr, "usage: pg_id [login]\n"); - exit(1); - } - if ((pw = getpwnam(argv[0])) == NULL) - { - printf("NOUSER\n"); - exit(1); - } - printf("%ld\n", (long) pw->pw_uid); - } - else - printf("%ld\n", (long) getuid()); - - exit(0); -} diff --git a/src/bin/psql/common.c b/src/bin/psql/common.c index 0565d0cac2..c5a2e78af7 100644 --- a/src/bin/psql/common.c +++ b/src/bin/psql/common.c @@ -3,7 +3,7 @@ * * Copyright 2000 by PostgreSQL Global Development Team * - * $Header: /cvsroot/pgsql/src/bin/psql/common.c,v 1.9 2000/01/18 23:30:23 petere Exp $ + * $Header: /cvsroot/pgsql/src/bin/psql/common.c,v 1.10 2000/01/19 20:08:33 petere Exp $ */ #include #include "common.h" @@ -146,7 +146,7 @@ psql_error(const char *fmt, ...) fflush(pset.queryFout); if (pset.inputfile) - fprintf(stderr, "%s:%u: ", pset.inputfile ? pset.inputfile : pset.progname, pset.lineno); + fprintf(stderr, "%s:%s:%u: ", pset.progname, pset.inputfile, pset.lineno); va_start(ap, fmt); vfprintf(stderr, fmt, ap); va_end(ap); diff --git a/src/bin/psql/help.c b/src/bin/psql/help.c index 04690a1303..7b1ce49458 100644 --- a/src/bin/psql/help.c +++ b/src/bin/psql/help.c @@ -3,7 +3,7 @@ * * Copyright 2000 by PostgreSQL Global Development Team * - * $Header: /cvsroot/pgsql/src/bin/psql/help.c,v 1.11 2000/01/18 23:30:23 petere Exp $ + * $Header: /cvsroot/pgsql/src/bin/psql/help.c,v 1.12 2000/01/19 20:08:34 petere Exp $ */ #include #include "help.h" @@ -129,7 +129,7 @@ usage(void) puts( "(for SQL commands) from within psql, or consult the psql section in"); puts( "the PostgreSQL manual, which accompanies the distribution and is also"); puts( "available at ."); - puts( "Report bugs to ."); + puts( "Report bugs to ."); #ifndef WIN32 if (pw) diff --git a/src/bin/psql/startup.c b/src/bin/psql/startup.c index 1c31cb4756..4c16dae9d7 100644 --- a/src/bin/psql/startup.c +++ b/src/bin/psql/startup.c @@ -3,7 +3,7 @@ * * Copyright 2000 by PostgreSQL Global Development Team * - * $Header: /cvsroot/pgsql/src/bin/psql/startup.c,v 1.16 2000/01/18 23:30:24 petere Exp $ + * $Header: /cvsroot/pgsql/src/bin/psql/startup.c,v 1.17 2000/01/19 20:08:34 petere Exp $ */ #include @@ -205,10 +205,18 @@ main(int argc, char **argv) successResult = process_file(options.action_string) ? 0 : 1; /* process slash command if one was given to -c */ else if (options.action == ACT_SINGLE_SLASH) + { + if (GetVariable(pset.vars, "ECHO") && strcmp(GetVariable(pset.vars, "ECHO"), "full")==0) + puts(options.action_string); successResult = HandleSlashCmds(options.action_string, NULL, NULL) != CMD_ERROR ? 0 : 1; + } /* If the query given to -c was a normal one, send it */ else if (options.action == ACT_SINGLE_QUERY) + { + if (GetVariable(pset.vars, "ECHO") && strcmp(GetVariable(pset.vars, "ECHO"), "full")==0) + puts(options.action_string); successResult = SendQuery( options.action_string) ? 0 : 1; + } /* or otherwise enter interactive main loop */ else { diff --git a/src/bin/scripts/createdb b/src/bin/scripts/createdb index 490edb196e..3fba2ae0e5 100644 --- a/src/bin/scripts/createdb +++ b/src/bin/scripts/createdb @@ -11,11 +11,12 @@ # # # IDENTIFICATION -# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/createdb,v 1.6 2000/01/12 19:36:36 petere Exp $ +# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/createdb,v 1.7 2000/01/19 20:08:35 petere Exp $ # #------------------------------------------------------------------------- CMDNAME=`basename $0` +PATHNAME=`echo $0 | sed "s,$CMDNAME\$,,"` MB= PSQLOPT= @@ -49,15 +50,12 @@ do --port=*) PSQLOPT="$PSQLOPT -p "`echo $1 | sed 's/^--port=//'` ;; - --user|--username|-U) - PSQLOPT="$PSQLOPT -U '$2'" + --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=//'` ;; @@ -90,7 +88,7 @@ do MB=`echo $1 | sed 's/^--encoding=//'` ;; -*) - echo "$CMDNAME: unrecognized option: $1" + echo "$CMDNAME: invalid option: $1" echo "Try -? for help." exit 1 ;; @@ -106,16 +104,22 @@ do done if [ "$usage" ]; then - echo "Usage: $CMDNAME [options] dbname [description]" - echo "" + echo "$CMDNAME creates a PostgreSQL database." + echo + echo "Usage:" + echo " $CMDNAME [options] dbname [description]" + echo + echo "Options:" 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" + echo " -e, --echo Show the query being sent to the backend" + echo " -q, --quiet Don't write any messages" + echo + echo "Report bugs to ." exit 0 fi @@ -146,7 +150,7 @@ withstring= [ "$MB" ] && withstring="$withstring ENCODING = '$MB'" [ "$withstring" ] && withstring=" WITH$withstring" -psql $PSQLOPT -d template1 -c "CREATE DATABASE \"$dbname\"$withstring" +${PATHNAME}psql $PSQLOPT -d template1 -c "CREATE DATABASE \"$dbname\"$withstring" if [ $? -ne 0 ]; then echo "$CMDNAME: database creation failed" exit 1 @@ -157,7 +161,7 @@ fi dbcomment=`echo $dbcomment | sed "s/'/\\\\\'/g"` -psql $PSQLOPT -d template1 -c "COMMENT ON DATABASE \"$dbname\" IS '$dbcomment'" +${PATHNAME}psql $PSQLOPT -d template1 -c "COMMENT ON DATABASE \"$dbname\" IS '$dbcomment'" if [ $? -ne 0 ]; then echo "$CMDNAME: comment creation failed (database was created)" exit 1 diff --git a/src/bin/scripts/createlang.sh b/src/bin/scripts/createlang.sh index 404a8bd53a..b789196652 100644 --- a/src/bin/scripts/createlang.sh +++ b/src/bin/scripts/createlang.sh @@ -8,16 +8,16 @@ # # # IDENTIFICATION -# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/createlang.sh,v 1.5 2000/01/12 19:36:36 petere Exp $ +# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/createlang.sh,v 1.6 2000/01/19 20:08:35 petere Exp $ # #------------------------------------------------------------------------- CMDNAME=`basename $0` +PATHNAME=`echo $0 | sed "s,$CMDNAME\$,,"` PSQLOPT= dbname= langname= -echo= list= # Check for echo -n vs echo \c @@ -65,25 +65,19 @@ do --port=*) PSQLOPT="$PSQLOPT -p "`echo $1 | sed 's/^--port=//'` ;; - --user|--username|-U) - PSQLOPT="$PSQLOPT -U '$2'" + --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) - echo=t - ;; - --dbname|--database|-d) + --dbname|-d) dbname="$2" shift;; -d*) @@ -92,9 +86,6 @@ do --dbname=*) dbname=`echo $1 | sed 's/^--dbname=//'` ;; - --database=*) - dbname=`echo $1 | sed 's/^--database=//'` - ;; # misc options --pglib|-L) PGLIB="$2" @@ -107,7 +98,7 @@ do ;; -*) - echo "$CMDNAME: unrecognized option: $1" + echo "$CMDNAME: invalid option: $1" echo "Try -? for help." exit 1 ;; @@ -123,25 +114,24 @@ do done if [ "$usage" ]; then - echo "" - echo "Usage: $CMDNAME [options] [langname [dbname]]" - echo "" + echo "$CMDNAME installs a procedural language into a PostgreSQL database." + echo + echo "Usage:" + echo " $CMDNAME [options] [langname [dbname]]" + echo + echo "Options:" 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" + echo + echo "Report bugs to ." exit 0 fi -if [ "$list" ]; then - psql $PSQLOPT -d "$dbname" -c "SELECT lanname, lanpltrusted, lancompiler FROM pg_language WHERE lanispl = 't'" - exit $? -fi - # ---------- # Check that we have a database @@ -153,6 +143,15 @@ if [ -z "$dbname" ]; then fi +# ---------- +# List option +# ---------- +if [ "$list" ]; then + ${PATHNAME}psql $PSQLOPT -d "$dbname" -P 'title=Procedural languages' -c "SELECT lanname as \"Name\", lanpltrusted as \"Trusted?\", lancompiler as \"Compiler\" FROM pg_language WHERE lanispl = 't'" + exit $? +fi + + # ---------- # Check that we have PGLIB # ---------- @@ -210,13 +209,7 @@ if [ ! -f $PGLIB/${langname}__DLSUFFIX__ ]; then fi -if [ "$echo" ]; then - PSQLOPT="$PSQLOPT -e" -else - PSQLOPT="$PSQLOPT -q" -fi - -PSQL="psql -A -t $PSQLOPT -d $dbname -c" +PSQL="${PATHNAME}psql -A -t -q $PSQLOPT -d $dbname -c" # ---------- # Make sure the language isn't already installed @@ -254,4 +247,5 @@ if [ $? -ne 0 ]; then exit 1 fi +echo "Ok" exit 0 diff --git a/src/bin/scripts/createuser b/src/bin/scripts/createuser index bb1aabba3e..4f717c8cb6 100644 --- a/src/bin/scripts/createuser +++ b/src/bin/scripts/createuser @@ -8,13 +8,14 @@ # # # IDENTIFICATION -# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/createuser,v 1.7 2000/01/19 02:59:01 petere Exp $ +# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/createuser,v 1.8 2000/01/19 20:08:36 petere Exp $ # # Note - this should NOT be setuid. # #------------------------------------------------------------------------- CMDNAME=`basename $0` +PATHNAME=`echo $0 | sed "s,$CMDNAME\$,,"` NewUser= SysID= @@ -64,15 +65,12 @@ do ;; # 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'" + --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=//'` ;; @@ -111,7 +109,7 @@ do PwPrompt=t ;; -*) - echo "$CMDNAME: unrecognized option: $1" + echo "$CMDNAME: invalid option: $1" echo "Try -? for help." exit 1 ;; @@ -123,8 +121,12 @@ do done if [ "$usage" ]; then - echo "Usage: $CMDNAME [options] [username]" - echo "" + echo "$CMDNAME creates a new PostgreSQL user." + echo + echo "Usage:" + echo " $CMDNAME [options] [username]" + echo + echo "Options:" echo " -d, --createdb User can create new databases" echo " -D, --no-createdb User cannot create databases" echo " -a, --adduser User can add new users" @@ -135,8 +137,10 @@ if [ "$usage" ]; then 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" + echo " -e, --echo Show the query being sent to the backend" + echo " -q, --quiet Don't write any messages" + echo + echo "Report bugs to ." exit 0 fi @@ -219,7 +223,7 @@ SUBQUERY= [ "$CanAddUser" = t ] && QUERY="$QUERY CREATEUSER" [ "$CanAddUser" = f ] && QUERY="$QUERY NOCREATEUSER" -psql $PSQLOPT -d template1 -c "$QUERY" +${PATHNAME}psql -c "$QUERY" -d template1 $PSQLOPT if [ $? -ne 0 ]; then echo "$CMDNAME: creation of user \"$NewUser\" failed" exit 1 diff --git a/src/bin/scripts/dropdb b/src/bin/scripts/dropdb index a839610317..65c8542e89 100644 --- a/src/bin/scripts/dropdb +++ b/src/bin/scripts/dropdb @@ -10,11 +10,12 @@ # # # IDENTIFICATION -# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/dropdb,v 1.5 2000/01/12 19:36:36 petere Exp $ +# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/dropdb,v 1.6 2000/01/19 20:08:36 petere Exp $ # #------------------------------------------------------------------------- CMDNAME=`basename $0` +PATHNAME=`echo $0 | sed "s,$CMDNAME\$,,"` PSQLOPT= dbname= @@ -58,15 +59,12 @@ do --port=*) PSQLOPT="$PSQLOPT -p "`echo $1 | sed 's/^--port=//'` ;; - --user|--username|-U) - PSQLOPT="$PSQLOPT -U '$2'" + --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=//'` ;; @@ -84,7 +82,8 @@ do forcedel=f ;; -*) - echo "$CMDNAME: Unrecognized option: $1. Try -? for help." + echo "$CMDNAME: invalid option: $1" + echo "Try -? for help." exit 1 ;; *) @@ -96,15 +95,21 @@ done if [ "$usage" ]; then - echo "Usage: $CMDNAME [options] dbname" - echo "" + echo "$CMDNAME removes a PostgreSQL database." + echo + echo "Usage:" + echo " $CMDNAME [options] dbname" + echo + echo "Options:" 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" + echo " -e, --echo Show the query being sent to the backend" + echo " -q, --quiet Don't write any messages" + echo + echo "Report bugs to ." exit 0 fi @@ -127,7 +132,7 @@ fi dbname=`echo $dbname | sed 's/\"/\\\"/g'` -psql $PSQLOPT -d template1 -c "DROP DATABASE \"$dbname\"" +${PATHNAME}psql $PSQLOPT -d template1 -c "DROP DATABASE \"$dbname\"" if [ $? -ne 0 ]; then echo "$CMDNAME: database removal failed" exit 1 diff --git a/src/bin/scripts/droplang b/src/bin/scripts/droplang index a6b6efd363..cd6563aeef 100644 --- a/src/bin/scripts/droplang +++ b/src/bin/scripts/droplang @@ -8,11 +8,12 @@ # # # IDENTIFICATION -# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/droplang,v 1.5 2000/01/12 19:36:36 petere Exp $ +# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/droplang,v 1.6 2000/01/19 20:08:36 petere Exp $ # #------------------------------------------------------------------------- CMDNAME=`basename $0` +PATHNAME=`echo $0 | sed "s,$CMDNAME\$,,"` PSQLOPT= dbname= @@ -64,25 +65,19 @@ do --port=*) PSQLOPT="$PSQLOPT -p "`echo $1 | sed 's/^--port=//'` ;; - --user|--username|-U) - PSQLOPT="$PSQLOPT -U '$2'" + --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) - echo=t - ;; - --dbname|--database|-d) + --dbname|-d) dbname="$2" shift;; -d*) @@ -91,12 +86,9 @@ do --dbname=*) dbname=`echo $1 | sed 's/^--dbname=//'` ;; - --database=*) - dbname=`echo $1 | sed 's/^--database=//'` - ;; -*) - echo "$CMDNAME: unrecognized option: $1" + echo "$CMDNAME: invalid option: $1" echo "Try -? for help." exit 1 ;; @@ -113,22 +105,26 @@ done if [ "$usage" ]; then - echo "" - echo "Usage: $CMDNAME [options] [langname [dbname]]" - echo "" + echo "$CMDNAME removes a procedural language from a database." + echo + echo "Usage:" + echo " $CMDNAME [options] [langname [dbname]]" + echo + echo "Options:" 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" + echo + echo "Report bugs to ." exit 0 fi if [ "$list" ]; then - psql $PSQLOPT -d "$dbname" -c "SELECT lanname, lanpltrusted, lancompiler FROM pg_language WHERE lanispl = 't'" + ${PATHNAME}psql $PSQLOPT -d "$dbname" -P 'title=Procedural languages' -c "SELECT lanname as \"Name\", lanpltrusted as \"Trusted?\", lancompiler as \"Compiler\" FROM pg_language WHERE lanispl = 't'" exit $? fi @@ -171,13 +167,7 @@ case "$langname" in esac -if [ "$echo" ]; then - PSQLOPT="$PSQLOPT -e" -else - PSQLOPT="$PSQLOPT -q" -fi - -PSQL="psql -A -t $PSQLOPT -d $dbname -c" +PSQL="${PATHNAME}psql -A -t -q $PSQLOPT -d $dbname -c" # ---------- @@ -222,4 +212,5 @@ if [ $? -ne 0 ]; then exit 1 fi +echo "Ok" exit 0 diff --git a/src/bin/scripts/dropuser b/src/bin/scripts/dropuser index add007290b..3a33c1f9cd 100644 --- a/src/bin/scripts/dropuser +++ b/src/bin/scripts/dropuser @@ -8,13 +8,15 @@ # # # IDENTIFICATION -# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/dropuser,v 1.5 2000/01/12 19:36:36 petere Exp $ +# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/dropuser,v 1.6 2000/01/19 20:08:36 petere Exp $ # # Note - this should NOT be setuid. # #------------------------------------------------------------------------- CMDNAME=`basename $0` +PATHNAME=`echo $0 | sed "s,$CMDNAME\$,,"` + PSQLOPT= forcedel=t DelUser= @@ -59,15 +61,12 @@ do ;; # 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'" + --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=//'` ;; @@ -85,7 +84,8 @@ do forcedel=f ;; -*) - echo "$CMDNAME: Unrecognized option: $1. Try -? for help." + echo "$CMDNAME: invalid option: $1" + echo "Try -? for help." exit 1 ;; *) @@ -97,16 +97,21 @@ done if [ "$usage" ]; then - echo "" - echo "Usage: $CMDNAME [options] [username]" - echo "" + echo "$CMDNAME removes a PostgreSQL user." + echo + echo "Usage:" + echo " $CMDNAME [options] [username]" + echo + echo "Options:" 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" + echo " -e, --echo Show the query being sent to the backend" + echo " -q, --quiet Don't write any messages" + echo + echo "Report bugs to ." exit 0 fi @@ -120,7 +125,7 @@ fi if [ "$forcedel" = f ]; then - echo "User \"$DelUser\" and any owned databases will be permanently deleted." + echo "User \"$DelUser\" will be permanently deleted." $ECHO_N "Are you sure? (y/n) "$ECHO_C read REPLY @@ -131,7 +136,7 @@ fi DelUser=`echo $DelUser | sed 's/\"/\\\"/g'` -psql $PSQLOPT -d template1 -c "DROP USER \"$DelUser\"" +${PATHNAME}psql $PSQLOPT -d template1 -c "DROP USER \"$DelUser\"" if [ $? -ne 0 ]; then echo "$CMDNAME: deletion of user \"$DelUser\" failed" diff --git a/src/bin/scripts/vacuumdb b/src/bin/scripts/vacuumdb index 92c0ce9cc9..fcf6d4513c 100644 --- a/src/bin/scripts/vacuumdb +++ b/src/bin/scripts/vacuumdb @@ -11,11 +11,12 @@ # # # IDENTIFICATION -# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/vacuumdb,v 1.8 2000/01/12 19:36:36 petere Exp $ +# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/vacuumdb,v 1.9 2000/01/19 20:08:36 petere Exp $ # #------------------------------------------------------------------------- CMDNAME=`basename $0` +PATHNAME=`echo $0 | sed "s,$CMDNAME\$,,"` PSQLOPT= verbose= @@ -23,6 +24,7 @@ analyze= table= dbname= alldb= +quiet=0 while [ $# -gt 0 ] do @@ -50,15 +52,12 @@ do --port=*) PSQLOPT="$PSQLOPT -p "`echo $1 | sed 's/^--port=//'` ;; - --user|--username|-U) - PSQLOPT="$PSQLOPT -U '$2'" + --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=//'` ;; @@ -66,12 +65,13 @@ do PSQLOPT="$PSQLOPT -W" ;; --echo|-e) - PSQLOPT="$PSQLOPT -e" + ECHOOPT="-e" ;; --quiet|-q) - PSQLOPT="$PSQLOPT -o /dev/null" + ECHOOPT="$ECHOOPT -o /dev/null" + quiet=1 ;; - --dbname|--database|-d) + --dbname|-d) dbname="$2" shift;; -d*) @@ -80,12 +80,9 @@ do --dbname=*) dbname=`echo $1 | sed 's/^--dbname=//'` ;; - --database=*) - dbname=`echo $1 | sed 's/^--database=//'` - ;; # options converted into SQL command --analyze|-z) - analyze="ANALYZE " + analyze="ANALYZE" ;; --all|-a) alldb=Y @@ -100,11 +97,11 @@ do table=`echo $1 | sed 's/^--table=//'` ;; --verbose|-v) - verbose="VERBOSE " + verbose="VERBOSE" ;; -*) - echo "$CMDNAME: unrecognized option: $1" + echo "$CMDNAME: invalid option: $1" echo "Try -? for help." exit 1 ;; @@ -116,8 +113,12 @@ do done if [ "$usage" ]; then - echo "Usage: $CMDNAME [options] [dbname]" - echo "" + echo "$CMDNAME cleans and analyzes a PostgreSQL database." + echo + echo "Usage:" + echo " $CMDNAME [options] [dbname]" + echo + echo "Options:" echo " -h, --host=HOSTNAME Database server host" echo " -p, --port=PORT Database server port" echo " -U, --username=USERNAME Username to connect as" @@ -127,8 +128,10 @@ if [ "$usage" ]; then 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 " -e, --echo Show the command being sent to the backend" echo " -q, --quiet Don't write any output" + echo + echo "Report bugs to ." exit 0 fi @@ -137,10 +140,9 @@ if [ "$alldb" ]; 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 + dbname=`${PATHNAME}psql $PSQLOPT -q -t -A -d template1 -c 'SELECT datname FROM pg_database'` -if [ -z "$dbname" ]; then +elif [ -z "$dbname" ]; then echo "$CMDNAME: missing required argument database name" echo "Try -? for help." exit 1 @@ -148,7 +150,8 @@ fi for db in $dbname do - psql $PSQLOPT -c "vacuum $verbose $analyze $table" -d $dbname + [ "$alldb" -a "$quiet" -ne 1 ] && echo "Vacuuming $db" + ${PATHNAME}psql $PSQLOPT $ECHOOPT -c "VACUUM $verbose $analyze $table" -d $db done if [ $? -ne 0 ]; then -- 2.40.0