Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3bb7755

Browse files
committed
Sync up.
1 parent5ab0ad5 commit3bb7755

File tree

2 files changed

+146
-24
lines changed

2 files changed

+146
-24
lines changed

‎doc/src/sgml/ref/pg_upgrade.sgml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/ref/Attic/pg_upgrade.sgml,v 1.17 2002/01/1106:08:02 momjian Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/ref/Attic/pg_upgrade.sgml,v 1.18 2002/01/1120:34:14 momjian Exp $
33
PostgreSQL documentation
44
-->
55

@@ -154,7 +154,8 @@ $ pg_upgrade -s schema.out data.old
154154

155155
<note>
156156
<para>
157-
pg_upgrade does not migrate large objects.
157+
pg_upgrade does not handle custom tables/indexes/sequences in template1.
158+
It does handle other template1 object customizations.
158159
</para>
159160
</note>
160161
</procedure>

‎src/bin/pg_dump/pg_upgrade

Lines changed: 143 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,23 @@
55

66
#set -x
77

8-
# $Header: /cvsroot/pgsql/src/bin/pg_dump/Attic/pg_upgrade,v 1.28 2002/01/11 06:48:41 momjian Exp $
8+
# Set this to "Y" to enable this program
9+
ENABLE="N"
10+
11+
# UPGRADE_VERSION is the expected old database version
12+
UPGRADE_VERSION="7.1"
13+
14+
# Hard-wired from pg_class in 7.1. I wish there was another way.
15+
# Are these fixed values for that release? XXX
16+
SRC_LARGEOBJECT_OID=16948
17+
SRC_LARGEOBJECT_IDX_OID=17148
18+
19+
# $Header: /cvsroot/pgsql/src/bin/pg_dump/Attic/pg_upgrade,v 1.29 2002/01/11 20:34:14 momjian Exp $
920
#
1021
# NOTE: we must be sure to update the version-checking code a few dozen lines
1122
# below for each new PostgreSQL release.
1223

13-
TMPFILE="/tmp/pgupgrade.$$"
14-
15-
trap"rm -f$TMPFILE" 0 1 2 3 15
24+
trap"rm -f /tmp/$$.*" 0 1 2 3 15
1625

1726
SCHEMA=""
1827
while ["$#"-gt 1 ]
@@ -71,15 +80,13 @@ thenecho "Cannot read ./$OLDDIR/PG_VERSION --- something is wrong." 1>&2
7180
fi
7281

7382
# Get the actual versions seen in the data dirs.
83+
7484
DEST_VERSION=`cat ./data/PG_VERSION`
7585
SRC_VERSION=`cat ./$OLDDIR/PG_VERSION`
7686

7787
# Check for version compatibility.
7888
# This code will need to be updated/reviewed for each new PostgreSQL release.
7989

80-
# UPGRADE_VERSION is the expected output database version
81-
UPGRADE_VERSION="7.1"
82-
8390
if ["$DEST_VERSION"!="$UPGRADE_VERSION"-a"$DEST_VERSION"!="$SRC_VERSION" ]
8491
thenecho"`basename$0` is for PostgreSQL version$UPGRADE_VERSION, but ./data/PG_VERSION contains$DEST_VERSION."1>&2
8592
echo"Did you run initdb for version$UPGRADE_VERSION?"1>&2
@@ -92,13 +99,18 @@ fi
9299
# enough to compare dotted version strings properly. Using a case statement
93100
# looks uglier but is more flexible.
94101

95-
case"$SRC_VERSION"in
96-
# 7.2) ;;
97-
*)echo"Sorry,`basename$0` cannot upgrade database version$SRC_VERSION to$DEST_VERSION."1>&2
98-
echo"The on-disk structure of tables has changed."1>&2
99-
echo"You will need to dump and restore using pg_dumpall."1>&2
100-
exit 1;;
101-
esac
102+
if ["$ENABLE"!="Y" ]
103+
then
104+
case"$SRC_VERSION"in
105+
# 7.2) ;;
106+
*)echo"Sorry,`basename$0` cannot upgrade database version$SRC_VERSION to$DEST_VERSION."1>&2
107+
echo"The on-disk structure of tables has changed."1>&2
108+
echo"You will need to dump and restore using pg_dumpall."1>&2
109+
exit 1;;
110+
esac
111+
fi
112+
113+
# check for proper pg_resetxlog version
102114

103115
pg_resetxlog2>/dev/null
104116
# file not found status is normally 127, not 1
@@ -117,13 +129,27 @@ fi
117129
# If the XID is > 2 billion, 7.1 database will have non-frozen XID's in
118130
# low numbers, and 7.2 will think they are in the future --- bad.
119131

