Reindex concurrently

From UVOO Tech Wiki
Jump to navigation Jump to search

https://www.postgresql.org/docs/current/sql-reindex.html#SQL-REINDEX-CONCURRENTLY

There was a bug with it that was patched in 14.4 here is note on that https://www.postgresql.org/about/news/postgresql-144-released-2470/#:~:text=The%20PostgreSQL%20Global%20Development%20Group,CONCURRENTLY%20or%20REINDEX%20CONCURRENTLY%20commands.

You can detect if a B-tree index (the default index type) has data corruption using the pg_amcheck command with the --heapallindexed flag. For example:

pg_amcheck --heapallindexed database

If pg_amcheck detects corruption or if you ran CREATE INDEX CONCURRENTLY or REINDEX CONCURRENTLY on any other index type (e.g. GiST, GIN, etc.), please follow the instructions below.

Once you upgrade your system to PostgreSQL 14.4, you can fix any silent data corruption using REINDEX CONCURRENTLY. For example, if you have an index named elephant_idx that has data corruption, you can run the following command on PostgreSQL 14.4 to fix it:

REINDEX CONCURRENTLY elephant_idx;

You can use the reindexdb command to reindex all indexes across your cluster. reindexdb also has a --jobs flag that lets you run reindex operations in parallel. For example, to reindex your entire PostgreSQL cluster using <N> parallel jobs, you can run the following command:

reindexdb --all --concurrently --jobs <N>