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

Commit8e76187

Browse files
committed
More cleanups with ideas from Peter.
1 parent86beaf4 commit8e76187

File tree

2 files changed

+57
-78
lines changed

2 files changed

+57
-78
lines changed

‎contrib/pg_upgrade/README

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,3 @@ Read the manual page for more information. To view it:
1010
Bruce Momjian
1111

1212
2002-01-14
13-
14-
--
15-
16-
To migrate this to newer versions of PostgreSQL:
17-
18-
1) Update the version numbers at the top of the file
19-
2) Search for specific version mentions in the script and update
20-
accordingly.
21-
3) Add changes for next version.
22-

‎contrib/pg_upgrade/pg_upgrade

Lines changed: 57 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1-
#!/bin/sh
1+
z#!/bin/sh
22
#
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/contrib/pg_upgrade/Attic/pg_upgrade,v 1.3 2002/01/15 04:05:24 momjian Exp $
6+
# $Header: /cvsroot/pgsql/contrib/pg_upgrade/Attic/pg_upgrade,v 1.4 2002/01/15 04:50:37 momjian Exp $
77
#
8-
# NOTE: we must be sure to update the version-checking code a few dozen lines
9-
# below for each new PostgreSQL release.
8+
# To migrate this to newer versions of PostgreSQL:
9+
#1) Update the version numbers at the top of the file
10+
#2) Search for specific version mentions in the script and update
11+
# accordingly.
12+
#3) Add changes for next version.
1013

1114
#set -x
1215

@@ -15,8 +18,7 @@ ENABLE="Y"
1518

1619
if [ "$ENABLE" != "Y" ]
1720
then
18-
echo"Sorry,$0 cannot upgrade database
19-
version$SRC_VERSION to$DST_VERSION."1>&2
21+
echo "Sorry, $0 cannot upgrade database version $SRC_VERSION to $DST_VERSION." 1>&2
2022
echo "The on-disk structure of tables has changed." 1>&2
2123
echo "You will need to dump and restore using pg_dumpall." 1>&2
2224
exit 1
@@ -59,17 +61,15 @@ thenecho "You must set the PGDATA environment variable or specify it with -D."
5961
fi
6062

6163
if [ ! -d "$PGDATA" ]
62-
thenecho"$PGDATA does not exist.
63-
$BASENAME aborted."1>&2
64+
thenecho "$PGDATA does not exist. Exiting." 1>&2
6465
if [ "$PHASE" -eq 2 ]
6566
thenecho "Perhaps you didn't run initdb." 1>&2
6667
fi
6768
exit 1
6869
fi
6970

7071
if [ "$USER" = "root" -o ! -r "$PGDATA"/PG_VERSION ]
71-
thenecho"You must run this as the PostgreSQL superuser.
72-
$BASENAME aborted."1>&2
72+
thenecho "You must run this as the PostgreSQL superuser. Exiting." 1>&2
7373
exit 1
7474
fi
7575

@@ -120,24 +120,24 @@ move_objfiles()
120120

121121
if [ ! -f "$SAVEDATA"/base/"$SRC_DBOID"/"$SRC_OID" -a \
122122
! -h "$SAVEDATA"/base/"$SRC_DBOID"/"$SRC_OID" ]
123-
thenecho"Move of database$DB, OID$SRC_OID, object$OBJ failed.
124-
File not found; exiting"1>&2
123+
thenecho "Moving of database $DB, OID $SRC_OID, object $OBJ failed." 1>&2
124+
echo "File not found. Exiting." 1>&2
125125
return 1
126126
fi
127127

128128
if [ ! -f "$PGDATA"/base/"$DST_DBOID"/"$DST_OID" -a \
129129
! -h "$PGDATA"/base/"$DST_DBOID"/"$DST_OID" ]
130-
thenecho"Move of database$DB, OID$DST_OID, object$OBJ failed.
131-
File not found; exiting"1>&2
130+
thenecho "Moving of database $DB, OID $DST_OID, object $OBJ failed." 1>&2
131+
echo "File not found. Exiting." 1>&2
132132
return 1
133133
fi
134134

135135
# Move files
136136

137137
mv -f "$SAVEDATA"/base/"$SRC_DBOID"/"$SRC_OID" "$PGDATA"/base/"$DST_DBOID"/"$DST_OID"
138138
if [ "$?" -ne 0 ]
139-
thenecho"Move of database$DB, OID$SRC_OID, object$OBJ
140-
to$DST_OID failed.; exiting"1>&2
139+
thenecho "Moving of database $DB, OID $SRC_OID, object $OBJ" 1>&2
140+
echo "to $DST_OID failed. Exiting" 1>&2
141141
return 1
142142
fi
143143

