Users are experiencing corrupt indexes in PostgreSQL 12 after upgrading from PG10, causing REINDEX SCHEMA CONCURRENTLY to fail with duplicate key errors. The issue stems from duplicate data in tables like tags, incoming_referers, and users, which prevent unique indexes from being created. Users are advised to identify and delete duplicate rows (e.g., using ilike queries for case-insensitive matches) and then drop invalid indexes with ccnew suffixes, which are left behind when concurrent reindexing fails. These ccnew indexes are temporary and can be safely removed. Once the data is cleaned and invalid indexes dropped, reindexing can succeed. The process is repetitive, requiring multiple attempts, and highlights a potential bug in PostgreSQL’s concurrent reindexing behavior. Some users suggest automating the fix in future Discourse upgrades, but the root cause remains unclear. See solution for steps.
Sorry for bumping this once again, I got a very strange
discourse=# REINDEX SCHEMA CONCURRENTLY public;
ERROR: could not create unique index "index_tags_on_name_ccnew"
DETAIL: Key (name)=(chronicillness) is duplicated.
I’m assuming it can be fixed by the solution suggested above by @riking but I’m unable to figure out how to modify the syntax to suit my case.
The recommended recovery method in such cases is to drop the invalid index and try again to perform REINDEX CONCURRENTLY . The concurrent index created during the processing has a name ending in the suffix ccnew , or ccold if it is an old index definition which we failed to drop. Invalid indexes can be dropped using DROP INDEX , including invalid toast indexes.