Skip to content

Commit 5370cd6

Browse files
committed
More improvements using pg_resetxlog. still disabled.
1 parent 9ab1872 commit 5370cd6

File tree

1 file changed

+48
-23
lines changed

1 file changed

+48
-23
lines changed

src/bin/pg_dump/pg_upgrade

Lines changed: 48 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
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.22 2002/01/10 04:58:19 momjian Exp $
6+
# $Header: /cvsroot/pgsql/src/bin/pg_dump/Attic/pg_upgrade,v 1.23 2002/01/11 00:27:42 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.
@@ -121,11 +121,33 @@ case "$SRC_VERSION" in
121121
exit 1;;
122122
esac
123123

124+
pg_resetxlog 2>/dev/null
125+
if [ "$?" -ne 1 ]
126+
then echo "Unable to find pg_resetxlog in path.
127+
Install it from pgsql/contrib/pg_resetxlog and continue.; exiting" 1>&2
128+
exit 1
129+
fi
130+
131+
if ! pg_resetxlog -x | grep -q XID
132+
then echo "Old version of pg_resetxlog found in path.
133+
Install a newer version from pgsql/contrib/pg_resetxlog and continue.; exiting" 1>&2
134+
exit 1
135+
fi
136+
137+
# We need a high XID number so there is 1 gig gap in XID numbers so the
138+
# moved-over rows can be frozen on next VACUUM.
139+
140+
XID=`pg_resetxlog -n "$OLDDIR" | grep "NextXID" | awk -F' *' '{print $4}'`
141+
if [ "$SRC_VERSION" = "7.1" -a "$XID" -gt 2000000000 ]
142+
then echo "XID too high for $0.; exiting" 1>&2
143+
exit 1
144+
fi
124145

125146
# Checking done. Ready to proceed.
126147

127148
# Execute the schema script to create everything, except modify any
128149
# sequences with int4 maximums if we are upgrading from 7.1.
150+
129151
cat $SCHEMA | awk -F' ' '{
130152
if ("'"$SRC_VERSION"'" == "7.1" &&
131153
$1 == "CREATE" &&
@@ -169,6 +191,7 @@ fi
169191

170192
# Now vacuum each result database in case our transaction increase
171193
# causes all the XID's to be marked with the frozen XID.
194+
172195
psql -d template1 -At -c "SELECT datname FROM pg_database" | while read DB
173196
do
174197
echo "VACUUM;" | psql "$DB"
@@ -189,6 +212,7 @@ fi
189212

190213
# we are done with SQL database access
191214
# shutdown forces buffers to disk
215+
192216
pg_ctl stop
193217
if [ "$?" -ne 0 ]
194218
then echo "Unable to stop database server.; exiting" 1>&2
@@ -282,30 +306,31 @@ to $NEWOID failed.; exiting" 1>&2
282306
fi
283307
done
284308

285-
# 7.1 has non-compressed log file format
286-
if [ "$SRC_VERSION" = "7.1" ]
287-
then
288-
# pg_log is oid 1269 in 7.1
289-
LOGSIZE=`ls -l "$OLDDIR"/global/1269 "$OLDDIR"/global/1269.* 2>/dev/null |
290-
awk -F' *' '
291-
BEGIN {sum=0;}
292-
{sum += $5;}
293-
END {print sum;}'`
294-
295-
# check < 2gig
296-
297-
# set max transaction id
298-
299-
else
300-
rm -r data/pg_clog &&
301-
mv "$OLDDIR"/data/pg_clog data/pg_clog &&
302-
mv "$OLDDIR"/data/global/pg_control data/global/pg_control
303-
if [ "$?" -ne 0 ]
304-
then echo "Moving of transaction and control files failed.; exiting" 1>&2
305-
exit 1
306-
fi
309+
310+
# Set this so the next VACUUM sets the old row XID's as "frozen"
311+
pg_resetxlog -x "$XID" data
312+
if [ "$?" -ne 0 ]
313+
then echo "Unable to set new XID.; exiting" 1>&2
314+
exit 1
307315
fi
308316

317+
# set last checkpoint location from old database
318+
319+
CHKPOINT=`pg_resetxlog -n "$OLDDIR" | grep "checkpoint location" |
320+
awk -F' *' '{print $4}'`
321+
if [ "$CHKPOINT" = "" ]
322+
then echo "Unable to get old checkpoint location.; exiting" 1>&2
323+
exit 1
324+
fi
325+
326+
pg_resetxlog -l `echo "$CHKPOINT | tr '/' ' '` data
327+
if [ "$?" -ne 0 ]
328+
then echo "Unable to set new checkpoint location.; exiting" 1>&2
329+
exit 1
330+
fi
331+
332+
# Restart server with moved data
333+
309334
pg_ctl start
310335
if [ "$?" -ne 0 ]
311336
then echo "Unable to restart database server.; exiting" 1>&2

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy