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

Commit3a69c31

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 executedas superuser not some random user; also, do not forget to vacuumtemplate1 itself.
1 parent3d14618 commit3a69c31

File tree

1 file changed

+45
-20
lines changed

1 file changed

+45
-20
lines changed

‎src/bin/pg_dump/pg_upgrade

Lines changed: 45 additions & 20 deletions
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-
thenecho"Usage:$0[-f inputfile] old_data_dir"1>&2
16+
thenecho"Usage:$0 -f inputfile old_data_dir"1>&2
1517
exit 1
1618
fi
1719

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

2831
if ["$#"-ne 1 ]
29-
thenecho"Usage:$0[-f inputfile] old_data_dir"1>&2
32+
thenecho"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
elseprint $0;
118-
}'>/tmp/$$
118+
}'>$TMPFILE
119+
120+
psql"template1"<$TMPFILE
121+
122+
if [$?-ne 0 ]
123+
thenecho"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-
thenecho"There were errors in theinput script$INPUT.
152+
thenecho"There were errors in thevacuuming 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
forDIRin 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)

[8]ページ先頭

©2009-2025 Movatter.jp