120-
XID=`pg_resetxlog -n"$OLDDIR"| grep"NextXID"| awk -F' *''{print $4}'`
132+
SRC_XID=`pg_resetxlog -n"$OLDDIR"| grep"NextXID"| awk -F' *''{print $4}'`
121133
if ["$SRC_VERSION"="7.1"-a"$XID"-gt 2000000000 ]
122134
thenecho"XID too high for$0.; exiting"1>&2
123135
exit 1
124136
fi
137+
DST_XID=`pg_resetxlog -n data| grep"NextXID"| awk -F' *''{print $4}'`
125138

139+
# compare locales to make sure they match
140+
141+
pg_resetxlog -n"$OLDDIR"| grep"^LC_"> /tmp/$$.0
142+
pg_resetxlog -n data| grep"^LC_"> /tmp/$$.1
143+
if! diff /tmp/$$.0 /tmp/$$.1>/dev/null
144+
thenecho"Locales do not match between the two versions.; exiting"1>&2
145+
exit 1
146+
fi
147+
148+
149+
###################################
126150
# Checking done. Ready to proceed.
151+
###################################
152+
127153

128154
# Execute the schema script to create everything
129155

@@ -149,12 +175,27 @@ fi
149175

150176
# Used for scans looking for a database/table name match
151177
# New oid is looked up
152-
pg_dumpall -s>$TMPFILE2>/dev/null
178+
pg_dumpall -s>/tmp/$$.32>/dev/null
153179
if ["$?"-ne 0 ]
154180
thenecho"Unable to dump schema of new database.; exiting"1>&2
155181
exit 1
156182
fi
157183

184+
# Get pg_largeobject oids for movement
185+
186+
DST_LARGEOBJECT_OID=`psql -d template1 -At -c"SELECT oid from pg_class where relname = 'pg_largeobject';"`
187+
DST_LARGEOBJECT_IDX_OID=`psql -d template1 -At -c"SELECT oid from pg_class where relname = 'pg_largeobject_loid_pn_index';"`
188+
if ["$LARGEOBJECT_OID"-eq 0-o"$LARGEOBJECT_IDX_OID"-eq 0 ]
189+
thenecho"Unable to find large object oid.; exiting"1>&2
190+
exit 1
191+
fi
192+
193+
if ["$SRC_VERSION"="$DST_VERSION" ]
194+
then# Versions are the same so we can get pg_largeobject oid this way
195+
SRC_LARGEOBJECT_IDX_OID="$DST_LARGEOBJECT_OID"
196+
SRC_LARGEOBJECT_IDX_OID="$DST_LARGEOBJECT_IDX_OID"
197+
fi
198+
158199
# we are done with SQL database access
159200
# shutdown forces buffers to disk
160201

@@ -166,6 +207,8 @@ fi
166207

167208
echo"Commit fixes complete, moving data files..."
168209

