J’essaie de migrer un forum vers un nouveau serveur. Les deux serveurs exécutent la dernière version de Discourse Docker. Lors de l’importation de la sauvegarde via la ligne de commande, j’obtiens l’erreur suivante :
ERREUR : impossible de créer l'index unique « index_incoming_referers_on_path_and_incoming_domain_id »
DÉTAIL : La clé (path, incoming_domain_id)=(« /search/ », 418) est dupliquée.
EXCEPTION : psql a échoué : DÉTAIL : La clé (path, incoming_domain_id)=(« /search/ », 418) est dupliquée.
Cela semble être la même erreur ou une erreur similaire à :
Cependant, dans mon cas, les enregistrements dupliqués se trouvent dans le chemin /search/ plutôt que /m/search comme c’est le cas dans le fil de discussion ci-dessus.
Je me suis connecté au conteneur sur l’ancien serveur (./launcher enter app) et dans la console Rails (rails c), j’ai essayé de rechercher les enregistrements dupliqués en utilisant :
IncomingReferer.where(path: "/search")
et IncomingReferer.where("path LIKE '%/search%'")
Cependant, cela affiche des centaines d’enregistrements. Comment puis-je identifier les enregistrements dupliqués, et comment puis-je les supprimer en toute sécurité et reconstruire ? Le forum fonctionne actuellement correctement sur l’ancien serveur, nous devons juste passer à du nouveau matériel.
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>