@@ -148,8 +148,8 @@ to $DST_OID failed.; exiting" 1>&2
148148
EXT=`basename "$FILE" | sed 's/^.*\.\(.*\)$/\1/'`
149149
mv -f "$FILE" "$PGDATA"/base/"$DST_DBOID"/"$DST_OID"."$EXT"
150150
if [ "$?" -ne 0 ]
151-
thenecho"Move of database$DB, OID$SRC_OID, object$OBJ
152-
to$DST_OID failed.; exiting"1>&2
151+
thenecho "Moving of database $DB, OID $SRC_OID, object $OBJ" 1>&2
152+
echo "to $DST_OID failed. Exiting." 1>&2
153153
return 1
154154
fi
155155
done
@@ -171,45 +171,43 @@ then
171171
# get version
172172
SRC_VERSION=`cat "$PGDATA"/PG_VERSION`
173173
if [ "$SRC_VERSION" = "" ]
174-
thenecho"$BASENAME can not find PostgreSQL version file '$PGDATA/PG_VERSION'.
175-
$BASENAME aborted."1>&2
174+
thenecho "$BASENAME can not findthePostgreSQL version file" 1>&2
175+
echo "'$PGDATA/PG_VERSION'. Exiting." 1>&2
176176
exit 1
177177
fi
178178

179179
if [ "$SRC_VERSION" != "$CUR_VERSION" -a \
180180
"$SRC_VERSION" != "$UPGRADE_VERSION" ]
181181
thenecho "$BASENAME supports versions $UPGRADE_VERSION and $CUR_VERSION only." 1>&2
182-
echo"However, your database is version$SRC_VERSION;
183-
$BASENAME aborted."1>&2
184-
echo"You will need to dump and restore using pg_dumpall."1>&2
182+
echo "However, your database is version $SRC_VERSION." 1>&2
183+
echo "You will need to dump and restore using pg_dumpall. Exiting." 1>&2
185184
exit 1
186185
fi
187186

188187
# Start server, if needed, so we can do some work.
189188
if ! pg_ctl status | sed -n '1p' | grep "is running" > /dev/null 2>&1
190189
thenpg_ctl -w start
191190
if [ $? -ne 0 ]
192-
thenecho"Can not start server.
193-
$BASENAME aborted."1>&2
191+
thenecho "Can not start server. Exiting." 1>&2
194192
exit 1
195193
fi
196194
fi
197195

198196
# create directory for our data
199197
if ! rm -rf "$INFODIR"
200-
thenecho"Deletion of old pg_upgrade_info directoryfailed,$INFODIR.
201-
$BASENAME aborted."1>&2
198+
thenecho "Deletion of old pg_upgrade_info directory $INFODIR failed." 1>&2
199+
echo "Exiting." 1>&2
202200
exit 1
203201
fi
204202
if ! mkdir "$INFODIR"
205-
thenecho"Creation of new pg_upgrade_info directoryfailed,$INFODIR.
206-
$BASENAME aborted."1>&2
203+
thenecho "Creation of new pg_upgrade_info directory $INFODIR failed." 1>&2
204+
echo "Exiting." 1>&2
207205
exit 1
208206
fi
209207

210208
if ! chmod og-rwx "$INFODIR"
211-
thenecho"Permission change on new pg_upgrade_info directoryfailed,$INFODIR.
212-
$BASENAME aborted."1>&2
209+
thenecho "Permission change on new pg_upgrade_info directory $INFODIR failed." 1>&2
210+
echo "Exiting." 1>&2
213211
exit 1
214212
fi
215213

@@ -238,8 +236,7 @@ $BASENAME aborted." 1>&2
238236
else print $0;
239237
}' > "$INFODIR"/schema
240238
if [ $? -ne 0 ]
241-
thenecho"Can not dump schema.
242-
$BASENAME aborted."1>&2
239+
thenecho "Can not dump schema. Exiting." 1>&2
243240
exit 1
244241
fi
245242

@@ -278,30 +275,27 @@ $BASENAME aborted." 1>&2
278275

279276
vacuumdb -a
280277
if [ $? -ne 0 ]
281-
thenecho"Can not vacuum server.
282-
$BASENAME aborted."1>&2
278+
thenecho "Can not vacuum server. Exiting." 1>&2
283279
exit 1
284280
fi
285281

