# Failed to restore DB

**URL:** https://meta.discourse.org/t/failed-to-restore-db/131137
**Category:** Self-hosting
**Created:** [October 16, 2019, 6:38am UTC](https://meta.discourse.org/t/failed-to-restore-db/131137 "2019-10-16T06:38:28Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![Rasin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rasin/32/130523_2.png) [@Rasin](https://meta.discourse.org/u/Rasin)
#### Post date: [October 16, 2019, 6:38am UTC](https://meta.discourse.org/t/failed-to-restore-db/131137/1 "2019-10-16T06:38:28Z")

</div>

I was trying to restore my backup to a new server, and it showed some errors.

The log is here: [Ubuntu Pastebin](https://paste.ubuntu.com/p/RDRbX9NRg5/)

The error maybe:

```plaintext
PG::UniqueViolation: ERROR: could not create unique index "unique_index_categories_on_slug"
DETAIL: Key (COALESCE(parent_category_id, '-1'::integer), slug)=(5, ) is duplicated.

```

I though it could be a DB problem, but I didn’t edit it. Just download the backup tar but restored wrongly.

Please help!

---

<div class="post-metadata">

### Author: ![ariznaf](https://avatars.discourse-cdn.com/v4/letter/a/ecccb3/32.png) [@ariznaf](https://meta.discourse.org/u/ariznaf)
#### Post date: [October 16, 2019, 7:02am UTC](https://meta.discourse.org/t/failed-to-restore-db/131137/2 "2019-10-16T07:02:46Z")

</div>

There is another thread with similar problem.

It is a strange problem.

Many of us have solved it just by keep trying.

Try it several times and may one of them you don’t have the error.

May be your problem is different but it resembles the database errors we had while restoring.

It seems there is a bug in restoring scripts or spme kind of bug with the postgres database system used.

---

<div class="post-metadata">

### Author: ![Rasin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rasin/32/130523_2.png) [@Rasin](https://meta.discourse.org/u/Rasin)
#### Post date: [October 16, 2019, 7:12am UTC](https://meta.discourse.org/t/failed-to-restore-db/131137/3 "2019-10-16T07:12:49Z")

</div>

How strange is this solution…FML  
Will it be able to edit the sql file to make it normal?

I mean, if I there any way to ignore the duplicated key?

---

<div class="post-metadata">

### Author: ![Rasin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rasin/32/130523_2.png) [@Rasin](https://meta.discourse.org/u/Rasin)
#### Post date: [October 16, 2019, 7:57am UTC](https://meta.discourse.org/t/failed-to-restore-db/131137/4 "2019-10-16T07:57:06Z")

</div>

And after I rebuild to a previous version or a beta version, the log has turned into:

```plaintext
EXCEPTION: Compression::Strategy::ExtractFailed[2019-10-16 07:53:52] /var/www/discourse/lib/compression/strategy.rb:89:in `block in extract_file'
/var/www/discourse/lib/compression/strategy.rb:85:in `open'
/var/www/discourse/lib/compression/strategy.rb:85:in `extract_file'
/var/www/discourse/lib/compression/strategy.rb:26:in `block (2 levels) in decompress'
/usr/local/lib/ruby/site_ruby/2.6.0/rubygems/package/tar_reader.rb:65:in `each'
/var/www/discourse/lib/compression/strategy.rb:18:in `block in decompress'
/var/www/discourse/lib/compression/tar.rb:26:in `get_compressed_file_stream'
/var/www/discourse/lib/compression/strategy.rb:15:in `decompress'
/var/www/discourse/lib/compression/pipeline.rb:26:in `block in decompress'
/var/www/discourse/lib/compression/pipeline.rb:24:in `each'
/var/www/discourse/lib/compression/pipeline.rb:24:in `reduce'
/var/www/discourse/lib/compression/pipeline.rb:24:in `decompress'
/var/www/discourse/lib/backup_restore/restorer.rb:141:in `decompress_archive'
/var/www/discourse/lib/backup_restore/restorer.rb:60:in `run'
/var/www/discourse/lib/backup_restore.rb:166:in `block in start!'
/var/www/discourse/lib/backup_restore.rb:163:in `fork'
/var/www/discourse/lib/backup_restore.rb:163:in `start!'
/var/www/discourse/lib/backup_restore.rb:22:in `restore!'
/var/www/discourse/app/controllers/admin/backups_controller.rb:119:in `restore'

```

Why is that a problem? I didn’t change anything on the tar file.

---

<div class="post-metadata">

### Author: ![Roman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/roman/32/157504_2.png) [@Roman](https://meta.discourse.org/u/Roman)
#### Post date: [October 16, 2019, 12:19pm UTC](https://meta.discourse.org/t/failed-to-restore-db/131137/5 "2019-10-16T12:19:26Z")

</div>

Take a look at:

> [@Error Restoring Backup on Migration](https://meta.discourse.org/t/error-restoring-backup-on-migration/128849/35):
>
> @pfaffman Please increase the decompressed\_file\_max\_size\_mb site setting (it’s hidden). The default is currently set at 1GB. I have a PR ready to bump the default to 100GB but it wasn’t merged yet: [https://github.com/discourse/discourse/pull/8179](https://github.com/discourse/discourse/pull/8179)

---

<div class="post-metadata">

### Author: ![Rasin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rasin/32/130523_2.png) [@Rasin](https://meta.discourse.org/u/Rasin)
#### Post date: [October 16, 2019, 12:46pm UTC](https://meta.discourse.org/t/failed-to-restore-db/131137/6 "2019-10-16T12:46:28Z")

</div>

Thank you very much on this extracting thing!

Could you please help me with the duplicated key error? Or is there a way I can fix this sql on `psql`?

---

<div class="post-metadata">

### Author: ![gerhard](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gerhard/32/119479_2.png) [@gerhard](https://meta.discourse.org/u/gerhard)
#### Post date: [October 16, 2019, 1:39pm UTC](https://meta.discourse.org/t/failed-to-restore-db/131137/7 "2019-10-16T13:39:25Z")

</div>

> [@Rasin](#):
>
> The error maybe:
> 
> ```plaintext
> PG::UniqueViolation: ERROR: could not create unique index "unique_index_categories_on_slug"
> DETAIL: Key (COALESCE(parent_category_id, '-1'::integer), slug)=(5, ) is duplicated.
> 
> ```

@daniel I think the migration in [FIX: Add unique index to prevent duplicate slugs for categories · discourse/discourse@c71da3f · GitHub](https://github.com/discourse/discourse/commit/c71da3f3352159f02276c9a49f1ed8c54c75010d) needs to make sure the column values are unique before creating the unique index.

---

<div class="post-metadata">

### Author: ![daniel](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/daniel/32/172786_2.png) [@daniel](https://meta.discourse.org/u/daniel)
#### Post date: [October 16, 2019, 2:36pm UTC](https://meta.discourse.org/t/failed-to-restore-db/131137/8 "2019-10-16T14:36:42Z")

</div>

@Rasin, This should now be fixed as of:

[https://github.com/discourse/discourse/commit/7ba914f1e10d90b1e4d25b0ab2427c94df456eae](https://github.com/discourse/discourse/commit/7ba914f1e10d90b1e4d25b0ab2427c94df456eae)

Thank you for bringing this to our attention and I’m sorry for any inconvenience. Let us know if you have any other problems.

---

<div class="post-metadata">

### Author: ![ariznaf](https://avatars.discourse-cdn.com/v4/letter/a/ecccb3/32.png) [@ariznaf](https://meta.discourse.org/u/ariznaf)
#### Post date: [October 16, 2019, 9:52pm UTC](https://meta.discourse.org/t/failed-to-restore-db/131137/9 "2019-10-16T21:52:34Z")

</div>

Yes, I have told you: it is an odd thing.

But it worked for several of us as you can read here:

> [@Error Restoring Backup on Migration](https://meta.discourse.org/t/error-restoring-backup-on-migration/128849/5):
>
> Wow, trying to reproduce it so I can be sure that things will go as planned on migration, and I have the error again? I’m going to continue to try and find the steps to reproduce a fix. Because I can’t reproduce it now.

I don’t know if your situation is the same, as the error is similar but not exactly the same.

@usulrasolas has comented that he edited the script with sql sentences to correct it.

But me (and others) have not change anything just tried multiple tries.

It is odd, I know, but may be there are timing or time expiration issues involved.  
We don’t know.  
Developers are looking at it.

---

<div class="post-metadata">

### Author: ![Rasin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rasin/32/130523_2.png) [@Rasin](https://meta.discourse.org/u/Rasin)
#### Post date: [October 17, 2019, 1:22am UTC](https://meta.discourse.org/t/failed-to-restore-db/131137/10 "2019-10-17T01:22:45Z")

</div>

Thank you for all your suggestions! Looking forward to new updates.

---

<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: [November 16, 2019, 1:33am UTC](https://meta.discourse.org/t/failed-to-restore-db/131137/11 "2019-11-16T01:33:11Z")

</div>

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