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.14 2000/02/23 15:46:12 momjian Exp $
6
+ # $Header: /cvsroot/pgsql/src/bin/pg_dump/Attic/pg_upgrade,v 1.15 2000/05/05 03:08:20 tgl 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.
10
10
11
- trap " rm -f /tmp/$$ " 0 1 2 3 15
11
+ TMPFILE=" /tmp/pgupgrade.$$ "
12
+
13
+ trap " rm -f $TMPFILE " 0 1 2 3 15
12
14
13
15
if [ " $# " -eq 0 ]
14
- then echo " Usage: $0 [ -f inputfile] old_data_dir" 1>&2
16
+ then echo " Usage: $0 -f inputfile old_data_dir" 1>&2
15
17
exit 1
16
18
fi
17
19
@@ -22,11 +24,12 @@ then INPUT="$2"
22
24
then echo " $INPUT does not exist" 1>&2
23
25
exit 1
24
26
fi
25
- else INPUT=" "
27
+ else echo " Usage: $0 -f inputfile old_data_dir" 1>&2
28
+ exit 1
26
29
fi
27
30
28
31
if [ " $# " -ne 1 ]
29
- then echo " Usage: $0 [ -f inputfile] old_data_dir" 1>&2
32
+ then echo " Usage: $0 -f inputfile old_data_dir" 1>&2
30
33
exit 1
31
34
fi
32
35
@@ -101,36 +104,57 @@ esac
101
104
102
105
# OK, ready to proceed.
103
106
104
- # Remove any COPY statements, except for the one that loads pg_shadow.
107
+ # Execute the input script to create everything, except that we remove
108
+ # any COPY statements, except for the ones that load pg_shadow/pg_group.
105
109
# There shouldn't be any others in there anyway...
106
- # Also marks rows as committed because when pg_log is replaced with
107
- # the saved version, the transaction statuses may be wrong, so
108
- # vacuum sets the on-row status to the proper value.
109
110
110
111
cat $INPUT | awk ' {
111
- if (toupper($1) == "COPY" && $2 != "pg_shadow")
112
+ if (tolower($1) == "copy" &&
113
+ $2 != "pg_shadow" &&
114
+ $2 != "pg_group")
112
115
while (getline $0 > 0 && $0 != "\\.")
113
116
;
114
- else if (tolower($1) == "\\connect" &&
115
- tolower($2) == "template1")
116
- printf "VACUUM;\n%s\n", $0;
117
117
else print $0;
118
- }' > /tmp/$$
118
+ }' > $TMPFILE
119
+
120
+ psql " template1" < $TMPFILE
121
+
122
+ if [ $? -ne 0 ]
123
+ then echo " There were errors in the input script $INPUT .
124
+ $0 aborted." 1>&2
125
+ exit 1
126
+ fi
119
127
120
- # We need to vacuum the last database too
121
- echo " VACUUM;" >> /tmp/$$
128
+ echo " Input script $INPUT complete, fixing row commit statuses..."
122
129
123
- # Create and vacuum empty tables/indexes
130
+ # Now vacuum each result database to mark all system-table rows as committed,
131
+ # because when pg_log is replaced with the saved version, the transaction
132
+ # statuses will no longer match the data. VACUUM will force the on-row
133
+ # status flags to the right value so that pg_log will not matter anymore.
134
+ # Note: we used to try to do this as part of the previous step, but that
135
+ # risks permissions problems if VACUUM is run as the wrong user.
136
+ # Note: the initial VACUUM does template1, then we do everything else.
137
+
138
+ cat $INPUT | awk ' BEGIN { print "VACUUM;" }
139
+ {
140
+ if (tolower($1) == "copy")
141
+ while (getline $0 > 0 && $0 != "\\.")
142
+ ;
143
+ else if (tolower($1) == "\\connect" &&
144
+ $2 != "-" &&
145
+ $2 != "template1")
146
+ printf "\\connect %s\nVACUUM;\n", $2;
147
+ }' > $TMPFILE
124
148
125
- psql " template1" < " /tmp/ $$ "
149
+ psql " template1" < $TMPFILE
126
150
127
151
if [ $? -ne 0 ]
128
- then echo " There were errors in the input script $INPUT .
152
+ then echo " There were errors in the vacuuming step .
129
153
$0 aborted." 1>&2
130
154
exit 1
131
155
fi
132
156
133
- echo " Input script $INPUT complete, moving data files..."
157
+ echo " Commit fixes complete, moving data files..."
134
158
135
159
for DIR in data/base/*
136
160
do
@@ -153,4 +177,5 @@ mv -f $OLDDIR/pg_variable data
153
177
154
178
echo " You must stop/start the postmaster before doing anything else."
155
179
echo " You may remove the $OLDDIR directory with 'rm -r $OLDDIR '."
180
+
156
181
exit 0
0 commit comments