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

Commitbf45bff

Browse files
committed
Repair quoting sloppiness, lack of schema awareness in reindexdb.
1 parentf89c972 commitbf45bff

File tree

1 file changed

+43
-23
lines changed

1 file changed

+43
-23
lines changed

‎contrib/reindexdb/reindexdb

Lines changed: 43 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/sh
22
# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- #
3-
# Package : reindexdb Version : $Revision: 1.4 $
3+
# Package : reindexdb Version : $Revision: 1.5 $
44
# Date : 05/08/2002 Author : Shaun Thomas
55
# Req : psql, sh, perl, sed Type : Utility
66
#
@@ -26,7 +26,7 @@ usage()
2626
echo" -a, --all Reindex all databases"
2727
echo" -t, --table=TABLE Reindex specific table only"
2828
echo" -i, --index=INDEX Reindex specific index only"
29-
echo" -e, --echo Show the command being sent to the backend"
29+
echo" -e, --echo Show the command(s) sent to the backend"
3030
echo" -q, --quiet Don't write any output"
3131
echo
3232
echo"Read the description of the SQL command REINDEX for details."
@@ -41,7 +41,7 @@ usage()
4141
CMDNAME=`basename"$0"`
4242
PATHNAME=`echo$0| sed"s,$CMDNAME\$,,"`
4343

44-
# Tryvalliantly to get the location of psql, since you can't ever
44+
# Tryvaliantly to get the location of psql, since you can't ever
4545
# really know where it has been placed. We'll start by trying the
4646
# path. If that fails, we'll try the directory where this script
4747
# resides. Then on to whereis, and finally locate. Wish us luck.
@@ -95,9 +95,9 @@ do
9595
ECHOOPT="-e"
9696
;;
9797

98-
# Do not echo messages. We'll direct all output to /dev/null.
98+
# Do not echo messages.
9999
--quiet|-q)
100-
ECHOOPT="$ECHOOPT -o /dev/null"
100+
ECHOOPT="-q"
101101
quiet=1
102102
;;
103103

@@ -172,8 +172,9 @@ if [ "$alldb" ]; then
172172

173173
# Execute a command to pull back all databases the user specified can
174174
# connect to. That's the list we'll be using. It's also why it's
175-
# a good idea for this to be a super-user.
176-
dbname=`$PSQL$PSQLOPT -q -t -A -d template1 -c'SELECT datname FROM pg_database WHERE datallowconn'`
175+
# a good idea for this to be run as a super-user.
176+
sql='SELECT datname FROM pg_database WHERE datallowconn'
177+
dbname=`$PSQL$PSQLOPT -q -t -A -d template1 -c"$sql"`
177178

178179
# Ok, if it's not all databases, make sure at least one database is
179180
# specified before continuing.
@@ -191,42 +192,61 @@ if [ "$table" ] && [ "$index" ]; then
191192
exit 1
192193
fi
193194

194-
# If index wasset, reindex that index.
195+
# If index wasselected, reindex that index.
195196
if ["$index" ];then
196-
$PSQL$PSQLOPT$ECHOOPT -c"REINDEX INDEX$index" -d$dbname
197+
$PSQL$PSQLOPT$ECHOOPT -c"REINDEX INDEX\"$index\"" -d"$dbname"
198+
if ["$?"-ne 0 ];then
199+
echo"$CMDNAME: reindex index\"$index\" failed"1>&2
200+
exit 1
201+
fi
197202

198203
# Ok, no index. Is there a specific table to reindex?
199204
elif ["$table" ];then
200-
$PSQL$PSQLOPT$ECHOOPT -c"REINDEX TABLE\"$table\"" -d$dbname
205+
$PSQL$PSQLOPT$ECHOOPT -c"REINDEX TABLE\"$table\"" -d"$dbname"
206+
if ["$?"-ne 0 ];then
207+
echo"$CMDNAME: reindex table\"$table\" failed"1>&2
208+
exit 1
209+
fi
201210

202211
# No specific table, no specific index, either we have a specific database,
203212
# or were told to do all databases. Do it!
204213
else
205214

206-
sql="SELECT distinct tablename FROM pg_indexes WHERE tablename NOT LIKE 'pg_%'"
215+
# We set IFS to newline only so that the for-loops won't misinterpret
216+
# spaces in the lists we retrieved via psql. Note also the use of
217+
# regclass to handle spaces, mixed-case names, and schema awareness.
218+
sql="SELECT DISTINCT c.oid::pg_catalog.regclass FROM pg_catalog.pg_index x JOIN pg_catalog.pg_class c ON c.oid = x.indrelid JOIN pg_catalog.pg_namespace n ON c.relnamespace = n.oid WHERE nspname NOT LIKE 'pg\\\\_%'"
219+
220+
IFS='
221+
'
207222
fordbin$dbname;do
208223

209224
# Only print which database we're currently reindexing if not in
210225
# quiet mode, and we're doing more than one database.
211226
["$alldb" ]&& [-z"$quiet" ]&&echo"Reindexing$db"
212227

213-
# Ok, reindex every table in the database. Use the same method
214-
# we used to get a list of databases, and get a list of tables in this
215-
# database that we may reindex.
216-
tables=`$PSQL$PSQLOPT -q -t -A -d$db -c"$sql"`
228+
IFS='
229+
'
230+
# Get a list of non-system tables that have indexes.
231+
tables=`$PSQL$PSQLOPT -q -t -A -d"$db" -c"$sql"`
232+
233+
# Ok, reindex every table in the database.
234+
IFS='
235+
'
217236
fortabin$tables;do
218-
$PSQL$PSQLOPT$ECHOOPT -c"REINDEX TABLE\"$tab\"" -d$db
237+
IFS='
238+
'
239+
$PSQL$PSQLOPT$ECHOOPT -c"REINDEX TABLE$tab" -d"$db"
240+
if ["$?"-ne 0 ];then
241+
echo"$CMDNAME: reindex table$tab failed"1>&2
242+
exit 1
243+
fi
244+
IFS='
245+
'
219246
done
220247

221248
done
222249

223250
fi
224251

225-
# If any of the commands we've executed above failed in any way, bail
226-
# out with an error.
227-
if ["$?"-ne 0 ];then
228-
echo"$CMDNAME: reindex$index$table$dbname failed"1>&2
229-
exit 1
230-
fi
231-
232252
exit 0

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp