Fix script to handle autocommit = 'off' by prepending autocommit 'on' to

the start of the psql commandline.  This is better than adding BEGIN/END
because it handles multiple queries well, and allows the return code for
psql to return the proper value.
This commit is contained in:
Bruce Momjian 2002-10-16 03:24:09 +00:00
parent facb720073
commit 5d8c67462d
8 changed files with 20 additions and 20 deletions

View File

@ -11,7 +11,7 @@
# #
# #
# IDENTIFICATION # IDENTIFICATION
# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/clusterdb,v 1.4 2002/09/27 17:51:10 momjian Exp $ # $Header: /cvsroot/pgsql/src/bin/scripts/Attic/clusterdb,v 1.5 2002/10/16 03:24:09 momjian Exp $
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
@ -176,7 +176,7 @@ do
idx=`echo $tabs | cut -d: -f3` idx=`echo $tabs | cut -d: -f3`
query="$query CLUSTER $idx ON $nspc.$tab;" query="$query CLUSTER $idx ON $nspc.$tab;"
done done
${PATHNAME}psql $PSQLOPT $ECHOOPT -c "$query" -d $db ${PATHNAME}psql $PSQLOPT $ECHOOPT -c "SET autocommit = 'on';$query" -d $db
if [ "$?" -ne 0 ] if [ "$?" -ne 0 ]
then then
echo "$CMDNAME: While clustering $db, the following failed: $query" 1>&2 echo "$CMDNAME: While clustering $db, the following failed: $query" 1>&2

View File

@ -12,7 +12,7 @@
# #
# #
# IDENTIFICATION # IDENTIFICATION
# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/createdb,v 1.25 2002/09/03 21:45:43 petere Exp $ # $Header: /cvsroot/pgsql/src/bin/scripts/Attic/createdb,v 1.26 2002/10/16 03:24:09 momjian Exp $
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
@ -189,7 +189,7 @@ withstring=
[ "$TEMPLATE" ] && withstring="$withstring TEMPLATE = \"$TEMPLATE\"" [ "$TEMPLATE" ] && withstring="$withstring TEMPLATE = \"$TEMPLATE\""
[ "$withstring" ] && withstring=" WITH$withstring" [ "$withstring" ] && withstring=" WITH$withstring"
${PATHNAME}psql $PSQLOPT -d template1 -c "CREATE DATABASE \"$dbname\"$withstring" ${PATHNAME}psql $PSQLOPT -d template1 -c "SET autocommit = 'on';CREATE DATABASE \"$dbname\"$withstring"
if [ "$?" -ne 0 ]; then if [ "$?" -ne 0 ]; then
echo "$CMDNAME: database creation failed" 1>&2 echo "$CMDNAME: database creation failed" 1>&2
exit 1 exit 1
@ -200,7 +200,7 @@ fi
dbcomment=`echo "$dbcomment" | sed "s/'/\\\\\'/g"` dbcomment=`echo "$dbcomment" | sed "s/'/\\\\\'/g"`
${PATHNAME}psql $PSQLOPT -d "$dbname" -c "COMMENT ON DATABASE \"$dbname\" IS '$dbcomment'" ${PATHNAME}psql $PSQLOPT -d "$dbname" -c "SET autocommit = 'on';COMMENT ON DATABASE \"$dbname\" IS '$dbcomment'"
if [ "$?" -ne 0 ]; then if [ "$?" -ne 0 ]; then
echo "$CMDNAME: comment creation failed (database was created)" 1>&2 echo "$CMDNAME: comment creation failed (database was created)" 1>&2
exit 1 exit 1

View File