286282
# Stop server so we can move the directory.
287283
pg_ctl -w stop
288284
if [ $? -ne 0 ]
289-
thenecho"Can not stop server.
290-
$BASENAME aborted."1>&2
285+
thenecho "Can not stop server. Exiting." 1>&2
291286
exit 1
292287
fi
293288

294289
# No matter what the directory name, call it data
295290
mv "$PGDATA" "$INFODIR"/data
296291
if [ $? -ne 0 ]
297-
thenecho"Can not move old /$PGDATA out of the way.
298-
$BASENAME aborted."1>&2
292+
thenecho "Can not move old $PGDATA out of the way. Exiting." 1>&2
299293
exit 1
300294
fi
301295
echo
302296
echo
303-
echo"Plase 1 completed.
304-
Continue with the steps outlined in the$BASENAME manual page."
297+
echo "Plase 1 completed."
298+
echo "Continue with the steps outlined in the $BASENAME manual page."
305299
exit 0
306300
fi
307301

@@ -313,7 +307,7 @@ fi
313307
# check things
314308

315309
if [ ! -d "$INFODIR" ]
316-
thenecho"There is no '$INFODIR' directory froma phase 1 run of$BASENAME."1>&2
310+
thenecho "There is no '$INFODIR' directory fromthe phase 1 run of $BASENAME." 1>&2
317311
exit 1
318312
fi
319313

@@ -347,8 +341,8 @@ DST_VERSION=`cat "$PGDATA"/PG_VERSION`
347341
# This code will need to be updated/reviewed for each new PostgreSQL release.
348342

349343
if [ "$DST_VERSION" != "$CUR_VERSION" ]
350-
thenecho"$BASENAME is for PostgreSQL version$CUR_VERSION
351-
but$PGDATA/PG_VERSION contains$DST_VERSION."1>&2
344+
thenecho "$BASENAME is for PostgreSQL version $CUR_VERSION" 1>&2
345+
echo "but $PGDATA/PG_VERSION contains $DST_VERSION." 1>&2
352346
echo "Did you run initdb for version $UPGRADE_VERSION by mistake?" 1>&2
353347
exit 1
354348
fi
@@ -358,8 +352,7 @@ fi
358352
if pg_ctl status | sed -n '1p' | grep "is running" > /dev/null 2>&1
359353
thenpg_ctl -w stop
360354
if [ $? -ne 0 ]
361-
thenecho"Can no start server.
362-
$BASENAME aborted."1>&2
355+
thenecho "Can no start server. Exiting." 1>&2
363356
exit 1
364357
fi
365358
fi
@@ -369,14 +362,15 @@ fi
369362
pg_resetxlog 2> /dev/null
370363
# file not found status is normally 127, not 1
371364
if [ "$?" -ne 1 ]
372-
thenecho"Unable to find pg_resetxlog in path.
373-
Install it from pgsql/contrib/pg_resetxlog and continue.; exiting"1>&2
365+
thenecho "Unable to find pg_resetxlog inyourpath." 1>&2
366+
echo "Install it from pgsql/contrib/pg_resetxlog and continue. Exiting." 1>&2
374367
exit 1
375368
fi
376369

377370
if ! pg_resetxlog -x 2>&1 | grep 'xid' > /dev/null 2>&1
378-
thenecho"Old version of pg_resetxlog found in path.
379-
Install a newer version from pgsql/contrib/pg_resetxlog.; exiting"1>&2
371+
thenecho "Old version of pg_resetxlog found in path." 1>&2
372+
echo "Install a newer version of pg_resetxlog from pgsql/contrib/pg_resetxlog." 1>&2
373+
echo "Exiting." 1>&2
380374
exit 1
381375
fi
382376

@@ -385,7 +379,7 @@ fi
385379

386380
SRC_XID=`pg_resetxlog -n "$SAVEDATA" | grep "NextXID" | awk -F' *' '{print $4}'`
387381
if [ "$SRC_VERSION" = "7.1" -a "$SRC_XID" -gt 2000000000 ]
388-
thenecho"XID too high for$BASENAME.; exiting"1>&2
382+
thenecho "XID too high for $BASENAME. Exiting." 1>&2
389383
exit 1
390384
fi
391385
DST_XID=`pg_resetxlog -n "$PGDATA" | grep "NextXID" | awk -F' *' '{print $4}'`
@@ -395,16 +389,15 @@ DST_XID=`pg_resetxlog -n "$PGDATA" | grep "NextXID" | awk -F' *' '{print $4}'`
395389
pg_resetxlog -n "$SAVEDATA" | grep "^LC_" > /tmp/$$.0
396390
pg_resetxlog -n "$PGDATA" | grep "^LC_" > /tmp/$$.1
397391
if ! diff /tmp/$$.0 /tmp/$$.1 > /dev/null
398-
thenecho"Locales do not match between the two versions.; exiting"1>&2
392+
thenecho "Locales do not match between the two versions. Exiting." 1>&2
399393
exit 1
400394
fi
401395

