Skip to content

Commit 1c82aae

Browse files
committed
Documentation updates for indexes-only mode.
Beena Emerson, with some additional cleanup from me.
1 parent 1e8ac21 commit 1c82aae

File tree

2 files changed

+53
-12
lines changed

2 files changed

+53
-12
lines changed

bin/pg_repack.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ main(int argc, char *argv[])
264264
errmsg("cannot specify --index (-i) and --only-indexes (-x)")));
265265
else if (only_indexes && !table_list.head)
266266
ereport(ERROR, (errcode(EINVAL),
267-
errmsg("cannot repack all indexes of database, specify the table with -t option")));
267+
errmsg("cannot repack all indexes of database, specify the table(s) via --table (-t)")));
268268
else if (alldb)
269269
ereport(ERROR, (errcode(EINVAL),
270270
errmsg("cannot repack specific index(es) in all databases")));

doc/pg_repack.rst

Lines changed: 52 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,9 @@ Options:
122122
-S, --moveidx move repacked indexes to *TBLSPC* too
123123
-o, --order-by=COLUMNS order by columns instead of cluster keys
124124
-n, --no-order do vacuum full instead of cluster
125-
-j, --jobs Use this many parallel jobs for each table
125+
-j, --jobs=NUM Use this many parallel jobs for each table
126+
-i, --index=INDEX move only the specified index
127+
-x, --only-indexes move only indexes of the specified table
126128
-T, --wait-timeout=SECS timeout to cancel other backends on conflict
127129
-Z, --no-analyze don't analyze at end
128130

@@ -149,8 +151,9 @@ Reorg Options
149151
``pg_repack`` extension is not installed will be skipped.
150152

151153
``-t TABLE``, ``--table=TABLE``
152-
Reorganize the specified table only. By default, all eligible tables in
153-
the target databases are reorganized.
154+
Reorganize the specified table(s) only. Multiple tables may be
155+
reorganized by writing multiple `-t` switches. By default, all eligible
156+
tables in the target databases are reorganized.
154157

155158
``-o COLUMNS [,...]``, ``--order-by=COLUMNS [,...]``
156159
Perform an online CLUSTER ordered by the specified columns.
@@ -174,6 +177,15 @@ Reorg Options
174177
Move the indexes too of the repacked tables to the tablespace specified
175178
by the option ``--tablespace``.
176179

180+
``-i``, ``--index``
181+
Repack the specified index(es) only. Multiple indexes may be repacked
182+
by writing multiple `-i` switches. May be used in conjunction with
183+
``--tablespace`` to move the index to a different tablespace.
184+
185+
``-x``, ``--only-indexes``
186+
Repack only the indexes of the specified table(s), which must be specified
187+
with the ``--table`` option.
188+
177189
``-T SECS``, ``--wait-timeout=SECS``
178190
pg_repack needs to take an exclusive lock at the end of the
179191
reorganization. This setting controls how many seconds pg_repack will
@@ -184,8 +196,8 @@ Reorg Options
184196
twice this timeout has passed. The default is 60 seconds.
185197

186198
``-Z``, ``--no-analyze``
187-
Disable ANALYZE after the reorganization. If not specified, run ANALYZE
188-
after the reorganization.
199+
Disable ANALYZE after a full-table reorganization. If not specified, run
200+
ANALYZE after the reorganization.
189201

190202

191203
Connection Options
@@ -271,10 +283,18 @@ Perform an online CLUSTER of all the clustered tables in the database
271283

272284
$ pg_repack test
273285

274-
Perform an online VACUUM FULL on the table ``foo`` in the database ``test``
275-
(an eventual cluster index is ignored)::
286+
Perform an online VACUUM FULL on the tables ``foo`` and ``bar`` in the
287+
database ``test`` (an eventual cluster index is ignored)::
288+
289+
$ pg_repack --no-order --table foo --table bar test
290+
291+
Move all indexes of table ``foo`` to tablespace ``tbs``::
292+
293+
$ pg_repack -d test --table foo --only-indexes --tablespace tbs
294+
295+
Move the specified index to tablespace ``tbs``::
276296

277-
$ pg_repack --no-order --table foo -d test
297+
$ pg_repack -d test --index idx --tablespace tbs
278298

279299

280300
Diagnostics
@@ -349,6 +369,22 @@ WARNING: trigger "trg" conflicting on table "tbl"
349369

350370
ALTER TRIGGER zzz_my_trigger ON sometable RENAME TO yyy_my_trigger;
351371

372+
ERROR: Another pg_repack command may be running on the table. Please try again
373+
later.
374+
375+
There is a chance of deadlock when two concurrent pg_repack commands are run
376+
on the same table. So, try to run the command after some time.
377+
378+
WARNING: Error creating index: ERROR: relation "index_xxxxx" already exists
379+
DETAIL: An invalid index may have been left behind by a previous pg_repack on
380+
the table which was interrupted. Please use DROP INDEX "schema"."index_xxxxx"
381+
to remove this index and try again.
382+
383+
A temporary index apparently created by pg_repack has been left behind, and
384+
we do not want to risk dropping this index ourselves. If the index was in
385+
fact created by an old pg_repack job which didn't get cleaned up, you
386+
should just use DROP INDEX and try the repack command again.
387+
352388

353389
Restrictions
354390
------------
@@ -395,9 +431,13 @@ ALTER TABLE ... SET TABLESPACE
395431
Details
396432
-------
397433

398-
pg_repack creates a work table in the repack schema and sorts the rows in this
399-
table. Then, it updates the system catalogs directly to swap the work table
400-
and the original one.
434+
To perform full table repacks, pg_repack creates a work table in the "repack"
435+
schema and sorts the rows in this table. Then, it updates the system catalogs
436+
directly to swap the work table and the original one.
437+
438+
To perform index only repacks, pg_repack creates its work index on the target
439+
table and then updates the system catalogs directly to swap the work index and
440+
the original index.
401441

402442

403443
Releases
@@ -413,6 +453,7 @@ Releases
413453
* Bugfix: correctly handle key indexes with options such as DESC, NULL
414454
FIRST/LAST, COLLATE (pg_repack issue #3).
415455
* More helpful program output and error messages.
456+
* Added feature to repack indexes only.
416457

417458
* pg_repack 1.1.8
418459

0 commit comments

Comments
 (0)