Database rebuild ERROR: cannot execute REINDEX during recovery
Description
After upgrading the operating system for PostgreSQL, attempts to run REINDEX DATABASE gitlabhq_production;
returns:
gitlabhq_production=# REINDEX DATABASE gitlabhq_production;
ERROR: cannot execute REINDEX during recovery
Environment
- PosgreSQL using Patroni
Impacted offerings:
- GitLab Self-Managed
Impacted versions:
- All versions
Solution
- Confirm the primary node (Leader) of the cluster. if the
REINDEX DATABASE gitlabhq_production;
was executed in the primary node (Leader) of Patroni. - Re-run
REINDEX DATABASE gitlabhq_production;
on the primary node.
Cause
This can happen if the command was run on the secondary node.
Commands like REINDEX DATABASE
must be executed on the primary node (Leader) rather than the secondary node (Replica).
You cannot execute changes on the replica.
Additional Information
- The "Check replication status" section in the documentation describes how to find a current Leader.