Skip to content


Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time

PgToolkit - tools for PostgreSQL maintenance

Join the chat at

Currently the package contains the only tool pgcompact, we are planning to add much more in the future. Stay tuned.

The list of changes can be found in The To-Do List is in


The easiest way to deploy the toolkit is to download the latest stable version, unpack the archive and copy the autonomous scripts from the fatpack directory to your bin or to just add this directory to your PATH. The autonomous scripts are packed with all the dependencies and need Perl >=5.8.8 to be installed only.

If you need a specific version or branch of the tools, replace the stable with its name string in the URL.

Another way is to git clone the repository

git clone

or to svn checkout it

svn checkout

Do not forget to switch to the necessary version branch afterwards.

You can also use the autonomous scripts in the fatpack directory or the non-autonomous versions of them in the bin directory. For the latter you need the lib directory either to be in the same sub-directory with bin or to be in your PERL5LIB.


A tool to reduce bloat for tables and indexes without heavy locks and full table rebuilding.

Initially the tool is an automation of the solutions proposed in these publications:

If pgstattuple is installed pgcompact uses it to get a better statistics. It is highly recommended to be for TOASTed tables and indexes.

Usage examples

Shows user manual.

pgcompact --man

Compacts all the bloated tables in all the databases in the cluster plus their bloated indexes. Prints additional progress information.

pgcompact --all --reindex --verbosity info

Compacts all the bloated tables in the billing database and their bloated indexes excepts ones that are in the pgq schema.

pgcompact --dbname billing --exclude-schema pgq --reindex


  • Requires no dependencies except Perl >=5.8.8, so it can just be copied to server and run
  • Works via DBD::Pg, DBD::PgPP or even psql if there are no former ones, detects and chooses the best option automatically
  • Processes either whole cluster or specified tables, schemes, databases only
  • Has an ability to exclude tables, schemes or databases from processing
  • Performs bloat analysis and processes those tables that have it only. We recommend to install pgstattuple for more precise estimations.
  • Uses non blocking reindex techniques
  • Performs indexes bloat analysis and processes only the required ones
  • Analyses and rebuilds bloated unique constraints and primary keys where possible
  • Provides TOAST tables and their indexes bloat information and rebuilding instructions
  • Incremental processing, in other words one can stop the process and continue it at any time later
  • Dynamically adjusts behavior for current load of database to not affect its performance
  • Can be run in several parallel sessions on the same instance to process the tables faster
  • Instructs administrators, supplying them with ready to use DDL, to manually rebuild database objects that can not be rebuilt automatically

See Also

License and Copyright

Copyright © 2011-2014 Sergey Konoplev, Maxim Boguk

PgToolkit is released under the PostgreSQL License, read for additional information.



Thank you:

  • DenisBY for bug reports and testing
  • for a huge amount of ideas and lots of testing
  • Maxim Boguk for ideas, testing and useful hints
  • Lonni Friedman for your ideas
  • Rural Hunter for ideas and testing
  • Hubert "depesz" Lubaczewski for testing, useful hints and code contributions
  • Gonzalo Gil for testing.


Tools for PostgreSQL maintenance







No packages published