Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 3a69c31

Browse files
committed
Accept pg_group as well as pg_shadow data from dumpall script.
Rearrange handling of VACUUMs so that they are certain to be executed as superuser not some random user; also, do not forget to vacuum template1 itself.
1 parent 3d14618 commit 3a69c31

File tree

1 file changed

+45
-20
lines changed

1 file changed

+45
-20
lines changed

src/bin/pg_dump/pg_upgrade

+45-20
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,17 @@
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/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 $
77
#
88
# NOTE: we must be sure to update the version-checking code a few dozen lines
99
# below for each new PostgreSQL release.
1010

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
1214

1315
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
1517
exit 1
1618
fi
1719

@@ -22,11 +24,12 @@ then INPUT="$2"
2224
then echo "$INPUT does not exist" 1>&2
2325
exit 1
2426
fi
25-
else INPUT=""
27+
else echo "Usage: $0 -f inputfile old_data_dir" 1>&2
28+
exit 1
2629
fi
2730

2831
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
3033
exit 1
3134
fi
3235

@@ -101,36 +104,57 @@ esac
101104

102105
# OK, ready to proceed.
103106

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.
105109
# 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.
109110

110111
cat $INPUT | awk ' {
111-
if (toupper($1) == "COPY" && $2 != "pg_shadow")
112+
if (tolower($1) == "copy" &&
113+
$2 != "pg_shadow" &&
114+
$2 != "pg_group")
112115
while (getline $0 > 0 && $0 != "\\.")
113116
;
114-
else if (tolower($1) == "\\connect" &&
115-
tolower($2) == "template1")
116-
printf "VACUUM;\n%s\n", $0;
117117
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
119127

120-
# We need to vacuum the last database too
121-
echo "VACUUM;" >>/tmp/$$
128+
echo "Input script $INPUT complete, fixing row commit statuses..."
122129

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
124148

125-
psql "template1" <"/tmp/$$"
149+
psql "template1" <$TMPFILE
126150

127151
if [ $? -ne 0 ]
128-
then echo "There were errors in the input script $INPUT.
152+
then echo "There were errors in the vacuuming step.
129153
$0 aborted." 1>&2
130154
exit 1
131155
fi
132156

133-
echo "Input script $INPUT complete, moving data files..."
157+
echo "Commit fixes complete, moving data files..."
134158

135159
for DIR in data/base/*
136160
do
@@ -153,4 +177,5 @@ mv -f $OLDDIR/pg_variable data
153177

154178
echo "You must stop/start the postmaster before doing anything else."
155179
echo "You may remove the $OLDDIR directory with 'rm -r $OLDDIR'."
180+
156181
exit 0

0 commit comments

Comments
 (0)