@ -7,7 +7,7 @@
# Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group # Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
# Portions Copyright (c) 1994, Regents of the University of California # Portions Copyright (c) 1994, Regents of the University of California
# #
# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/createlang.sh,v 1.39 2002/09/24 23:14:25 tgl Exp $ # $Header: /cvsroot/pgsql/src/bin/scripts/Attic/createlang.sh,v 1.40 2002/10/16 03:24:09 momjian Exp $
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
@ -270,7 +270,7 @@ fi
# Create the call handler and the language # Create the call handler and the language
# ---------- # ----------
if [ "$handlerexists" = no ]; then if [ "$handlerexists" = no ]; then
sqlcmd="CREATE FUNCTION \"$handler\" () RETURNS LANGUAGE_HANDLER AS '$PGLIB/${object}' LANGUAGE C;" sqlcmd="SET autocommit = 'on';CREATE FUNCTION \"$handler\" () RETURNS LANGUAGE_HANDLER AS '$PGLIB/${object}' LANGUAGE C;"
if [ "$showsql" = yes ]; then if [ "$showsql" = yes ]; then
echo "$sqlcmd" echo "$sqlcmd"
fi fi
@ -281,7 +281,7 @@ if [ "$handlerexists" = no ]; then
fi fi
fi fi
sqlcmd="CREATE ${trusted}LANGUAGE \"$langname\" HANDLER \"$handler\";" sqlcmd="SET autocommit = 'on';CREATE ${trusted}LANGUAGE \"$langname\" HANDLER \"$handler\";"
if [ "$showsql" = yes ]; then if [ "$showsql" = yes ]; then
echo "$sqlcmd" echo "$sqlcmd"
fi fi
@ -297,7 +297,7 @@ fi
# seems best to disable public USAGE for an untrusted one. # seems best to disable public USAGE for an untrusted one.
# ---------- # ----------
if test -z "$trusted"; then if test -z "$trusted"; then
sqlcmd="REVOKE ALL ON LANGUAGE \"$langname\" FROM PUBLIC;" sqlcmd="SET autocommit = 'on';REVOKE ALL ON LANGUAGE \"$langname\" FROM PUBLIC;"
if [ "$showsql" = yes ]; then if [ "$showsql" = yes ]; then
echo "$sqlcmd" echo "$sqlcmd"
fi fi

View File

@ -9,7 +9,7 @@
# #
# #
# IDENTIFICATION # IDENTIFICATION
# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/createuser,v 1.26 2002/06/20 20:29:42 momjian Exp $ # $Header: /cvsroot/pgsql/src/bin/scripts/Attic/createuser,v 1.27 2002/10/16 03:24:09 momjian Exp $
# #
# Note - this should NOT be setuid. # Note - this should NOT be setuid.
# #
@ -253,7 +253,7 @@ SUBQUERY=
[ "$CanAddUser" = t ] && QUERY="$QUERY CREATEUSER" [ "$CanAddUser" = t ] && QUERY="$QUERY CREATEUSER"
[ "$CanAddUser" = f ] && QUERY="$QUERY NOCREATEUSER" [ "$CanAddUser" = f ] && QUERY="$QUERY NOCREATEUSER"
${PATHNAME}psql -c "$QUERY" -d template1 $PSQLOPT ${PATHNAME}psql -c "SET autocommit = 'on';$QUERY" -d template1 $PSQLOPT
if [ "$?" -ne 0 ]; then if [ "$?" -ne 0 ]; then
echo "$CMDNAME: creation of user \"$NewUser\" failed" 1>&2 echo "$CMDNAME: creation of user \"$NewUser\" failed" 1>&2
exit 1 exit 1

View File

@ -11,7 +11,7 @@
# #
# #
# IDENTIFICATION # IDENTIFICATION
# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/dropdb,v 1.16 2002/06/20 20:29:42 momjian Exp $ # $Header: /cvsroot/pgsql/src/bin/scripts/Attic/dropdb,v 1.17 2002/10/16 03:24:09 momjian Exp $
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
@ -138,7 +138,7 @@ fi
dbname=`echo "$dbname" | sed 's/\"/\\\"/g'` dbname=`echo "$dbname" | sed 's/\"/\\\"/g'`
${PATHNAME}psql $PSQLOPT -d template1 -c "DROP DATABASE \"$dbname\"" ${PATHNAME}psql $PSQLOPT -d template1 -c "SET autocommit = 'on';DROP DATABASE \"$dbname\""
if [ "$?" -ne 0 ]; then if [ "$?" -ne 0 ]; then
echo "$CMDNAME: database removal failed" 1>&2 echo "$CMDNAME: database removal failed" 1>&2
exit 1 exit 1

