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

Commit970ef45

Browse files
committed
Re-enable pg_upgrade, after adding checks that the source
and target databases are of versions it knows about.
1 parentd7f2c55 commit970ef45

File tree

1 file changed

+60
-19
lines changed

1 file changed

+60
-19
lines changed

‎src/bin/pg_dump/pg_upgrade

Lines changed: 60 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
#!/bin/sh
22
#
3-
# pg_upgrade: update a database without needing a full dump/reload cycle
3+
# 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-
echo"pg_upgrade is disabled in this release because the on-disk structure"1>&2
7-
echo"of the tables has changed compared to previous releases."1>&2
8-
exit 1
6+
# NOTE: we must be sure to update the version-checking code a few dozen lines
7+
# below for each new PostgreSQL release.
98

109
trap"rm -f /tmp/$$" 0 1 2 3 15
1110

@@ -33,37 +32,76 @@ OLDDIR="$1"
3332

3433
# check things
3534

36-
if [!-f"./data/PG_VERSION" ]
35+
if [!-d"./data" ]
3736
thenecho"`basename$0` must be run from the directory containing
38-
the database directory\`data' (`dirname$PGDATA`.)"1>&2
37+
the database directory\`data\' (`dirname$PGDATA`.)"1>&2
38+
echo"You must have run initdb to create the template1 database."1>&2
3939
exit 1
4040
fi
4141

4242
if [!-d"./$OLDDIR" ]
43-
thenecho"You must rename your old /data directory to /$OLDDIR and run initdb."1>&2
43+
thenecho"You must rename your old data directory to$OLDDIR and run initdb."1>&2
44+
exit 1
45+
fi
46+
47+
if [!-d"./data/base/template1" ]
48+
thenecho"Cannot find database template1 in ./data/base."1>&2
49+
echo"Are you running$0 as the postgres superuser?"1>&2
4450
exit 1
4551
fi
4652

4753
if [!-d"./$OLDDIR/base/template1" ]
48-
thenecho"There isnot database template1 in ./$OLDDIR/base."1>&2
54+
thenecho"There isno database template1 in ./$OLDDIR/base."1>&2
4955
exit 1
5056
fi
5157

52-
if [!-d"./data" ]
53-
thenecho"You must run initdb to create the template1 database."1>&2
58+
if [!-r"./data/PG_VERSION" ]
59+
thenecho"Cannot read ./data/PG_VERSION --- something is wrong."1>&2
5460
exit 1
5561
fi
5662

57-
if [!-d"./data/base/template1" ]
58-
thenecho"$0 must be run as the postgres superuser."1>&2
63+
if [!-r"./$OLDDIR/PG_VERSION" ]
64+
thenecho"Cannot read ./$OLDDIR/PG_VERSION --- something is wrong."1>&2
5965
exit 1
6066
fi
6167

62-
# do I need to create a database?
68+
# Get the actual versions seen in the data dirs.
69+
DESTVERSION=`cat ./data/PG_VERSION`
70+
SRCVERSION=`cat ./$OLDDIR/PG_VERSION`
6371

64-
# remove any COPY statements
65-
# we don't even need pgdump_oid because we are moving pg_variable
66-
# then shouldn't be in there anyway
72+
# Check for version compatibility.
73+
# This code will need to be updated/reviewed for each new PostgreSQL release.
74+
75+
# MYVERSION is the expected output database version
76+
MYVERSION="6.6"
77+
78+
if ["$DESTVERSION"!="$MYVERSION" ]
79+
thenecho"$0 is for PostgreSQL version$MYVERSION, but ./data/PG_VERSION contains$DESTVERSION."1>&2
80+
echo"Did you run initdb for version$MYVERSION?"1>&2
81+
exit 1
82+
fi
83+
84+
# Check that input database is of a compatible version (anything with the same
85+
# physical layout of user tables and indexes should be OK). I did not write
86+
# something like "$SRCVERSION -ge $MINVERSION" because test(1) isn't bright
87+
# enough to compare dotted version strings properly. Using a case statement
88+
# looks uglier but is more flexible.
89+
90+
case"$SRCVERSION"in
91+
6.5) ;;
92+
6.6) ;;
93+
*)echo"Sorry,`basename$0` cannot upgrade database version$SRCVERSION to$DESTVERSION."1>&2
94+
echo"The on-disk structure of tables has changed."1>&2
95+
echo"You will need to dump and restore using pg_dump."1>&2
96+
exit 1;;
97+
esac
98+
99+
100+
# OK, ready to proceed.
101+
# XXX Do I need to create a database?
102+
103+
# remove any COPY statements, except for the one that loads pg_shadow.
104+
# there shouldn't be any others in there anyway...
67105

68106
cat$INPUT| awk'{
69107
if (toupper($1) == "COPY" && $2 != "pg_shadow")
@@ -82,6 +120,8 @@ $0 aborted." 1>&2
82120
exit 1
83121
fi
84122

123+
echo"Input script$INPUT complete, moving data files..."
124+
85125
forDIRin data/base/*
86126
do
87127
BASEDIR="`basename$DIR`"
@@ -92,13 +132,14 @@ do
92132
BASEFILE="`basename$FILE`"
93133
if [`expr"$BASEFILE":"pg_"`-ne 3-a \
94134
"$BASEFILE"!="PG_VERSION" ]
95-
thenmv$FILE$DIR
135+
thenmv-f$FILE$DIR
96136
fi
97137
done
98138
fi
99139
done
100140

101-
mv$OLDDIR/pg_log data
102-
mv$OLDDIR/pg_variable data
141+
mv-f$OLDDIR/pg_log data
142+
mv-f$OLDDIR/pg_variable data
103143

104144
echo"You may remove the$OLDDIR directory with 'rm -r$OLDDIR'."
145+
exit 0

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp