Commit 2913d655 authored by Bruce Momjian's avatar Bruce Momjian

Preserver pg_log and pg_variable in upgrade. Cleanups.

parent a753e5d1
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
trap "rm -f /tmp/$$" 0 1 2 3 15 trap "rm -f /tmp/$$" 0 1 2 3 15
if [ "$#" -eq 0 ] if [ "$#" -eq 0 ]
then echo "Usage: $0 [-f inputfile] old_data_dir database" 1>&2 then echo "Usage: $0 [-f inputfile] old_data_dir" 1>&2
exit 1 exit 1
fi fi
...@@ -16,13 +16,12 @@ then INPUT="$2" ...@@ -16,13 +16,12 @@ then INPUT="$2"
else INPUT="" else INPUT=""
fi fi
if [ "$#" -ne 2 ] if [ "$#" -ne 1 ]
then echo "Usage: $0 [-f input_file] old_data_dir database" 1>&2 then echo "Usage: $0 [-f inputfile] old_data_dir" 1>&2
exit 1 exit 1
fi fi
OLDDIR="$1" OLDDIR="$1"
DATABASE="$2"
# check things # check things
...@@ -36,8 +35,8 @@ then echo "You must rename your old /data directory to /$OLDDIR and run initdb." ...@@ -36,8 +35,8 @@ then echo "You must rename your old /data directory to /$OLDDIR and run initdb."
exit 1 exit 1
fi fi
if [ ! -d "./$OLDDIR/data/base/$DATABASE" ] if [ ! -d "./$OLDDIR/base/template1" ]
then echo "There is not database $DATABASE in ./$OLDDIR/data/base." 1>&2 then echo "There is not database template1 in ./$OLDDIR/base." 1>&2
exit 1 exit 1
fi fi
...@@ -53,17 +52,12 @@ fi ...@@ -53,17 +52,12 @@ fi
# do I need to create a database? # do I need to create a database?
if [ "$DATABASE" != "template1" ] # remove any COPY statements
then echo "Dropping and recreating database $DATABASE." 1>&2 # we don't even need pgdump_oid because we are moving pg_variable
destroydb "$DATABASE" >/dev/null 2>&1 # then shouldn't be in there anyway
createdb "$DATABASE"
fi
# remove any COPY statements, preserve pgdump_oid setting from pg_dumpall
cat $INPUT | awk ' { cat $INPUT | awk ' {
if (toupper($0) ~ /^COPY / && if (toupper($0) ~ /^COPY /)
toupper($0) !~ /^COPY[ ]*PGDUMP_OID/ )
while (getline $0 > 0 && $0 != "\\.") while (getline $0 > 0 && $0 != "\\.")
; ;
else print $0; else print $0;
...@@ -71,16 +65,14 @@ cat $INPUT | awk ' { ...@@ -71,16 +65,14 @@ cat $INPUT | awk ' {
#create empty tables/indexes #create empty tables/indexes
psql "$DATABASE" <"/tmp/$$" psql "template1" <"/tmp/$$"
set -x
for DIR in data/base/* for DIR in data/base/*
do do
BASEDIR="`basename $DIR`" BASEDIR="`basename $DIR`"
if [ -d "$DIR" -a \ if [ -d "$DIR" -a \
-d "$OLDDIR/$DIR" -a \ -d "$OLDDIR/base/$BASEDIR" -a \( "$BASEDIR" != "template1" \) ]
\( "$DATABASE" = "$BASEDIR" -o "$DATABASE" = "template1" \) ] then for FILE in $OLDDIR/base/$BASEDIR/*
then for FILE in $OLDDIR/$DIR/*
do do
BASEFILE="`basename $FILE`" BASEFILE="`basename $FILE`"
if [ `expr "$BASEFILE" : "pg_"` -ne 3 -a \ if [ `expr "$BASEFILE" : "pg_"` -ne 3 -a \
...@@ -91,4 +83,7 @@ do ...@@ -91,4 +83,7 @@ do
fi fi
done done
mv $OLDDIR/pg_log data
mv $OLDDIR/pg_variable data
echo "You may removed the $OLDDIR directory with 'rm -r $OLDDIR'." echo "You may removed the $OLDDIR directory with 'rm -r $OLDDIR'."
.\" This is -*-nroff-*- .\" This is -*-nroff-*-
.\" XXX standard disclaimer belongs here.... .\" XXX standard disclaimer belongs here....
.\" $Header: /cvsroot/pgsql/src/man/Attic/pg_upgrade.1,v 1.3 1998/08/30 13:14:00 momjian Exp $ .\" $Header: /cvsroot/pgsql/src/man/Attic/pg_upgrade.1,v 1.4 1998/08/31 04:32:18 momjian Exp $
.TH pg_upgrade UNIX 1/20/96 PostgreSQL PostgreSQL .TH pg_upgrade UNIX 1/20/96 PostgreSQL PostgreSQL
.SH NAME .SH NAME
pg_upgrade - allows upgrade from a previous release without reloading data pg_upgrade - allows upgrade from a previous release without reloading data
.SH SYNOPSIS .SH SYNOPSIS
.BR pg_upgrade .BR pg_upgrade
[-f input_file] old_data_dir database [-f input_file] old_data_dir
.SH DESCRIPTION .SH DESCRIPTION
.IR "pg_upgrade" .IR "pg_upgrade"
is a utility for upgrading from a previous PostgreSQL release is a utility for upgrading from a previous PostgreSQL release
...@@ -15,27 +15,28 @@ First, to be safe, back up your data directory. ...@@ -15,27 +15,28 @@ First, to be safe, back up your data directory.
Then, use: Then, use:
.nf .nf
pg_dumpall -s -o >db.out pg_dumpall -s >db.out
.fi .fi
to dump out your old database definitions without data, to dump out your old database definitions without any data.
while perserving the max system oid. Stop the postmaster and all backends.
.PP .PP
Then rename (using Then rename (using
.IR mv ) .IR mv )
your old pgsql /data directory to /data.old and do a your old pgsql /data directory to /data.old and do a
.IR "make install" .IR "make install"
to install the new binaries. to install the new binaries.
Then run Run
.IR initdb .IR initdb
to create a new to create a new
.IR template1 .IR template1
database containing the system tables for the new release. database containing the system tables for the new release.
Start the new postmaster,
.IR cd .IR cd
to the pgsql main directory, and type: to the pgsql main directory, and type:
.nf .nf
pg_upgrade -f db.out data.old template1 pg_upgrade -f db.out data.old
.fi .fi
The system will do some checking to make sure everything is properly The system will do some checking to make sure everything is properly
...@@ -45,13 +46,9 @@ script to create all the databases and tables you had, but with no data. ...@@ -45,13 +46,9 @@ script to create all the databases and tables you had, but with no data.
It will then move the data files from /data.old into the proper It will then move the data files from /data.old into the proper
.IR /data .IR /data
directory. directory.
You can then start the You can then check out the data.
.IR postmaster
and check out the data.
You can delete the You can delete the
.IR /data.old .IR /data.old
directory when you are finished. directory when you are finished.
.PP
It can also be used for individual databases.
.SH "SEE ALSO" .SH "SEE ALSO"
pg_dumpall(1). pg_dumpall(1).
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