Estoy intentando migrar un foro a un nuevo servidor. Ambos servidores ejecutan la última versión de discourse docker. Al importar la copia de seguridad a través de la línea de comandos, obtengo el siguiente error:
ERROR: no se pudo crear el índice único «index_incoming_referers_on_path_and_incoming_domain_id»
DETAIL: La clave (path, incoming_domain_id)=(«/search/», 418) está duplicada.
EXCEPTION: psql falló: DETAIL: La clave (path, incoming_domain_id)=(«/search/», 418) está duplicada.
Esto parece ser el mismo error o uno similar a:
Sin embargo, en mi caso, los registros duplicados están en la ruta /search/ en lugar de /m/search, como ocurre en el hilo enlazado anteriormente.
Me he conectado al contenedor en el servidor antiguo (./launcher enter app) y en la consola de Rails (rails c) he intentado buscar los registros duplicados usando:
IncomingReferer.where(path: "/search")
y IncomingReferer.where("path LIKE '%/search%'")
Sin embargo, esto resulta en que se muestren cientos de registros. ¿Cómo puedo averiguar qué registros están duplicados y cómo puedo eliminarlos de forma segura y reconstruirlos? El foro está funcionando correctamente en el servidor antiguo, solo necesitamos movernos a hardware nuevo.
The old server doesn’t have a file called PG_VERSION, how can I tell what version its running? I’ve updated the docket install to the latest version today.
The new server (newly bootstrapped) is running postgres V13
cat shared/standalone/postgres_data/PG_VERSION
13
Is there a recommended procedure on how to do this?
I had a topic that had some hints, but I don’t see it anymore. It’s been close to a year since the postgres 12 upgrade.
reindex index index_incoming_referers_on_path_and_incoming_domain_id;
And
ActiveRecord::Base.connection.execute('reindex index index_incoming_referers_on_path_and_incoming_domain_id;')
Are ways to try to rebuild the index. It’ll give you an error and you can then go and delete the errant records. You’ll need to include both the path and the ID.
DELETE FROM incoming_referers WHERE path LIKE '%/search/' AND id IN (6247);
Then rebuild
discourse=# REINDEX SCHEMA CONCURRENTLY public;
WARNING: cannot reindex invalid index "public.incoming_referers_pkey_ccnew" concurrently, skipping
WARNING: cannot reindex invalid index "public.index_incoming_referers_on_path_and_incoming_domain_id_ccnew" concurrently, skipping
WARNING: cannot reindex invalid index "pg_toast.pg_toast_20732_index_ccnew" concurrently, skipping
REINDEX
Then I took another backup, copied it to the new server, and it imported successfully
It would be nice if the backup process could spot duplicates to avoid any issues, I was luckily that I had access to the original server which was still running. If I was restoring a cold backup, this would probably have been more of an issue>