2012-09-22 19:58:49 +01:00
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
2009-12-28 08:25:00 +00:00
< html >
< head >
2012-11-10 22:33:57 +00:00
< title > pg_repack< / title >
< link rel = "home" title = "pg_repack " href = "index.html" >
2012-09-22 19:58:49 +01:00
< link rel = "stylesheet" TYPE = "text/css" href = "style.css" >
2009-12-28 08:25:00 +00:00
< meta http-equiv = "Content-Type" content = "text/html; charset=UTF-8" >
< / head >
< body >
2012-11-10 22:33:57 +00:00
< h1 id = "pg_repack" > pg_repack 1.1.7< / h1 >
2010-03-25 07:13:16 +00:00
< div class = "navigation" >
< a href = "index.html" > Top< / a > >
2012-11-10 22:33:57 +00:00
< a href = "pg_repack.html" > pg_repack< / a >
2012-09-22 19:58:49 +01:00
< / div >
< hr >
2009-12-28 08:25:00 +00:00
< div class = "index" >
< ol >
< li > < a href = "#name" > Name< / a > < / li >
< li > < a href = "#synopsis" > Synopsis< / a > < / li >
< li > < a href = "#description" > Description< / a > < / li >
< li > < a href = "#examples" > Examples< / a > < / li >
< li > < a href = "#options" > Options< / a > < / li >
< li > < a href = "#environment" > Environment< / a > < / li >
< li > < a href = "#restrictions" > Restrictions< / a > < / li >
< li > < a href = "#details" > Details< / a > < / li >
< li > < a href = "#install" > Installations< / a > < / li >
< li > < a href = "#requirement" > Requirements< / a > < / li >
2011-08-07 04:24:39 +00:00
< li > < a href = "#releases" > Releases< / a > < / li >
2009-12-28 08:25:00 +00:00
< li > < a href = "#seealso" > See Also< / a > < / li >
< / ol >
< / div >
< h2 id = "name" > Name< / h2 >
2012-11-10 22:33:57 +00:00
pg_repack -- Reorganize tables in PostgreSQL databases without any locks.
2009-12-28 08:25:00 +00:00
< h2 id = "synopsis" > Synopsis< / h2 >
< p >
2012-11-10 22:33:57 +00:00
pg_repack [OPTIONS]
2009-12-28 08:25:00 +00:00
< / p >
2010-03-25 07:13:16 +00:00
< p > The following options can be specified in OPTIONS.
See also "< a href = "#options" > Options< / a > " for details.< / p >
< ul >
< li > Reorg Options< ul >
2012-09-22 19:58:49 +01:00
< li > -a, --all : reorganize all databases< / li >
2010-03-25 07:13:16 +00:00
< li > -o [--order-by] columns [,...]< / li >
< li > -n [--no-order]< / li >
< li > -t [--table] table< / li >
< li > -T [--wait-timeout] seconds< / li >
< li > -Z [--no-analyze]< / li >
< / ul > < / li >
< li > Connection Options< ul >
< li > -d, --dbname=DBNAME : database to connect< / li >
< li > -h, --host=HOSTNAME : database server host or socket directory< / li >
< li > -p, --port=PORT : database server port< / li >
< li > -U, --username=USERNAME : user name to connect as< / li >
2010-06-18 01:12:28 +00:00
< li > -w, --no-password : never prompt for password< / li >
2010-03-25 07:13:16 +00:00
< li > -W, --password : force password prompt< / li >
< / ul > < / li >
< li > Generic Options< ul >
< li > -e, --echo : echo queries< / li >
< li > -E, --elevel=LEVEL : set output message level< / li >
< li > --help : show the help, then exit< / li >
< li > --version : output version information, then exit< / li >
< / ul > < / li >
< / ul >
2009-12-28 08:25:00 +00:00
< h2 id = "description" > Description< / h2 >
2012-11-10 22:33:57 +00:00
< p > pg_repack is an utility program to reorganize tables in PostgreSQL databases.
2010-04-21 09:25:20 +00:00
Unlike < a href = "http://developer.postgresql.org/pgdocs/postgres/app-clusterdb.html" > clusterdb< / a > , it doesn't block any selections and updates during reorganization.
2009-12-28 08:25:00 +00:00
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 >
< / ul >
< h2 id = "examples" > Examples< / h2 >
2012-09-22 19:58:49 +01:00
< p > Execute the following command to perform an online CLUSTER of all tables in test database.< / p >
2012-11-10 22:33:57 +00:00
< PRE > < SAMP > $ < / SAMP > < KBD > pg_repack test< / KBD > < / PRE >
2012-09-22 19:58:49 +01:00
< p > Execute the following command to perform an online VACUUM FULL to foo table in test database.< / p >
2012-11-10 22:33:57 +00:00
< PRE > < SAMP > $ < / SAMP > < KBD > pg_repack --no-order --table foo -d test< / KBD > < / PRE > < p >
2009-12-28 08:25:00 +00:00
< / p >
< h2 id = "options" > Options< / h2 >
2012-11-10 22:33:57 +00:00
< p > pg_repack has the following command line options:< / p >
2009-12-28 08:25:00 +00:00
2010-03-25 07:13:16 +00:00
< h3 > Reorg Options< / h3 >
2009-12-28 08:25:00 +00:00
< p > Options to order rows.
2012-11-10 22:33:57 +00:00
If not specified, pg_repack performs an online CLUSTER using cluster indexes.
2009-12-28 08:25:00 +00:00
Only one option can be specified.
2010-03-25 07:13:16 +00:00
2012-09-22 19:58:49 +01:00
You may also specify target tables or databases.
2009-12-28 08:25:00 +00:00
< / p >
< dl >
2012-09-22 19:58:49 +01:00
< dt > -n< br > --no-order< / dt >
2009-12-28 08:25:00 +00:00
< dd > Do online VACUUM FULL.< / dd >
2012-09-22 19:58:49 +01:00
< dt > -o columns [,...]< br >
2010-03-25 07:13:16 +00:00
--order-by=columns [,...]< / dt >
2009-12-28 08:25:00 +00:00
< dd > Do online CLUSTER ordered by specified columns.< / dd >
2010-03-25 07:13:16 +00:00
< dt >
2012-09-22 19:58:49 +01:00
-t table< br >
2010-03-25 07:13:16 +00:00
--table=table
< / dt >
< dd > Reorganize table only. If you don't specify this option, all tables in specified databases are reorganized.< / dd >
< dt >
2012-09-22 19:58:49 +01:00
-T seconds< br >
2010-03-25 07:13:16 +00:00
--wait-timeout=seconds
< / dt >
< dd >
2012-11-10 22:33:57 +00:00
pg_repack needs to take an exclusive lock at the end of the reorganization.
2010-03-25 07:13:16 +00:00
This setting controls how long it wait for acquiring the lock in seconds.
2012-11-10 22:33:57 +00:00
If the lock cannot be taken even after the duration, pg_repack forces to cancel conflicted queries.
Also, if the server version is 8.4 or newer, pg_repack forces to disconnect conflicted backends after twice time passed.
2010-03-25 07:13:16 +00:00
The default is 60 seconds.
< / dd >
2012-09-22 19:58:49 +01:00
< dt > -Z< br > --no-analyze< / dt >
2010-03-25 07:13:16 +00:00
< dd > Disable ANALYZE after the reorganization.
If not specified, run ANALYZE after the reorganization.< / dd >
< / dl >
2009-12-28 08:25:00 +00:00
2010-03-25 07:13:16 +00:00
< h3 > Connection Options< / h3 >
2009-12-28 08:25:00 +00:00
< p >
2010-03-25 07:13:16 +00:00
Options to connect to servers.
2009-12-28 08:25:00 +00:00
You cannot use --all and --dbname or --table together.
< / p >
< dl >
2012-09-22 19:58:49 +01:00
< dt > -a< br > --all< / dt >
2009-12-28 08:25:00 +00:00
< dd > Reorganize all databases.< / dd >
< dt >
2012-09-22 19:58:49 +01:00
-d dbname< br >
2009-12-28 08:25:00 +00:00
--dbname dbname
< / dt >
< dd > Specifies the name of the database to be reorganized. If this is not specified and -a (or --all) is not used, the database name is read from the environment variable PGDATABASE. If that is not set, the user name specified for the connection is used. < / dd >
2012-09-22 19:58:49 +01:00
< dt > -h host< br >
2010-03-25 07:13:16 +00:00
--host host< / 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 >
2009-12-28 08:25:00 +00:00
2012-09-22 19:58:49 +01:00
< dt > -p port< br >
2010-03-25 07:13:16 +00:00
--port port< / dt >
< dd > Specifies the TCP port or local Unix domain socket file extension on which the server is listening for connections.< / dd >
2012-09-22 19:58:49 +01:00
< dt > -U username< br >
2010-03-25 07:13:16 +00:00
--username username< / dt >
< dd > User name to connect as. < / dd >
2009-12-28 08:25:00 +00:00
2012-09-22 19:58:49 +01:00
< dt > -w< br >
2010-06-18 01:12:28 +00:00
--no-password< / dt >
< dd >
Never issue a password prompt.
If the server requires password authentication and a password is not available by other means such as a .pgpass file, the connection attempt will fail.
This option can be useful in batch jobs and scripts where no user is present to enter a password.
< / dd >
2012-09-22 19:58:49 +01:00
< dt > -W< br >
2010-06-18 01:12:28 +00:00
--password< / dt >
< dd > Force the program to prompt for a password before connecting to a database.< / dd >
2012-11-10 22:33:57 +00:00
< dd > This option is never essential, since the program will automatically prompt for a password if the server demands password authentication. However, pg_repack will waste a connection attempt finding out that the server wants a password. In some cases it is worth typing -W to avoid the extra connection attempt. < / dd >
2010-03-25 07:13:16 +00:00
< / dl >
< h3 > Generic Options< / h3 >
< dl >
2012-09-22 19:58:49 +01:00
< dt > -e< br > --echo< / dt >
2010-03-25 07:13:16 +00:00
< dd > Echo commands sent to server.< / dd >
2012-09-22 19:58:49 +01:00
< dt > -E< br > --elevel< / dt >
2010-03-25 07:13:16 +00:00
< dd > Choose the output message level from DEBUG, INFO, NOTICE, WARNING, ERROR, LOG, FATAL, and PANIC.
The default is INFO.< / dd >
< dt > --help< / dt >
< dd > Show usage of the program.< / dd >
< dt > --version< / dt >
< dd > Show the version number of the program.< / dd >
2009-12-28 08:25:00 +00:00
< / dl >
< h2 id = "environment" > Environment< / h2 >
< dl >
< dt >
2012-09-22 19:58:49 +01:00
PGDATABASE< br >
PGHOST< br >
PGPORT< br >
2009-12-28 08:25:00 +00:00
PGUSER
< / dt >
< dd > Default connection parameters< / dd >
< / dl >
< p > This utility, like most other PostgreSQL utilities, also uses the environment variables supported by libpq (see < a href = "http://developer.postgresql.org/pgdocs/postgres/libpq-envars.html" > Environment Variables< / a > ).< / p >
< h2 id = "diagnostics" > Diagnostics< / h2 >
2012-11-10 22:33:57 +00:00
< p > Error messages are reported when pg_repack fails.
2009-12-28 08:25:00 +00:00
The following list shows the cause of errors.< / p >
2012-09-22 19:58:49 +01:00
< p > You need to cleanup by hand after fatal errors.
2012-11-10 22:33:57 +00:00
To cleanup, execute $PGHOME/share/contrib/uninstall_pg_repack.sql to the database where the error occured and then execute $PGHOME/share/contrib/pg_repack.sql. (Do uninstall and reinstall.)< / p >
2009-12-28 08:25:00 +00:00
< dl >
2012-11-10 22:33:57 +00:00
< dt > pg_repack : repack database "template1" ... skipped< / dt >
< dd > pg_repack is not installed in the database when --all option is specified.< / dd >
< dd > Do register pg_repack to the database.< / dd >
2009-12-28 08:25:00 +00:00
2012-11-10 22:33:57 +00:00
< dt > ERROR: pg_repack is not installed< / dt >
< dd > pg_repack is not installed in the database specified by --dbname.< / dd >
< dd > Do register pg_repack to the database.< / dd >
2009-12-28 08:25:00 +00:00
< dt > ERROR: relation "table" has no primary key< / dt >
< dd > The target table doesn't have PRIMARY KEY.< / dd >
< dd > Define PRIMARY KEY to the table. (ALTER TABLE ADD PRIMARY KEY)< / dd >
< dt > ERROR: relation "table" has no cluster key< / dt >
< dd > The target table doesn't have CLUSTER KEY.< / dd >
< dd > Define CLUSTER KEY to the table. (ALTER TABLE CLUSTER)< / dd >
2012-11-10 22:33:57 +00:00
< dt > pg_repack : query failed: ERROR: column "col" does not exist< / dt >
2009-12-28 08:25:00 +00:00
< dd > The target table doesn't have columns specified by --order-by option.< / dd >
< dd > Specify existing columns.< / dd >
2012-11-10 22:33:57 +00:00
< dt > ERROR: permission denied for schema repack< / dt >
2009-12-28 08:25:00 +00:00
< dd > Permission error.< / dd >
2012-11-10 22:33:57 +00:00
< dd > pg_repack must be executed by superusers.< / dd >
2009-12-28 08:25:00 +00:00
2012-11-10 22:33:57 +00:00
< dt > pg_repack : query failed: ERROR: trigger "z_repack_trigger" for relation "tbl" already exists< / dt >
< dd > The target table already has a trigger named "z_repack_trigger".< / dd >
2009-12-28 08:25:00 +00:00
< dd > Delete or rename the trigger.< / dd >
2012-11-10 22:33:57 +00:00
< dt > pg_repack : trigger conflicted for tbl< / dt >
< dd > The target table already has a trigger which follows by "z_repack_trigger" in alphabetical order.< / dd >
2009-12-28 08:25:00 +00:00
< dd > Delete or rename the trigger.< / dd >
< / dl >
< h2 id = "restrictions" > Restrictions< / h2 >
2012-11-10 22:33:57 +00:00
< p > pg_repack has the following restrictions.
2009-12-28 08:25:00 +00:00
Be careful to avoid data corruptions.< / p >
< h3 > Temp tables< / h3 >
2012-11-10 22:33:57 +00:00
< p > pg_repack cannot reorganize temp tables.< / p >
2009-12-28 08:25:00 +00:00
< h3 > GiST indexes< / h3 >
2012-11-10 22:33:57 +00:00
< p > pg_repack cannot reorganize tables using GiST indexes.< / p >
2009-12-28 08:25:00 +00:00
< h3 > DDL commands< / h3 >
2012-11-10 22:33:57 +00:00
< p > You cannot do DDL commands < strong > except< / strong > VACUUM and ANALYZE during pg_repack.
In many cases pg_repack will fail and rollback collectly, but there are some cases which may result in data-corruption .< / p >
2009-12-28 08:25:00 +00:00
< dl >
< dt > TRUNCATE< / dt >
2012-11-10 22:33:57 +00:00
< dd > TRUNCATE is lost. Deleted rows still exist after pg_repack.< / dd >
2009-12-28 08:25:00 +00:00
< dt > CREATE INDEX< / dt >
< dd > It causes index corruptions.< / dd >
< dt > ALTER TABLE ... ADD COLUMN< / dt >
< dd > It causes lost of data. Newly added columns are initialized with NULLs.< / dd >
< dt > ALTER TABLE ... ALTER COLUMN TYPE< / dt >
< dd > It causes data corruptions.< / dd >
< dt > ALTER TABLE ... SET TABLESPACE< / dt >
< dd > It causes data corruptions by wrong relfilenode.< / dd >
< / dl >
< h2 id = "details" > Details< / h2 >
2012-11-10 22:33:57 +00:00
< p > pg_repack creates a work table in the repack schema and sorts the rows in this table.
2012-09-22 19:58:49 +01:00
Then, it updates the system catalogs directly to swap the work table and the original one.< / p >
2009-12-28 08:25:00 +00:00
< h2 id = "install" > Installations< / h2 >
2011-04-29 05:06:48 +00:00
< p >
2012-11-10 22:33:57 +00:00
pg_repack can be built with "make" on UNIX or Linux.
2011-04-29 05:06:48 +00:00
pgxs build framework is used automatically.
2012-09-22 19:58:49 +01:00
Before building, you might need to install postgres packages for developer (postgresql-devel, etc.)
2011-04-29 05:06:48 +00:00
and add < code > pg_config< / code > to your $PATH.
< / p >
2012-11-10 22:33:57 +00:00
< pre > $ cd pg_repack
2011-04-29 05:06:48 +00:00
$ make
2010-07-09 04:54:27 +00:00
$ su
2011-04-29 05:06:48 +00:00
$ make install< / pre >
< p >
You can also use Microsoft Visual C++ 2010 to build the program on Windows.
There are project files in the msvc folder.
< / p >
2010-07-09 04:54:27 +00:00
< p > Start PostgreSQL and execute the script to register functions to your database.< / p >
< pre > $ pg_ctl start
2012-11-10 22:33:57 +00:00
$ psql -f $PGSHARE/contrib/pg_repack.sql -d your_database< / pre >
2011-04-29 05:06:48 +00:00
< p > (NOTE: < code > CREATE EXTENSION< / code > is not supported yet.)< / p >
2009-12-28 08:25:00 +00:00
< h2 id = "requirement" > Requirements< / h2 >
< dl >
2012-09-22 19:58:49 +01:00
< dt > PostgreSQL versions< / dt >
< dd > PostgreSQL 8.2, 8.3, 8.4, 9.0, 9.1, 9.2< / dd >
2009-12-28 08:25:00 +00:00
< dt > OS< / dt > < dd > RHEL 5.2, Windows XP SP3< / dd >
2012-09-22 19:58:49 +01:00
< dt > Disks< / dt > < dd > Requires free disk space twice as large as the target
table(s) and indexes. For example, if the total size of the tables and
indexes to be reorganized is 1GB, an additional 2GB of disk space is
required.< / dd >
2009-12-28 08:25:00 +00:00
< / dl >
2011-08-07 04:20:23 +00:00
< h2 id = "releases" > Releases< / h2 >
< ul >
< li > 1.1.7 (2011-08-07)< ul >
< li > Bugfix: VIEWs and FUNCTIONs could be corrupted that used a reorganized table which has a dropped column.< / li >
< li > Supports PostgreSQL 9.1 and 9.2dev. (but EXTENSION is not yet)< / li >
< / ul > < / li >
< / ul >
2009-12-28 08:25:00 +00:00
< h2 id = "seealso" > See Also< / h2 >
< a href = "http://developer.postgresql.org/pgdocs/postgres/app-clusterdb.html" > clusterdb< / a > ,
< a href = "http://developer.postgresql.org/pgdocs/postgres/app-vacuumdb.html" > vacuumdb< / a >
2012-09-22 19:58:49 +01:00
< hr >
2010-03-25 07:13:16 +00:00
< div class = "navigation" >
< a href = "index.html" > Top< / a > >
2012-11-10 22:33:57 +00:00
< a href = "pg_repack.html" > pg_repack< / a >
2012-09-22 19:58:49 +01:00
< / div >
2010-03-25 07:13:16 +00:00
< div >
2011-04-29 05:06:48 +00:00
< p class = "footer" >
2012-09-22 19:58:49 +01:00
Portions Copyright (c) 2008-2011, NIPPON TELEGRAPH AND TELEPHONE CORPORATION< br >
2011-04-29 05:06:48 +00:00
Portions Copyright (c) 2011, Itagaki Takahiro
< / p >
2012-09-22 19:58:49 +01:00
< / div >
2009-12-28 08:25:00 +00:00
< script type = "text/javascript" >
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
< / script >
< script type = "text/javascript" >
try {
var pageTracker = _gat._getTracker("UA-10244036-4");
pageTracker._trackPageview();
} catch(err) {}< / script >
< / body >
< / html >