|
11 | 11 | #
|
12 | 12 | #
|
13 | 13 | # IDENTIFICATION
|
14 |
| -# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/clusterdb,v 1.2 2002/09/07 16:12:27 petere Exp $ |
| 14 | +# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/clusterdb,v 1.3 2002/09/12 00:18:14 momjian Exp $ |
15 | 15 | #
|
16 | 16 | #-------------------------------------------------------------------------
|
17 | 17 |
|
@@ -121,7 +121,7 @@ if [ "$usage" ]; then
|
121 | 121 | echo " -W, --password Prompt for password"
|
122 | 122 | echo " -d, --dbname=DBNAME Database to cluster"
|
123 | 123 | echo " -a, --all Cluster all databases"
|
124 |
| - echo " -t, --table='TABLE[(columns)]' Cluster specific table only" |
| 124 | + echo " -t, --table='TABLE' Cluster specific table only" |
125 | 125 | echo " -v, --verbose Write a lot of output"
|
126 | 126 | echo " -e, --echo Show the command being sent to the backend"
|
127 | 127 | echo " -q, --quiet Don't write any output"
|
|
152 | 152 |
|
153 | 153 | for db in $dbname
|
154 | 154 | do
|
155 |
| - [ "$alldb" -a "$quiet" -ne 1 ] && echo "Clustering $db" |
156 |
| - query="SELECT pg_class.relname, pg_class_2.relname FROM pg_class, \ |
157 |
| - pg_class AS pg_class_2, pg_index WHERE pg_class.oid=pg_index.indrelid\ |
158 |
| - AND pg_class_2.oid=pg_index.indexrelid AND pg_index.indisclustered" |
| 155 | + [ "$alldb" ] && echo "Clustering $db" |
| 156 | + query="SELECT nspname, pg_class.relname, pg_class_2.relname FROM pg_class, pg_class AS pg_class_2 JOIN pg_namespace ON (pg_namespace.oid=relnamespace), pg_index WHERE pg_class.oid=pg_index.indrelid AND pg_class_2.oid=pg_index.indexrelid AND pg_index.indisclustered" |
159 | 157 | if [ -z "$table" ]; then
|
160 | 158 | tables=`${PATHNAME}psql $db $PSQLOPT -F: -P format=unaligned -t -c "$query"`
|
161 | 159 | else
|
162 |
| - tables=`${PATHNAME}psql $db $PSQLOPT -F: -P format=unaligned -t -c \ |
163 |
| - "$query AND pg_class.relname='$table'"` |
| 160 | + # if tablename has a dot, use it as namespace separator |
| 161 | + if echo $table | grep -s '\.' 2>&1 >/dev/null |
| 162 | + then |
| 163 | + tbl=`echo $table | cut -d. -f2` |
| 164 | + nspc=`echo $table | cut -d. -f1` |
| 165 | + tables=`${PATHNAME}psql $db $PSQLOPT -F: -P format=unaligned -t -c "$query AND pg_class.relname='$tbl' AND nspname='$nspc'"` |
| 166 | + echo $tables |
| 167 | + else |
| 168 | + tables=`${PATHNAME}psql $db $PSQLOPT -F: -P format=unaligned -t -c "$query AND pg_class.relname='$table'"` |
| 169 | + fi |
164 | 170 | fi
|
| 171 | + query= |
165 | 172 | for tabs in $tables
|
166 | 173 | do
|
167 |
| - tab=`echo $tabs | cut -d: -f1` |
168 |
| - idx=`echo $tabs | cut -d: -f2` |
169 |
| - ${PATHNAME}psql $PSQLOPT $ECHOOPT -c "CLUSTER $idx on $tab" -d $db |
170 |
| - if [ "$?" -ne 0 ]; then |
171 |
| - echo "$CMDNAME: cluster $table $db failed" 1>&2 |
172 |
| - fi |
| 174 | + nspc=`echo $tabs | cut -d: -f1` |
| 175 | + tab=`echo $tabs | cut -d: -f2` |
| 176 | + idx=`echo $tabs | cut -d: -f3` |
| 177 | + query="$query CLUSTER $idx ON $nspc.$tab;" |
173 | 178 | done
|
| 179 | + ${PATHNAME}psql $PSQLOPT $ECHOOPT -c "$query" -d $db |
| 180 | + if [ "$?" -ne 0 ] |
| 181 | + then |
| 182 | + echo "$CMDNAME: While clustering $db, the following failed: $query" 1>&2 |
| 183 | + fi |
174 | 184 | done
|
175 | 185 |
|
176 | 186 | exit 0
|
0 commit comments