View File

@ -7,7 +7,7 @@
# Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group # Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
# Portions Copyright (c) 1994, Regents of the University of California # Portions Copyright (c) 1994, Regents of the University of California
# #
# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/droplang,v 1.24 2002/08/10 16:57:32 petere Exp $ # $Header: /cvsroot/pgsql/src/bin/scripts/Attic/droplang,v 1.25 2002/10/16 03:24:09 momjian Exp $
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
@ -229,7 +229,7 @@ fi
# ---------- # ----------
# Drop the language # Drop the language
# ---------- # ----------
sqlcmd="DROP LANGUAGE \"$langname\";" sqlcmd="SET autocommit = 'on';DROP LANGUAGE \"$langname\";"
if [ "$showsql" = yes ]; then if [ "$showsql" = yes ]; then
echo "$sqlcmd" echo "$sqlcmd"
fi fi
@ -256,7 +256,7 @@ if [ "$?" -ne 0 ]; then
exit 1 exit 1
fi fi
sqlcmd="DROP FUNCTION \"$handler\" ();" sqlcmd="SET autocommit = 'on';DROP FUNCTION \"$handler\" ();"
if [ "$showsql" = yes ]; then if [ "$showsql" = yes ]; then
echo "$sqlcmd" echo "$sqlcmd"
fi fi

View File

@ -9,7 +9,7 @@
# #
# #
# IDENTIFICATION # IDENTIFICATION
# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/dropuser,v 1.18 2002/06/20 20:29:42 momjian Exp $ # $Header: /cvsroot/pgsql/src/bin/scripts/Attic/dropuser,v 1.19 2002/10/16 03:24:09 momjian Exp $
# #
# Note - this should NOT be setuid. # Note - this should NOT be setuid.
# #
@ -148,7 +148,7 @@ fi
DelUser=`echo "$DelUser" | sed 's/\"/\\\"/g'` DelUser=`echo "$DelUser" | sed 's/\"/\\\"/g'`
${PATHNAME}psql $PSQLOPT -d template1 -c "DROP USER \"$DelUser\"" ${PATHNAME}psql $PSQLOPT -d template1 -c "SET autocommit = 'on';DROP USER \"$DelUser\""
if [ "$?" -ne 0 ]; then if [ "$?" -ne 0 ]; then
echo "$CMDNAME: deletion of user \"$DelUser\" failed" 1>&2 echo "$CMDNAME: deletion of user \"$DelUser\" failed" 1>&2

View File

@ -12,7 +12,7 @@
# #
# #
# IDENTIFICATION # IDENTIFICATION
# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/vacuumdb,v 1.23 2002/08/10 16:57:32 petere Exp $ # $Header: /cvsroot/pgsql/src/bin/scripts/Attic/vacuumdb,v 1.24 2002/10/16 03:24:09 momjian Exp $
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
@ -169,7 +169,7 @@ fi
for db in $dbname for db in $dbname
do do
[ "$alldb" -a "$quiet" -ne 1 ] && echo "Vacuuming $db" [ "$alldb" -a "$quiet" -ne 1 ] && echo "Vacuuming $db"
${PATHNAME}psql $PSQLOPT $ECHOOPT -c "VACUUM $full $verbose $analyze $table" -d $db ${PATHNAME}psql $PSQLOPT $ECHOOPT -c "SET autocommit = 'on';VACUUM $full $verbose $analyze $table" -d $db
if [ "$?" -ne 0 ]; then if [ "$?" -ne 0 ]; then
echo "$CMDNAME: vacuum $table $db failed" 1>&2 echo "$CMDNAME: vacuum $table $db failed" 1>&2
exit 1 exit 1