<p>pg_reorg is an utility program to reorganize tables in PostgreSQL databases.
Unlike <ahref="http://www.postgresql.jp/document/current/html/app-clusterdb.html"><tt>clusterdb</tt></a>, it doesn't block any selections and updates during reorganization.
You can choose one of the following methods to reorganize.</p>
<ul>
<li>Online CLUSTER (ordered by cluster index)</li>
<li>Ordered by specified columns</li>
<li>Online VACUUM FULL (packing rows only)</li>
</ul>
<p>NOTICE:</p>
<ul>
<li>Only superusers can use the utility.</li>
<li>Target table must have PRIMARY KEY.</li>
<li>You'd better to do <tt><ahref="http://www.postgresql.jp/document/current/html/sql-analyze.html">ANALYZE</a></tt> after pg_reorg is completed.</li>
</ul>
</div>
<div><aname="examples"></a>
<h2>Examples</h2>
<p>Execute the following command to do online CLUSTER to all tables in <tt>test</tt> database.</p>
<p>pg_reorg has command line options in 4 categolies.</p>
<div>
<dl>
<h3>connection-options</h3>
<p>Parameters to connect PostgreSQL.</p>
<div>
<dl>
<dt><tt>-h <tt><i>host</i></tt><br/>
<tt>--host <tt><i>host</i></tt></dt>
<dd>Specifies the host name of the machine on which the server is running. If the value begins with a slash, it is used as the directory for the Unix domain socket. </dd>
<dt><tt>-p <tt><i>port</i></tt><br/>
<tt>--port <tt><i>port</i></tt></dt>
<dd>Specifies the TCP port or local Unix domain socket file extension on which the server is listening for connections.</dd>
<dt><tt>-U <tt><i>username</i></tt><br/>
<tt>--username <tt><i>username</i></tt></dt>
<dd>User name to connect as. </dd>
<dt><tt>-W</tt><br/><tt>--password</tt></dt>
<dd>Force pg_reorg to prompt for a password before connecting to a database.</dd>
<dd>This option is never essential, since pg_reorg will automatically prompt for a password if the server demands password authentication. However, vacuumdb will waste a connection attempt finding out that the server wants a password. In some cases it is worth typing <tt>-W</tt> to avoid the extra connection attempt. </dd>
</dl>
</div>
<h3>message-options</h3>
<p>Specifies message output by pg_reorg.
<tt>--quiet</tt> is ignored if some of the other options are specified.</p>
<dl>
<dt><tt>-e</tt><br/><tt>--echo</tt></dt>
<dd>Echo the commands that pg_reorg generates and sends to the server.</dd>
<dt><tt>-q</tt><br/><tt>--quiet</tt></dt>
<dd>Do not display progress messages. </dd>
<dt><tt>-v</tt><br/><tt>--verbose</tt></dt>
<dd>Print detailed information during processing.</dd>
</dl>
<h3>order-options</h3>
<p>Options to order rows.
If not specified, pg_reorg do online CLUSTER using cluster indexes.
<dd>Do online CLUSTER ordered by specified columns.</dd>
</dl>
<h3>target-options</h3>
<p>
Options to specify target tables or databases.
You cannot use <tt>--all</tt> and <tt>--dbname</tt> or <tt>--table</tt> together.
</p>
<dl>
<dt><tt>-a</tt><br/><tt>--all</tt></dt>
<dd>Reorganize all databases.</dd>
<dt>
<tt>-d <tt><i>dbname</i></tt><br/>
<tt>--dbname <tt><i>dbname</i></tt>
</dt>
<dd>Specifies the name of the database to be reorganized. If this is not specified and <tt>-a</tt> (or <tt>--all</tt>) is not used, the database name is read from the environment variable <tt>PGDATABASE</tt>. If that is not set, the user name specified for the connection is used. </dd>
<dt>
<tt>-t</tt><tt><i>table</i></tt><br/>
<tt>--table</tt><tt><i>table</i></tt>
</dt>
<dd>Reorganize <tt><i>table</i></tt> only. If you don't specify this option, all tables in specified databases are reorganized.</dd>
</dl>
</div>
<div><aname="environment"></a>
<h2>Environment</h2><div>
<dl>
<dt>
<tt>PGDATABASE</tt><br/>
<tt>PGHOST</tt><br/>
<tt>PGPORT</tt><br/>
<tt>PGUSER</tt>
</dt>
<dd>Default connection parameters</dd>
</dl>
</div>
<p>This utility, like most other PostgreSQL utilities, also uses the environment variables supported by libpq (see <ahref="http://developer.postgresql.org/pgdocs/postgres/libpq-envars.html">Environment Variables</a>).</p>
</div>
<div><aname="diagnostics"></a>
<h2>Diagnostics</h2>
<p>Error messages are reported when pg_reorg fails.
The following list shows the cause of errors.</p>
<p>You need to cleanup by hand after fatal erros.
To cleanup, execute $PGHOME/share/contrib/uninstall_pg_reorg.sql to the database where the error occured and then execute $PGHOME/share/contrib/pg_reorg.sql. (Do uninstall and reinstall.)</p>