# Restore Failed due to Key (plugin\_name, key)=(discourse-data-explorer, q:-1) is duplicated

**URL:** https://meta.discourse.org/t/restore-failed-due-to-key-plugin-name-key-discourse-data-explorer-q-1-is-duplicated/157535
**Category:** Self-hosting
**Created:** [July 13, 2020, 2:00am UTC](https://meta.discourse.org/t/restore-failed-due-to-key-plugin-name-key-discourse-data-explorer-q-1-is-duplicated/157535 "2020-07-13T02:00:22Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![xiasummer](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/xiasummer/32/82790_2.png) [@xiasummer](https://meta.discourse.org/u/xiasummer)
#### Post date: [July 13, 2020, 2:00am UTC](https://meta.discourse.org/t/restore-failed-due-to-key-plugin-name-key-discourse-data-explorer-q-1-is-duplicated/157535/1 "2020-07-13T02:00:22Z")

</div>

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](https://global.discourse-cdn.com/meta/original/3X/f/0/f03f8bfadb76f9f6ed3c02c4f06648b05d2c889a.png)

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.

```plaintext
[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!'

```

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [July 13, 2020, 5:16am UTC](https://meta.discourse.org/t/restore-failed-due-to-key-plugin-name-key-discourse-data-explorer-q-1-is-duplicated/157535/2 "2020-07-13T05:16:50Z")

</div>

There is a corrupt data in plugin store.

If you do not care about any of the custom data you saved in [data explorer](https://meta.discourse.org/t/32566?silent=true) try:

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

```

---

<div class="post-metadata">

### Author: ![xiasummer](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/xiasummer/32/82790_2.png) [@xiasummer](https://meta.discourse.org/u/xiasummer)
#### Post date: [July 14, 2020, 11:09am UTC](https://meta.discourse.org/t/restore-failed-due-to-key-plugin-name-key-discourse-data-explorer-q-1-is-duplicated/157535/3 "2020-07-14T11:09:18Z")

</div>

```plaintext
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?

---

<div class="post-metadata">

### Author: ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### Post date: [July 14, 2020, 11:10am UTC](https://meta.discourse.org/t/restore-failed-due-to-key-plugin-name-key-discourse-data-explorer-q-1-is-duplicated/157535/4 "2020-07-14T11:10:27Z")

</div>

Should be PluginStoreRow, not PluginStore. Try this:

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

```

⚠ This will irreversibly delete all data-explorer data from your site

---

<div class="post-metadata">

### Author: ![xiasummer](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/xiasummer/32/82790_2.png) [@xiasummer](https://meta.discourse.org/u/xiasummer)
#### Post date: [July 14, 2020, 11:13am UTC](https://meta.discourse.org/t/restore-failed-due-to-key-plugin-name-key-discourse-data-explorer-q-1-is-duplicated/157535/5 "2020-07-14T11:13:59Z")

</div>

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

---

<div class="post-metadata">

### Author: ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### Post date: [July 14, 2020, 11:19am UTC](https://meta.discourse.org/t/restore-failed-due-to-key-plugin-name-key-discourse-data-explorer-q-1-is-duplicated/157535/6 "2020-07-14T11:19:54Z")

</div>

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

---

<div class="post-metadata">

### Author: ![xiasummer](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/xiasummer/32/82790_2.png) [@xiasummer](https://meta.discourse.org/u/xiasummer)
#### Post date: [July 14, 2020, 11:32am UTC](https://meta.discourse.org/t/restore-failed-due-to-key-plugin-name-key-discourse-data-explorer-q-1-is-duplicated/157535/7 "2020-07-14T11:32:26Z")

</div>

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).

```plaintext

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

```

---

<div class="post-metadata">

### Author: ![xiasummer](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/xiasummer/32/82790_2.png) [@xiasummer](https://meta.discourse.org/u/xiasummer)
#### Post date: [July 19, 2020, 2:04am UTC](https://meta.discourse.org/t/restore-failed-due-to-key-plugin-name-key-discourse-data-explorer-q-1-is-duplicated/157535/8 "2020-07-19T02:04:17Z")

</div>

hi， how to run the code please?

---

<div class="post-metadata">

### Author: ![DBHacker](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dbhacker/32/173072_2.png) [@DBHacker](https://meta.discourse.org/u/DBHacker)
#### Post date: [July 19, 2020, 1:40pm UTC](https://meta.discourse.org/t/restore-failed-due-to-key-plugin-name-key-discourse-data-explorer-q-1-is-duplicated/157535/9 "2020-07-19T13:40:13Z")

</div>

@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):

```plaintext
mv /var/discourse/shared /tmp

```

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

Then, you can rebuild from scratch:

```plaintext
./launcher rebuild app

```

and then you can restore from the command line:

```plaintext
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:

```plaintext
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:

```plaintext
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.

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [December 7, 2023, 3:13pm UTC](https://meta.discourse.org/t/restore-failed-due-to-key-plugin-name-key-discourse-data-explorer-q-1-is-duplicated/157535/10 "2023-12-07T15:13:30Z")

</div>

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