210+
# Move table/index/sequence files
211+
169212
cat"$SCHEMA"|whileread LINE
170213
do
171214
if /bin/echo"$LINE"| grep -q'^\\connect [^]*$'
@@ -205,13 +248,17 @@ do
205248
newdb == "'"$DB"'" && \
206249
$3 == "'"$TABLE"'" \
207250
{ ret=newoid; exit}
208-
END { print ret;}'$TMPFILE`
251+
END { print ret;}'/tmp/$$.3`
209252
if ["$NEWOID"-eq 0 ]
210253
thenecho"Move of database$DB, OID$OID, table$TABLE failed.
211254
New oid not found; exiting"1>&2
212255
exit 1
213256
fi
257+
214258
# We use stars so we don't have to worry about database oids
259+
260+
# Test to make sure there is exactly one matching file on each place
261+
215262
if [`ls"$OLDDIR"/base/*/"$OID"| wc -l`-eq 0 ]
216263
thenecho"Move of database$DB, OID$OID, table$TABLE failed.
217264
File not found; exiting"1>&2
@@ -232,26 +279,101 @@ File not found; exiting" 1>&2
232279
Too many found; exiting"1>&2
233280
exit 1
234281
fi
235-
mv -f"$OLDDIR"/base/*/"$OID" data/base/*/"$NEWOID"
282+
283+
# Move files
284+
285+
SRCDB=`basename\`dirname$OLDDIR"/base/*/"$OID"\``
286+
DSTDB=`basename \'dirname data/base/*/"$NEWOID"\``
287+
mv -f"$OLDIR"/base/"$SRCDB"/"$OID" data/base/"$DSTDB"/"$NEWOID"
236288
if ["$?"-ne 0 ]
237289
thenecho"Move of database$DB, OID$OID, table$TABLE
238290
to$NEWOID failed.; exiting"1>&2
239291
exit 1
240292
fi
293+
# handle table extents
294+
ls"$OLDDIR"/base/"$SRCDB"/"$OID".*|whileread FILE
295+
do
296+
EXT=`basename"$FILE"| sed's/[^[^\.]*\.\(.*\)$/\1/'`
297+
mv -f"$FILE" data/base/"$DSTDB"/"$NEWOID"."$EXT"
298+
if ["$?"-ne 0 ]
299+
thenecho"Move of database$DB, OID$OID, table$TABLE
300+
to$NEWOID failed.; exiting"1>&2
301+
exit 1
302+
fi
303+
done
304+
305+
# handle pg_largeobject
306+
# We use the unique oid's to tell use where to move the
307+
# pg_largeobject files.
308+
309+
if [-f"$OLDIR"/base/"$SRCDB"/"$SRC_LARGEOBJECT_OID" ]
310+
thenmv"$OLDIR"/base/"$SRCDB"/"$SRC_LARGEOBJECT_OID" \
311+
data/base/"$DSTDB"/"$DST_LARGEOBJECT_OID"
312+
if ["$?"-ne 0 ]
313+
thenecho"Move of large object for database$DB
314+
to$NEWOID failed.; exiting"1>&2
315+
exit 1
316+
fi
317+
# handle table extents
318+
ls"$OLDDIR"/base/"$SRCDB"/"$SRC_LARGEOBJECT_OID".*|whileread FILE
319+
do
320+
EXT=`basename"$FILE"| sed's/[^[^\.]*\.\(.*\)$/\1/'`
321+
mv -f"$FILE" data/base/"$DSTDB"/"$DST_LARGEOBJECT_OID"."$EXT"
322+
if ["$?"-ne 0 ]
323+
thenecho"Move of large object for database$DB
324+
to$NEWOID failed.; exiting"1>&2
325+
exit 1
326+
fi
327+
done
328+
fi
329+
330+
# Handle pg_largeobject_loid_pn_index
331+
if [-f"$OLDIR"/base/"$SRCDB"/"$SRC_LARGEOBJECT_IDX_OID" ]
332+
thenmv"$OLDIR"/base/"$SRCDB"/"$SRC_LARGEOBJECT_IDX_OID" \
333+
data/base/"$DSTDB"/"$DST_LARGEOBJECT_IDX_OID"
334+
if ["$?"-ne 0 ]
335+
thenecho"Move of large object for database$DB
336+
to$NEWOID failed.; exiting"1>&2
337+
exit 1
338+
fi
339+
# handle table extents
340+
ls"$OLDDIR"/base/"$SRCDB"/"$SRC_LARGEOBJECT_IDX_OID".*|whileread FILE
341+
do
342+
EXT=`basename"$FILE"| sed's/[^[^\.]*\.\(.*\)$/\1/'`
343+
mv -f"$FILE" data/base/"$DSTDB"/"$DST_LARGEOBJECT_IDX_OID"."$EXT"
344+
if ["$?"-ne 0 ]
345+
thenecho"Move of large object for database$DB
346+
to$NEWOID failed.; exiting"1>&2
347+
exit 1
348+
fi
349+
done
350+
fi
241351
TABLE=""
242352
fi
243353
done
244354
245355
246-
# Set this so the next VACUUM sets the old row XID's as "frozen"
356+
# Set this so future backends don't think these tuples are their own
357+
# because it matches their own XID.
247358
# Commit status already updated by vacuum above
359+
# Set to maximum XID just in case SRC wrapped around recently and
360+
# is lower than DST's database
361+
if ["$SRC_XID"-gt"$DST_XID" ]
362+
thenMAX_XID="$SRC_XID"
363+
elseMAX_XID="$DST_XID"
364+
fi
248365
249-
pg_resetxlog -x"$XID" data
366+
pg_resetxlog -x"$MAX_XID" data
250367
if ["$?"-ne 0 ]
251368
thenecho"Unable to set new XID.; exiting"1>&2
252369
exit 1
253370
fi
254371
372+
# Move over old WAL
373+
374+
rm -r data/pg_xlog
375+
mv -f"$OLDDIR"/pg_xlog data
376+
255377
# Set last checkpoint location from old database
256378
257379
CHKPOINT=`pg_resetxlog -n"$OLDDIR" | grep"checkpoint location:" |
@@ -283,8 +405,7 @@ if [ "$SRC_VERSION" = "7.1" ]
283405
thenecho"Set int8 sequence values from 7.1..."
284406
285407
psql -d template1 -At -c"SELECT datname FROM pg_database"|
286-
grep -v'^template0$'|# no system databases
287-
grep -v'^template1$'|# no system databases
408+
grep -v'^template0$'|# template1 OK
288409
whileread DB
289410
do
290411
echo"$DB"

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp