3
3
# pg_upgrade: update a database without needing a full dump/reload cycle.
4
4
# CAUTION: read the manual page before trying to use this!
5
5
6
- # $Header: /cvsroot/pgsql/src/bin/pg_dump/Attic/pg_upgrade,v 1.20 2002/01/09 21:50:52 momjian Exp $
6
+ # $Header: /cvsroot/pgsql/src/bin/pg_dump/Attic/pg_upgrade,v 1.21 2002/01/10 03:05:48 momjian Exp $
7
7
#
8
8
# NOTE: we must be sure to update the version-checking code a few dozen lines
9
9
# below for each new PostgreSQL release.
164
164
165
165
# Now vacuum each result database in case our transaction increase
166
166
# causes all the XID's to be marked with the frozen XID.
167
- psql -l | while read DB
167
+ psql -d template1 -At -c " SELECT datname FROM pg_database " | while read DB
168
168
do
169
169
echo " VACUUM;" | psql" $DB "
170
170
if [$? -ne 0 ]
@@ -179,12 +179,16 @@ pg_dumpall -s > $TMPFILE 2>/dev/null
179
179
180
180
# flush buffers to disk
181
181
pg_ctl stop
182
+ if [" $? " -ne 0 ]
183
+ then echo " Unable to stop database server.; exiting" 1>&2
184
+ exit 1
185
+ fi
182
186
183
187
echo " Commit fixes complete, moving data files..."
184
188
185
189
cat" $SCHEMA " | while read LINE
186
190
do
187
- if /bin/echo" $LINE " | grep -q" ^\\\\ connect"
191
+ if /bin/echo" $LINE " | grep -q" ^\\\\ connect[^]*$ "
188
192
then OLDDB=" $DB "
189
193
DB=" ` /bin/echo\" $LINE \" | cut -d' ' -f2` "
190
194
if [" $DB " = " -" ]
251
255
fi
252
256
done
253
257
254
- # set max transaction id, check < 2gig
255
-
256
258
# 7.1 has non-compressed log file format
257
259
if [" $SRCVERSION " = " 7.1" ]
258
- # pg_log is oid 1269 in 7.1
259
- LOGSIZE=` ls -l" $OLDDIR " /global/1269" $OLDDIR " /global/1269.* 2> /dev/null|
260
- awk -F' *' '
261
- BEGIN {sum=0;}
262
- {sum += $5;}
263
- END{print sum;}' `
260
+ then
261
+ # pg_log is oid 1269 in 7.1
262
+ LOGSIZE=` ls -l" $OLDDIR " /global/1269" $OLDDIR " /global/1269.* 2> /dev/null|
263
+ awk -F' *' '
264
+ BEGIN {sum=0;}
265
+ {sum += $5;}
266
+ END{print sum;}' `
267
+
268
+ # check < 2gig
269
+
270
+ # set max transaction id
271
+
272
+ else
273
+ # how to handle 7.2?
274
+ rm -r data/pg_clog&&
275
+ mv" $OLDDIR " /data/pg_clog data/pg_clog&&
276
+ mv" $OLDDIR " /data/global/pg_control data/global/pg_control
277
+ if [" $? " -ne 0 ]
278
+ then echo " Moving of transaction and control files failed.; exiting" 1>&2
279
+ exit 1
280
+ fi
281
+ fi
282
+
283
+ pg_ctl start
284
+ if [" $? " -ne 0 ]
285
+ then echo " Unable to restart database server.; exiting" 1>&2
286
+ exit 1
264
287
fi
265
288
266
- echo " You must stop/start the postmaster before doing anything else."
267
289
echo " You may remove the$OLDDIR directory with 'rm -r$OLDDIR '."
268
290
269
291
exit 0