Restore Failed due to Key (plugin_name, key)=(discourse-data-explorer, q:-1) is duplicated

When I upgrade my discourse, I found it not working. I can see the category page, but cannot read the top or latest page, like the latest page:

image

I’ve already deleted all the plugins, including the official and the non-official plugins. But the problem still exists.

So I tried to restore the backup, but I found the following message.

[2020-07-12 01:16:20] ERROR:  could not create unique index "index_plugin_store_rows_on_plugin_name_and_key"
[2020-07-12 01:16:20] DETAIL:  Key (plugin_name, key)=(discourse-data-explorer, q:-1) is duplicated.
[2020-07-12 01:16:20] EXCEPTION: psql failed: DETAIL:  Key (plugin_name, key)=(discourse-data-explorer, q:-1) is duplicated.

[2020-07-12 01:16:20] /var/www/discourse/lib/backup_restore/database_restorer.rb:95:in `restore_dump'
/var/www/discourse/lib/backup_restore/database_restorer.rb:26:in `restore'
/var/www/discourse/lib/backup_restore/restorer.rb:49:in `run'
/var/www/discourse/lib/backup_restore.rb:188:in `block in start!'

1 Like

There is a corrupt data in plugin store.

If you do not care about any of the custom data you saved in data explorer try:

./launcher enter app
rails c
PluginStore.where(plugin_name: 'discourse-data-explorer').delete_all
4 Likes
root@HFT-app:/var/www/discourse# rails c
[1] pry(main)> PluginStore.where(plugin_name: 'discourse-data-explorer').delete_all
NoMethodError: undefined method `where' for PluginStore:Class
Did you mean?  when
from (pry):1:in `__pry__'
[2] pry(main)>


Seems sth wrong.

Can you give me some further information?

Should be PluginStoreRow, not PluginStore. Try this:

./launcher enter app
rails c
PluginStoreRow.where(plugin_name: 'discourse-data-explorer').delete_all

:warning: This will irreversibly delete all data-explorer data from your site

4 Likes

Then what should I do?
The forum is now not readable now, seems latest.json lost.

I would try rebuilding the app. If that doesn’t work, then check /logs for errors.

1 Like

how to see the logs?

If you mean the rebuild process logs, then here’s the error message when rebuilding(all red words are here).


2020/07/14 11:33:39 socat[26] E connect(6, AF=1 "/shared/postgres_run/.s.PGSQL.5432", 36): No such file or directory


#------




2020-07-14 11:33:42.023 UTC [49] LOG:  database system is ready to accept connections
I, [2020-07-14T11:33:46.972466 #1]  INFO -- :
I, [2020-07-14T11:33:46.972792 #1]  INFO -- : > su postgres -c 'createdb discourse' || true
2020-07-14 11:33:47.025 UTC [62] postgres@postgres ERROR:  database "discourse" already exists
2020-07-14 11:33:47.025 UTC [62] postgres@postgres STATEMENT:  CREATE DATABASE discourse;
createdb: error: database creation failed: ERROR:  database "discourse" already exists
I, [2020-07-14T11:33:47.026573 #1]  INFO -- :
I, [2020-07-14T11:33:47.026936 #1]  INFO -- : > su postgres -c 'psql discourse -c "create user discourse;"' || true
2020-07-14 11:33:47.083 UTC [73] postgres@discourse ERROR:  role "discourse" already exists
2020-07-14 11:33:47.083 UTC [73] postgres@discourse STATEMENT:  create user discourse;
ERROR:  role "discourse" already exists


hi, how to run the code please?

@xiasummer

If and only if (IFF) you have a CONFIRMED full backup of your current DB and your uploads folder; you can move or copy that (those) backups out of the shared directory, for example (but adapt for your configuration):

mv  /var/discourse/shared  /tmp

Make sure you have full backups of the DB first, of course.

Then, you can rebuild from scratch:

./launcher rebuild app

and then you can restore from the command line:

cp -rf /tmp/shared/backups/default /var/discourse/shared/standalone/backups

Then you can do a restore from the command line using your latest backup in the normal way.

This will restore your application backup to where it was at the time of your last GOOD and FULL backup.

This is only recommended IF you have a full, recent backup of your entire DB and your uploads file.

If you performed a backup without the uploads, you can find them, of course, in /tmp/shared/standalone/uploads and you can copy them over as follows:

cp -rf /tmp/shared/standalone/uploads/* /var/discourse/shared/standalone/uploads

Then after all is working again, and you are confident the restore went as you hoped, you can then, of course, delete your staging directory:

rm -rf /tmp/shared

This is one way to proceed.

There may be other ways, but this is how I would proceed if I had a current, good full backup.

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.