Commit 5461983d authored by Bruce Momjian's avatar Bruce Momjian

Update with new features. Still disabled.

parent 9facc585
<!-- <!--
$Header: /cvsroot/pgsql/doc/src/sgml/ref/Attic/pg_upgrade.sgml,v 1.13 2001/12/08 03:24:38 thomas Exp $ $Header: /cvsroot/pgsql/doc/src/sgml/ref/Attic/pg_upgrade.sgml,v 1.14 2002/01/09 21:50:51 momjian Exp $
PostgreSQL documentation PostgreSQL documentation
--> -->
...@@ -24,7 +24,7 @@ PostgreSQL documentation ...@@ -24,7 +24,7 @@ PostgreSQL documentation
<date>1999-07-31</date> <date>1999-07-31</date>
</refsynopsisdivinfo> </refsynopsisdivinfo>
<synopsis> <synopsis>
pg_upgrade [ -f <replaceable class="parameter">filename</replaceable> ] <replaceable class="parameter">old_data_dir</replaceable> pg_upgrade -s <replaceable class="parameter">filename</replaceable> [ -d <replaceable class="parameter">filename</replaceable> ] <replaceable class="parameter">old_data_dir</replaceable>
</synopsis> </synopsis>
</refsynopsisdiv> </refsynopsisdiv>
...@@ -58,7 +58,7 @@ pg_upgrade [ -f <replaceable class="parameter">filename</replaceable> ] <replace ...@@ -58,7 +58,7 @@ pg_upgrade [ -f <replaceable class="parameter">filename</replaceable> ] <replace
<para> <para>
Then do: Then do:
<programlisting> <programlisting>
$ pg_dumpall -s >db.out $ pg_dumpall -s > schema.out
</programlisting> </programlisting>
to dump out your old database's table definitions without any data. to dump out your old database's table definitions without any data.
</para> </para>
...@@ -108,7 +108,7 @@ $ make install ...@@ -108,7 +108,7 @@ $ make install
Change your working directory to the Change your working directory to the
pgsql main directory, and type: pgsql main directory, and type:
<programlisting> <programlisting>
$ pg_upgrade -f db.out data.old $ pg_upgrade -s schema.out -d data.out data.old
</programlisting> </programlisting>
The program will do some checking to make sure everything is properly The program will do some checking to make sure everything is properly
configured, and will run your db.out script to recreate all the databases configured, and will run your db.out script to recreate all the databases
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
# pg_upgrade: update a database without needing a full dump/reload cycle. # pg_upgrade: update a database without needing a full dump/reload cycle.
# CAUTION: read the manual page before trying to use this! # CAUTION: read the manual page before trying to use this!
# $Header: /cvsroot/pgsql/src/bin/pg_dump/Attic/pg_upgrade,v 1.19 2002/01/09 16:08:54 momjian Exp $ # $Header: /cvsroot/pgsql/src/bin/pg_dump/Attic/pg_upgrade,v 1.20 2002/01/09 21:50:52 momjian Exp $
# #
# NOTE: we must be sure to update the version-checking code a few dozen lines # NOTE: we must be sure to update the version-checking code a few dozen lines
# below for each new PostgreSQL release. # below for each new PostgreSQL release.
...@@ -12,24 +12,31 @@ TMPFILE="/tmp/pgupgrade.$$" ...@@ -12,24 +12,31 @@ TMPFILE="/tmp/pgupgrade.$$"
trap "rm -f $TMPFILE" 0 1 2 3 15 trap "rm -f $TMPFILE" 0 1 2 3 15
if [ "$#" -eq 0 ] SCHEMA=""
then echo "Usage: $0 -f inputfile old_data_dir" 1>&2 DATA=""
exit 1 while [ "$#" -gt 1 ]
fi do
if [ "X$1" = "X-s" ]
if [ "X$1" = "X-f" ] then SCHEMA="$2"
then INPUT="$2" if [ ! -s "$SCHEMA" ]
shift 2 then echo "$SCHEMA does not exist" 1>&2
if [ ! -f "$INPUT" ] exit 1
then echo "$INPUT does not exist" 1>&2 fi
shift 2
elif [ "X$1" = "X-d" ]
then DATA="$2"
if [ ! -s "$DATA" ]
then echo "$DATA does not exist" 1>&2
exit 1
fi
shift 2
else echo "Usage: $0 -s schema_dump [ -d data_dump ] old_data_dir" 1>&2
exit 1 exit 1
fi fi
else echo "Usage: $0 -f inputfile old_data_dir" 1>&2 done
exit 1
fi
if [ "$#" -ne 1 ] if [ "$#" -ne 1 -o ! "$SCHEMA" ]
then echo "Usage: $0 -f inputfile old_data_dir" 1>&2 then echo "Usage: $0 -s schema_dump [ -d data_dump ] old_data_dir" 1>&2
exit 1 exit 1
fi fi
...@@ -38,8 +45,7 @@ OLDDIR="$1" ...@@ -38,8 +45,7 @@ OLDDIR="$1"
# check things # check things
if [ ! -d "./data" ] if [ ! -d "./data" ]
then echo "`basename $0` must be run from the directory containing then echo "`basename $0` must be run from the directory containing the database directory \`data\' (`dirname $PGDATA`.)" 1>&2
the database directory \`data\' (`dirname $PGDATA`.)" 1>&2
echo "You must have run initdb to create the template1 database." 1>&2 echo "You must have run initdb to create the template1 database." 1>&2
exit 1 exit 1
fi fi
...@@ -80,6 +86,12 @@ SRCVERSION=`cat ./$OLDDIR/PG_VERSION` ...@@ -80,6 +86,12 @@ SRCVERSION=`cat ./$OLDDIR/PG_VERSION`
# MYVERSION is the expected output database version # MYVERSION is the expected output database version
MYVERSION="7.1" MYVERSION="7.1"
if [ "$SRCVERSION" = "7.1" -a ! "$DATA" ]
then echo "$0 requires a full data dump file to upgrade from version $SRCVERSION." 1>&2
echo "Use the '-d' parameter to specify the dump file" 1>&2
exit 1
fi
if [ "$DESTVERSION" != "$MYVERSION" -a "$DESTVERSION" != "$SRCVERSION" ] if [ "$DESTVERSION" != "$MYVERSION" -a "$DESTVERSION" != "$SRCVERSION" ]
then echo "$0 is for PostgreSQL version $MYVERSION, but ./data/PG_VERSION contains $DESTVERSION." 1>&2 then echo "$0 is for PostgreSQL version $MYVERSION, but ./data/PG_VERSION contains $DESTVERSION." 1>&2
echo "Did you run initdb for version $MYVERSION?" 1>&2 echo "Did you run initdb for version $MYVERSION?" 1>&2
...@@ -103,56 +115,65 @@ esac ...@@ -103,56 +115,65 @@ esac
# OK, ready to proceed. # OK, ready to proceed.
# Execute the input script to create everything, except that we remove # Execute the schema script to create everything, except modify any
# any COPY statements, except for the ones that load pg_shadow/pg_group. # sequences with int4 maximums if we are upgrading from 7.1.
# There shouldn't be any others in there anyway... cat $SCHEMA | awk -F' ' '{
if ("'"$SRCVERSION"'" == "7.1" &&
cat $INPUT | awk ' { $1 == "CREATE" &&
if (tolower($1) == "copy" && $2 == "SEQUENCE" &&
$2 != "pg_shadow" && ($9 >= 2147483646 && # handle OS round
$2 != "pg_group") ($9 <= 2147483648))
while (getline $0 > 0 && $0 != "\\.") {
; for(i=1; i < NF; i++)
if (i != 9)
printf "%s ", $i;
else
printf "%s ", "9223372036854775807";
print;
}
else print $0; else print $0;
}' > $TMPFILE }' |
psql "template1"
psql "template1" < $TMPFILE
if [ $? -ne 0 ] if [ $? -ne 0 ]
then echo "There were errors in the input script $INPUT. then echo "There were errors in the input script $SCHEMA.
$0 aborted." 1>&2 $0 aborted." 1>&2
exit 1 exit 1
fi fi
echo "Input script $INPUT complete, fixing row commit statuses..."
if [ "$SRCVERSION" != "7.1" ]
# Now vacuum each result database to mark all system-table rows as committed, then echo "Input script $SCHEMA complete, fixing row commit statuses..."
# because when pg_clog is replaced with the saved version, the transaction else echo "Input script $SCHEMA complete, setting int8 sequences..."
# statuses will no longer match the data. VACUUM will force the on-row
# status flags to the right value so that pg_clog will not matter anymore. # Set all the sequence counters because they are not brought over
# Note: we used to try to do this as part of the previous step, but that # in the schema dump, and the old 7.1 sequences where int4 in size
# risks permissions problems if VACUUM is run as the wrong user. # so bringing over the file wouldn't help us anyway.
# Note: the initial VACUUM does template1, then we do everything else. cat $DATA | awk '$0 == "\\connect " || "SELECT setval (" \
{print $0;}' |
cat $INPUT | awk 'BEGIN { print "VACUUM;" } psql "template1"
{
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" < $TMPFILE
if [ $? -ne 0 ] if [ $? -ne 0 ]
then echo "There were errors in the vacuuming step. then echo "There were errors in the input script $SCHEMA.
$0 aborted." 1>&2 $0 aborted." 1>&2
exit 1 exit 1
fi fi
echo "Int8 sequences set, fixing row commit statuses..."
fi
# Now vacuum each result database in case our transaction increase
# causes all the XID's to be marked with the frozen XID.
psql -l | while read DB
do
echo "VACUUM;" | psql "$DB"
if [ $? -ne 0 ]
then echo "There were errors during VACUUM.
$0 aborted." 1>&2
exit 1
fi
done
# should be pretty small file # should be pretty small file
pg_dumpall -s > $TMPFILE 2>/dev/null pg_dumpall -s > $TMPFILE 2>/dev/null
...@@ -161,7 +182,7 @@ pg_ctl stop ...@@ -161,7 +182,7 @@ pg_ctl stop
echo "Commit fixes complete, moving data files..." echo "Commit fixes complete, moving data files..."
cat "$INPUT" | while read LINE cat "$SCHEMA" | while read LINE
do do
if /bin/echo "$LINE" | grep -q "^\\\\connect " if /bin/echo "$LINE" | grep -q "^\\\\connect "
then OLDDB="$DB" then OLDDB="$DB"
...@@ -176,7 +197,7 @@ do ...@@ -176,7 +197,7 @@ do
if echo "$LINE" | grep -q "^-- TOC Entry ID [0-9]* (OID " if echo "$LINE" | grep -q "^-- TOC Entry ID [0-9]* (OID "
then OID="`echo \"$LINE\" | cut -d' ' -f7 | tr -d ')'`" then OID="`echo \"$LINE\" | cut -d' ' -f7 | tr -d ')'`"
fi fi
if echo "$LINE" | grep -q "^-- Name: [^ ]* Type: TABLE " if echo "$LINE" | egrep -q "^-- Name: [^ ]* Type: (TABLE|INDEX) "
then TABLE="`echo \"$LINE\" | cut -d' ' -f3`" then TABLE="`echo \"$LINE\" | cut -d' ' -f3`"
# skip system tables # skip system tables
if [ "`echo \"$TABLE\" | cut -c 1-3`" = "pg_" ] if [ "`echo \"$TABLE\" | cut -c 1-3`" = "pg_" ]
...@@ -194,7 +215,8 @@ do ...@@ -194,7 +215,8 @@ do
{print $0 >> "/tmp/x"; {print $0 >> "/tmp/x";
print $3 >> "/tmp/x"; print $3 >> "/tmp/x";
print newdb," ", newoid >> "/tmp/x"} print newdb," ", newoid >> "/tmp/x"}
$0 ~ /^-- Name: [^ ]* Type: TABLE / && \ ($0 ~ /^-- Name: [^ ]* Type: TABLE / && \
$0 ~ /^-- Name: [^ ]* Type: INDEX /) && \
newdb == "'"$DB"'" && \ newdb == "'"$DB"'" && \
$3 == "'"$TABLE"'" \ $3 == "'"$TABLE"'" \
{ ret=newoid; exit} { ret=newoid; exit}
...@@ -229,6 +251,18 @@ do ...@@ -229,6 +251,18 @@ do
fi fi
done done
# set max transaction id, check < 2gig
# 7.1 has non-compressed log file format
if [ "$SRCVERSION" = "7.1" ]
# pg_log is oid 1269 in 7.1
LOGSIZE=`ls -l "$OLDDIR"/global/1269 "$OLDDIR"/global/1269.* 2>/dev/null |
awk -F' *' '
BEGIN {sum=0;}
{sum += $5;}
END {print sum;}'`
fi
echo "You must stop/start the postmaster before doing anything else." echo "You must stop/start the postmaster before doing anything else."
echo "You may remove the $OLDDIR directory with 'rm -r $OLDDIR'." echo "You may remove the $OLDDIR directory with 'rm -r $OLDDIR'."
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment