|
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.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 $ |
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. |
@@ -121,11 +121,33 @@ case "$SRC_VERSION" in |
121 | 121 | exit 1;; |
122 | 122 | esac |
123 | 123 |
|
| 124 | +pg_resetxlog2>/dev/null |
| 125 | +if ["$?"-ne 1 ] |
| 126 | +thenecho"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 | +thenecho"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 | +thenecho"XID too high for$0.; exiting"1>&2 |
| 143 | +exit 1 |
| 144 | +fi |
124 | 145 |
|
125 | 146 | # Checking done. Ready to proceed. |
126 | 147 |
|
127 | 148 | # Execute the schema script to create everything, except modify any |
128 | 149 | # sequences with int4 maximums if we are upgrading from 7.1. |
| 150 | + |
129 | 151 | cat$SCHEMA| awk -F'''{ |
130 | 152 | if ("'"$SRC_VERSION"'" == "7.1" && |
131 | 153 | $1 == "CREATE" && |
|
169 | 191 |
|
170 | 192 | # Now vacuum each result database in case our transaction increase |
171 | 193 | # causes all the XID's to be marked with the frozen XID. |
| 194 | + |
172 | 195 | psql -d template1 -At -c"SELECT datname FROM pg_database"|whileread DB |
173 | 196 | do |
174 | 197 | echo"VACUUM;"| psql"$DB" |
|
189 | 212 |
|
190 | 213 | # we are done with SQL database access |
191 | 214 | # shutdown forces buffers to disk |
| 215 | + |
192 | 216 | pg_ctl stop |
193 | 217 | if ["$?"-ne 0 ] |
194 | 218 | thenecho"Unable to stop database server.; exiting"1>&2 |
@@ -282,30 +306,31 @@ to $NEWOID failed.; exiting" 1>&2 |
282 | 306 | fi |
283 | 307 | done |
284 | 308 |
|
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 | | -thenecho"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 | +thenecho"Unable to set new XID.; exiting"1>&2 |
| 314 | +exit 1 |
307 | 315 | fi |
308 | 316 |
|
| 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 | +thenecho"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 | +thenecho"Unable to set new checkpoint location.; exiting"1>&2 |
| 329 | +exit 1 |
| 330 | +fi |
| 331 | +
|
| 332 | +# Restart server with moved data |
| 333 | +
|
309 | 334 | pg_ctl start |
310 | 335 | if ["$?"-ne 0 ] |
311 | 336 | thenecho"Unable to restart database server.; exiting"1>&2 |
|