Now that the CLUSTER ALL machinery is in place, the clusterdb script can

be simplified (I'd thought that it can even be removed).  This patch
does that.

Alvaro Herrera
This commit is contained in:
Bruce Momjian 2003-03-20 18:53:18 +00:00
parent 432b9b0f75
commit 8819213534
2 changed files with 8 additions and 38 deletions

View File

@ -1,5 +1,5 @@
<!-- <!--
$Header: /cvsroot/pgsql/doc/src/sgml/ref/clusterdb.sgml,v 1.7 2003/02/19 04:06:28 momjian Exp $ $Header: /cvsroot/pgsql/doc/src/sgml/ref/clusterdb.sgml,v 1.8 2003/03/20 18:53:18 momjian Exp $
PostgreSQL documentation PostgreSQL documentation
--> -->
@ -43,7 +43,7 @@ PostgreSQL documentation
<para> <para>
<application>clusterdb</application> is a shell script wrapper around the <application>clusterdb</application> is a shell script wrapper around the
backend command backend command
<xref linkend="SQL-CLUSTER" endterm="SQL-CLUSTER-title"> via <xref linkend="SQL-CLUSTER" endterm="sql-cluster-title"> via
the <productname>PostgreSQL</productname> interactive terminal the <productname>PostgreSQL</productname> interactive terminal
<xref linkend="APP-PSQL">. There is no effective <xref linkend="APP-PSQL">. There is no effective
difference between clustering databases via this or other methods. difference between clustering databases via this or other methods.
@ -53,13 +53,6 @@ PostgreSQL documentation
and the <application>libpq</application> front-end library do apply. and the <application>libpq</application> front-end library do apply.
</para> </para>
<para>
<application>clusterdb</application> might need to connect several
times to the <productname>PostgreSQL</productname> server, asking for
a password each time. It is convenient to have a
<filename>$HOME/.pgpass</> file in such cases.
</para>
</refsect1> </refsect1>
@ -202,10 +195,9 @@ PostgreSQL documentation
<listitem> <listitem>
<para> <para>
Something went wrong. <application>clusterdb</application> is only a wrapper Something went wrong. <application>clusterdb</application> is only a wrapper
script. See <xref linkend="SQL-CLUSTER" endterm="SQL-CLUSTER-title"> script. See <xref linkend="SQL-CLUSTER" endterm="sql-cluster-title">
and <xref linkend="APP-PSQL"> for a detailed and <xref linkend="APP-PSQL"> for a detailed
discussion of error messages and potential problems. Note that this message discussion of error messages and potential problems.
may appear once per table to be clustered.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>

View File

@ -11,7 +11,7 @@
# #
# #
# IDENTIFICATION # IDENTIFICATION
# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/clusterdb,v 1.9 2003/02/13 05:37:44 momjian Exp $ # $Header: /cvsroot/pgsql/src/bin/scripts/Attic/clusterdb,v 1.10 2003/03/20 18:53:18 momjian Exp $
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
@ -156,34 +156,12 @@ fi
for db in $dbname for db in $dbname
do do
[ "$alldb" ] && echo "Clustering $db" [ "$alldb" ] && echo "Clustering $db"
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 AND pg_class.relowner=(SELECT usesysid FROM pg_user WHERE usename=current_user)"
if [ -z "$table" ]; then if [ -z "$table" ]; then
tables=`${PATHNAME}psql $db $PSQLOPT -F: -P format=unaligned -t -c "$query"` ${PATHNAME}psql $PSQLOPT $ECHOOPT -c "SET autocommit TO 'on';CLUSTER" -d $db
[ "$?" -ne 0 ] && exit 1 [ "$?" -ne 0 ] && exit 1
else else
# if tablename has a dot, use it as namespace separator ${PATHNAME}psql $PSQLOPT $ECHOOPT -c "SET autocommit TO 'on';CLUSTER $table" -d $db
if echo $table | grep -s '\.' 2>&1 >/dev/null [ "$?" -ne 0 ] && exit 1
then
tbl=`echo $table | cut -d. -f2`
nspc=`echo $table | cut -d. -f1`
tables=`${PATHNAME}psql $db $PSQLOPT -F: -P format=unaligned -t -c "$query AND pg_class.relname='$tbl' AND nspname='$nspc'"`
echo $tables
else
tables=`${PATHNAME}psql $db $PSQLOPT -F: -P format=unaligned -t -c "$query AND pg_class.relname='$table'"`
fi
fi
query=
for tabs in $tables
do
nspc=`echo $tabs | cut -d: -f1`
tab=`echo $tabs | cut -d: -f2`
idx=`echo $tabs | cut -d: -f3`
query="$query CLUSTER $idx ON $nspc.$tab;"
done
${PATHNAME}psql $PSQLOPT $ECHOOPT -c "SET autocommit TO 'on';$query" -d $db
if [ "$?" -ne 0 ]
then
echo "$CMDNAME: While clustering $db, the following failed: $query" 1>&2
fi fi
done done