33# pg_upgrade: update a database without needing a full dump/reload cycle.
44# CAUTION: Read the manual page before trying to use this!
55
6- # $Header: /cvsroot/pgsql/src/bin/pg_dump/Attic/pg_upgrade,v 1.31 2002/01/1301:22:27 momjian Exp $
6+ # $Header: /cvsroot/pgsql/src/bin/pg_dump/Attic/pg_upgrade,v 1.32 2002/01/1304:55:44 momjian Exp $
77#
88# NOTE: we must be sure to update the version-checking code a few dozen lines
99# below for each new PostgreSQL release.
1313# Set this to "Y" to enable this program
1414ENABLE=" N"
1515
16+ if [" $ENABLE " != " Y" ]
17+ then
18+ echo " Sorry,$0 cannot upgrade database
19+ version$SRC_VERSION to$DST_VERSION ." 1>&2
20+ echo " The on-disk structure of tables has changed." 1>&2
21+ echo " You will need to dump and restore using pg_dumpall." 1>&2
22+ exit 1
23+ fi
24+
25+
1626# UPGRADE_VERSION is the expected old database version
1727UPGRADE_VERSION=" 7.1"
1828CUR_VERSION=" 7.2"
@@ -52,7 +62,7 @@ OLDDIR="$INFODIR/data"
5262make_dbobjoidmap ()
5363{
5464psql -d template1 -At -c" SELECT datname FROM pg_database" |
55- grep -v' ^template0$' | # template1 OK
65+ grep -v' ^template0$' |
5666while read DB
5767do
5868QUERY=" ` echo\" SELECT relname, oid
@@ -78,7 +88,8 @@ make_dbobjoidmap()
7888make_dboidmap ()
7989{
8090psql -d template1 -At -F' ' -c \
81- ' SELECT datname, oid FROM pg_database;'
91+ ' SELECT datname, oid FROM pg_database;' |
92+ grep -v' ^template0$'
8293}
8394
8495
@@ -149,24 +160,10 @@ $0 aborted." 1>&2
149160echo
150161" However, your database is version$SRC_VERSION ;
151162$0 aborted." 1>&2
152- exit 1
153- fi
154-
155- # Check that input database is of a compatible version (anything with the same
156- # physical layout of user tables and indexes should be OK). I did not write
157- # something like "$SRC_VERSION -ge $UPGRADE_VERSION" because test(1) isn't bright
158- # enough to compare dotted version strings properly. Using a case statement
159- # looks uglier but is more flexible.
160- if [" $ENABLE " != " Y" ]
161- then
162- echo " Sorry,$0 cannot upgrade database
163- version$SRC_VERSION to$DST_VERSION ." 1>&2
164- echo " The on-disk structure of tables has changed." 1>&2
165163echo " You will need to dump and restore using pg_dumpall." 1>&2
166164exit 1
167165fi
168166
169-
170167# Start server, if needed, so we can do some work.
171168if ! pg_ctl status| head -1| grep -q" is running"
172169then pg_ctl -w start
@@ -220,17 +217,18 @@ $0 aborted." 1>&2
220217if [" $SRC_VERSION " = " 7.1" ]
221218then
222219psql -d template1 -At -c" SELECT datname FROM pg_database" |
223- grep -v' ^template0$' | # template1 OK
220+ grep -v' ^template0$' |
224221while read DB
225- do
226- echo " \\ connect$DB "
222+ do
223+ # We use awk as a portable way to output a backslash
224+ awk' BEGIN {print "\\connect' " $DB " ' "}'
227225psql -d" $DB " -At -c"
228226SELECT relname
229227FROM pg_class
230228WHERE relkind = 'S';" |
231229while read SEQUENCE
232230do
233- VALUE=` psql -dtemplate1 -At -c" SELECT last_value
231+ VALUE=` psql -d" $DB " -At -c" SELECT last_value
234232 FROM\" $SEQUENCE \" ;" `
235233echo " SELECT setval ('$SEQUENCE ',$VALUE , true);"
236234done
@@ -263,7 +261,8 @@ $0 aborted." 1>&2
263261$0 aborted." 1>&2
264262exit 1
265263fi
266- echo " Plase 1 completed. Continue with the steps outlined in the$0 manual page."
264+ echo " Plase 1 completed.
265+ Continue with the steps outlined in the$0 manual page."
267266exit 0
268267fi
269268
@@ -520,6 +519,8 @@ $0 aborted." 1>&2
520519fi
521520fi
522521
522+ echo
523+ echo
523524echo " You may remove the old database files with 'rm -r pg_upgrade'."
524525
525526exit 0