402396
# Restart postmaster
403397

404398
pg_ctl -w start
405399
if [ $? -ne 0 ]
406-
thenecho"Can not start server.
407-
$BASENAME aborted."1>&2
400+
thenecho "Can not start server. Exiting." 1>&2
408401
exit 1
409402
fi
410403

@@ -418,21 +411,19 @@ fi
418411

419412
psql template1 < "$INFODIR"/schema
420413
if [ $? -ne 0 ]
421-
thenecho"There were errors in the input script.
422-
$BASENAME aborted."1>&2
414+
thenecho "There were errors in the input script. Exiting." 1>&2
423415
exit 1
424416
fi
425417

426-
echo"Input scriptcomplete, fixing row commit statuses..."
418+
echo "Input scriptcompleted, fixing row commit statuses..."
427419

428420
# XXX do we still need this?
429421
# Now vacuum each result database because our movement of transaction log
430422
# causes some committed transactions to appear as non-committed
431423

432424
vacuumdb -a
433425
if [ $? -ne 0 ]
434-
thenecho"There were errors during VACUUM.
435-
$BASENAME aborted."1>&2
426+
thenecho "There were errors during VACUUM. Exiting." 1>&2
436427
exit 1
437428
fi
438429

@@ -445,7 +436,7 @@ make_dbobjoidmap > /tmp/$$.dbobjoidmap || exit "$?"
445436

446437
pg_ctl -w stop
447438
if [ "$?" -ne 0 ]
448-
thenecho"Unable to stop database server.; exiting"1>&2
439+
thenecho "Unable to stop database server. Exiting." 1>&2
449440
exit 1
450441
fi
451442

@@ -507,7 +498,7 @@ fi
507498

508499
pg_resetxlog -x "$MAX_XID" "$PGDATA"
509500
if [ "$?" -ne 0 ]
510-
thenecho"Unable to set new XID.; exiting"1>&2
501+
thenecho "Unable to set new XID. Exiting." 1>&2
511502
exit 1
512503
fi
513504

@@ -521,29 +512,29 @@ mv -f "$SAVEDATA"/pg_xlog "$PGDATA"
521512
LOG_ID=`pg_resetxlog -n "$SAVEDATA" | grep "Current log file id:" |
522513
awk -F' *' '{print $5}'`
523514
if [ "$LOG_ID" = "" ]
524-
thenecho"Unable to get old log file id.; exiting"1>&2
515+
thenecho "Unable to get old log file id. Exiting." 1>&2
525516
exit 1
526517
fi
527518
SEG_ID=`pg_resetxlog -n "$SAVEDATA" | grep "Next log file segment:" |
528519
awk -F' *' '{print $5}'`
529520
if [ "$SEG_ID" = "" ]
530-
thenecho"Unable to get old log segment id.; exiting"1>&2
521+
thenecho "Unable to get old log segment id. Exiting." 1>&2
531522
exit 1
532523
fi
533524

534525
# Set checkpoint location of new database
535526

536527
pg_resetxlog -l "$LOG_ID" "$SEG_ID" "$PGDATA"
537528
if [ "$?" -ne 0 ]
538-
thenecho"Unable to set new log file/segment id.; exiting"1>&2
529+
thenecho "Unable to set new log file/segment id. Exiting." 1>&2
539530
exit 1
540531
fi
541532

542533
# Restart server with moved data
543534

544535
pg_ctl -w start
545536
if [ "$?" -ne 0 ]
546-
thenecho"Unable to restart database server.; exiting"1>&2
537+
thenecho "Unable to restart database server. Exiting." 1>&2
547538
exit 1
548539
fi
549540

@@ -554,14 +545,12 @@ if [ "$SRC_VERSION" = "7.1" -o \
554545
thenecho "Set sequence values..."
555546
psql -d template1 -At < "$INFODIR"/setval
556547
if [ $? -ne 0 ]
557-
thenecho"There were errors during int4 sequence restore.
558-
$BASENAME aborted."1>&2
548+
thenecho "There were errors during int4 sequence restore. Exiting." 1>&2
559549
exit 1
560550
fi
561551
fi
562552

563553
echo
564554
echo
565555
echo "You may remove the old database files with 'rm -r $INFODIR'."
566-
567556
exit 0

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp