aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2000-05-05 03:08:20 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2000-05-05 03:08:20 +0000
commit3a69c316cc91d0561ef4ece858433979bc1c7179 (patch)
tree16a79a8c78c6889c3a54844b5661cb7cd6859f68 /src
parent3d1461802e80709a4b16618dc0a7f745917c1e3b (diff)
downloadpostgresql-3a69c316cc91d0561ef4ece858433979bc1c7179.tar.gz
postgresql-3a69c316cc91d0561ef4ece858433979bc1c7179.zip
Accept pg_group as well as pg_shadow data from dumpall script.
Rearrange handling of VACUUMs so that they are certain to be executed as superuser not some random user; also, do not forget to vacuum template1 itself.
Diffstat (limited to 'src')
-rwxr-xr-xsrc/bin/pg_dump/pg_upgrade65
1 files changed, 45 insertions, 20 deletions
diff --git a/src/bin/pg_dump/pg_upgrade b/src/bin/pg_dump/pg_upgrade
index 5d03e20ca0d..4ee00cbe2fb 100755
--- a/src/bin/pg_dump/pg_upgrade
+++ b/src/bin/pg_dump/pg_upgrade
@@ -3,15 +3,17 @@
# pg_upgrade: update a database without needing a full dump/reload cycle.
# CAUTION: read the manual page before trying to use this!
-# $Header: /cvsroot/pgsql/src/bin/pg_dump/Attic/pg_upgrade,v 1.14 2000/02/23 15:46:12 momjian Exp $
+# $Header: /cvsroot/pgsql/src/bin/pg_dump/Attic/pg_upgrade,v 1.15 2000/05/05 03:08:20 tgl Exp $
#
# NOTE: we must be sure to update the version-checking code a few dozen lines
# below for each new PostgreSQL release.
-trap "rm -f /tmp/$$" 0 1 2 3 15
+TMPFILE="/tmp/pgupgrade.$$"
+
+trap "rm -f $TMPFILE" 0 1 2 3 15
if [ "$#" -eq 0 ]
-then echo "Usage: $0 [-f inputfile] old_data_dir" 1>&2
+then echo "Usage: $0 -f inputfile old_data_dir" 1>&2
exit 1
fi
@@ -22,11 +24,12 @@ then INPUT="$2"
then echo "$INPUT does not exist" 1>&2
exit 1
fi
-else INPUT=""
+else echo "Usage: $0 -f inputfile old_data_dir" 1>&2
+ exit 1
fi
if [ "$#" -ne 1 ]
-then echo "Usage: $0 [-f inputfile] old_data_dir" 1>&2
+then echo "Usage: $0 -f inputfile old_data_dir" 1>&2
exit 1
fi
@@ -101,36 +104,57 @@ esac
# OK, ready to proceed.
-# Remove any COPY statements, except for the one that loads pg_shadow.
+# Execute the input script to create everything, except that we remove
+# any COPY statements, except for the ones that load pg_shadow/pg_group.
# There shouldn't be any others in there anyway...
-# Also marks rows as committed because when pg_log is replaced with
-# the saved version, the transaction statuses may be wrong, so
-# vacuum sets the on-row status to the proper value.
cat $INPUT | awk ' {
- if (toupper($1) == "COPY" && $2 != "pg_shadow")
+ if (tolower($1) == "copy" &&
+ $2 != "pg_shadow" &&
+ $2 != "pg_group")
while (getline $0 > 0 && $0 != "\\.")
;
- else if (tolower($1) == "\\connect" &&
- tolower($2) == "template1")
- printf "VACUUM;\n%s\n", $0;
else print $0;
- }' >/tmp/$$
+ }' >$TMPFILE
+
+psql "template1" <$TMPFILE
+
+if [ $? -ne 0 ]
+then echo "There were errors in the input script $INPUT.
+$0 aborted." 1>&2
+ exit 1
+fi
-# We need to vacuum the last database too
-echo "VACUUM;" >>/tmp/$$
+echo "Input script $INPUT complete, fixing row commit statuses..."
-# Create and vacuum empty tables/indexes
+# Now vacuum each result database to mark all system-table rows as committed,
+# because when pg_log is replaced with the saved version, the transaction
+# statuses will no longer match the data. VACUUM will force the on-row
+# status flags to the right value so that pg_log will not matter anymore.
+# Note: we used to try to do this as part of the previous step, but that
+# risks permissions problems if VACUUM is run as the wrong user.
+# Note: the initial VACUUM does template1, then we do everything else.
+
+cat $INPUT | awk 'BEGIN { print "VACUUM;" }
+ {
+ if (tolower($1) == "copy")
+ while (getline $0 > 0 && $0 != "\\.")
+ ;
+ else if (tolower($1) == "\\connect" &&
+ $2 != "-" &&
+ $2 != "template1")
+ printf "\\connect %s\nVACUUM;\n", $2;
+ }' >$TMPFILE
-psql "template1" <"/tmp/$$"
+psql "template1" <$TMPFILE
if [ $? -ne 0 ]
-then echo "There were errors in the input script $INPUT.
+then echo "There were errors in the vacuuming step.
$0 aborted." 1>&2
exit 1
fi
-echo "Input script $INPUT complete, moving data files..."
+echo "Commit fixes complete, moving data files..."
for DIR in data/base/*
do
@@ -153,4 +177,5 @@ mv -f $OLDDIR/pg_variable data
echo "You must stop/start the postmaster before doing anything else."
echo "You may remove the $OLDDIR directory with 'rm -r $OLDDIR'."
+
exit 0