OSDN Git Service

Fix script to handle autocommit = 'off' by prepending autocommit 'on' to
authorBruce Momjian <bruce@momjian.us>
Wed, 16 Oct 2002 03:24:09 +0000 (03:24 +0000)
committerBruce Momjian <bruce@momjian.us>
Wed, 16 Oct 2002 03:24:09 +0000 (03:24 +0000)
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.

src/bin/scripts/clusterdb
src/bin/scripts/createdb
src/bin/scripts/createlang.sh
src/bin/scripts/createuser
src/bin/scripts/dropdb
src/bin/scripts/droplang
src/bin/scripts/dropuser
src/bin/scripts/vacuumdb

index d948dc5..c2b8b4e 100644 (file)
@@ -11,7 +11,7 @@
 #
 #
 # 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`
                query="$query CLUSTER $idx ON $nspc.$tab;"
        done
-       ${PATHNAME}psql $PSQLOPT $ECHOOPT -c "$query" -d $db
+       ${PATHNAME}psql $PSQLOPT $ECHOOPT -c "SET autocommit = 'on';$query" -d $db
        if [ "$?" -ne 0 ]
        then
                echo "$CMDNAME: While clustering $db, the following failed: $query" 1>&2
index bd68f4c..ad83719 100644 (file)
@@ -12,7 +12,7 @@
 #
 #
 # 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\""
 [ "$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
        echo "$CMDNAME: database creation failed" 1>&2
        exit 1
@@ -200,7 +200,7 @@ fi
 
 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
        echo "$CMDNAME: comment creation failed (database was created)" 1>&2
        exit 1
index b84680a..0c40855 100644 (file)
@@ -7,7 +7,7 @@
 # Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
 # 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
 # ----------
 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
                echo "$sqlcmd"
        fi
@@ -281,7 +281,7 @@ if [ "$handlerexists" = no ]; then
        fi
 fi
 
-sqlcmd="CREATE ${trusted}LANGUAGE \"$langname\" HANDLER \"$handler\";"
+sqlcmd="SET autocommit = 'on';CREATE ${trusted}LANGUAGE \"$langname\" HANDLER \"$handler\";"
 if [ "$showsql" = yes ]; then
        echo "$sqlcmd"
 fi
@@ -297,7 +297,7 @@ fi
 # seems best to disable public USAGE for an untrusted one.
 # ----------
 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
         echo "$sqlcmd"
     fi
index 04bbe13..83b48e5 100644 (file)
@@ -9,7 +9,7 @@
 #
 #
 # 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.
 #
@@ -253,7 +253,7 @@ SUBQUERY=
 [ "$CanAddUser" = t ] &&  QUERY="$QUERY CREATEUSER"
 [ "$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
        echo "$CMDNAME: creation of user \"$NewUser\" failed" 1>&2
        exit 1
index 8c3d9cb..9ad1b40 100644 (file)
@@ -11,7 +11,7 @@
 #
 #
 # 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'`
 
-${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
        echo "$CMDNAME: database removal failed" 1>&2
        exit 1
index 6970c93..f4b2d47 100644 (file)
@@ -7,7 +7,7 @@
 # Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
 # 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
 # ----------
-sqlcmd="DROP LANGUAGE \"$langname\";"
+sqlcmd="SET autocommit = 'on';DROP LANGUAGE \"$langname\";"
 if [ "$showsql" = yes ]; then
        echo "$sqlcmd"
 fi
@@ -256,7 +256,7 @@ if [ "$?" -ne 0 ]; then
        exit 1
 fi
 
-sqlcmd="DROP FUNCTION \"$handler\" ();"
+sqlcmd="SET autocommit = 'on';DROP FUNCTION \"$handler\" ();"
 if [ "$showsql" = yes ]; then
        echo "$sqlcmd"
 fi
index 71b072c..907a915 100644 (file)
@@ -9,7 +9,7 @@
 #
 #
 # 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.
 #
@@ -148,7 +148,7 @@ fi
 
 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
        echo "$CMDNAME: deletion of user \"$DelUser\" failed" 1>&2
index d1c5afc..8ff52e6 100644 (file)
@@ -12,7 +12,7 @@
 #
 #
 # 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
 do
         [ "$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
            echo "$CMDNAME: vacuum $table $db failed" 1>&2
            exit 1