Waiting for PostgreSQL 13 – Add support for –jobs in reindexdb

On 27th of July 2019, Michael Paquier committed patch:

Add support for --jobs in reindexdb
 
When doing a schema-level or a database-level operation, a list of
relations to build is created which gets processed in parallel using
multiple connections, based on the recent refactoring for parallel slots
in src/bin/scripts/.  System catalogs are processed first in a
serialized fashion to prevent deadlocks, followed by the rest done in
parallel.
 
This new option is not compatible with --system as reindexing system
catalogs in parallel can lead to deadlocks, and with --index as there is
no conflict handling for indexes rebuilt in parallel depending in the
same relation.
 
Author: Julien Rouhaud
 
Discussion: https://postgr.es/m/CAOBaU_YrnH_Jqo46NhaJ7uRBiWWEcS40VNRQxgFbqYo9kApUsg@mail.gmail.com

This is not something that is new, as we could get similar thing done previously with clever scripting, but now, thanks to this patch – scripting is no longer necessary.

Usage is extremely simple:

=$ time reindexdb -j 8 depesz_explain
 
real    0m6.789s
user    0m0.012s
sys     0m0.008s

This is 8 core system. When I ran without -j I got much worse time:

=$ time reindexdb depesz_explain
 
real    0m24.137s
user    0m0.001s
sys     0m0.004s

Great addition, thanks Julien and Michael.