2 #-------------------------------------------------------------------------
5 # Utility for removing a user from the PostgreSQL database.
7 # Copyright (c) 1994, Regents of the University of California
11 # $Header: /cvsroot/pgsql/src/bin/scripts/Attic/dropuser,v 1.11 2001/01/21 05:16:45 momjian Exp $
13 # Note - this should NOT be setuid.
15 #-------------------------------------------------------------------------
18 PATHNAME=`echo $0 | sed "s,$CMDNAME\$,,"`
24 # Check for echo -n vs echo \c
26 if echo '\c' | grep -s c >/dev/null 2>&1
43 # options passed on to psql
45 PSQLOPT="$PSQLOPT -h $2"
51 PSQLOPT="$PSQLOPT -h "`echo $1 | sed 's/^--host=//'`
54 PSQLOPT="$PSQLOPT -p $2"
60 PSQLOPT="$PSQLOPT -p "`echo $1 | sed 's/^--port=//'`
62 # Note: These two specify the user to connect as (like in psql),
63 # not the user you're dropping.
65 PSQLOPT="$PSQLOPT -U $2"
71 PSQLOPT="$PSQLOPT -U "`echo $1 | sed 's/^--username=//'`
80 PSQLOPT="$PSQLOPT -o /dev/null"
87 echo "$CMDNAME: invalid option: $1" 1>&2
88 echo "Try '$CMDNAME --help' for more information." 1>&2
100 echo "$CMDNAME removes a PostgreSQL user."
103 echo " $CMDNAME [options] [username]"
106 echo " -h, --host=HOSTNAME Database server host"
107 echo " -p, --port=PORT Database server port"
108 echo " -U, --username=USERNAME Username to connect as (not the one to drop)"
109 echo " -W, --password Prompt for password to connect"
110 echo " -i, --interactive Prompt before deleting anything"
111 echo " -e, --echo Show the query being sent to the backend"
112 echo " -q, --quiet Don't write any messages"
114 echo "Report bugs to <pgsql-bugs@postgresql.org>."
118 # Prompt for username if missing
120 if [ -z "$DelUser" ]; then
121 $ECHO_N "Enter name of user to delete: "$ECHO_C
123 [ $? -ne 0 ] && exit 1
127 if [ "$forcedel" = f ]; then
128 echo "User \"$DelUser\" will be permanently deleted."
129 $ECHO_N "Are you sure? (y/n) "$ECHO_C
132 [ $? -eq 1 ] && exit 1
133 [ "$REPLY" != "y" -a "$REPLY" != "Y" ] && exit 0
137 DelUser=`echo "$DelUser" | sed 's/\"/\\\"/g'`
139 ${PATHNAME}psql $PSQLOPT -d template1 -c "DROP USER \"$DelUser\""
141 if [ $? -ne 0 ]; then
142 echo "$CMDNAME: deletion of user \"$DelUser\" failed" 1>&2