# Backup restoration fails

**URL:** https://meta.discourse.org/t/backup-restoration-fails/405387
**Category:** Self-hosting
**Tags:** backups
**Created:** [June 16, 2026, 8:15am UTC](https://meta.discourse.org/t/backup-restoration-fails/405387 "2026-06-16T08:15:13Z")
**Posts on this page:** 18
**Page:** 1

<div class="post-metadata">

### Author: ![Michael\_Furtenbach](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/michael_furtenbach/32/134687_2.png) [@Michael\_Furtenbach](https://meta.discourse.org/u/Michael_Furtenbach)
#### Post date: [June 16, 2026, 8:15am UTC](https://meta.discourse.org/t/backup-restoration-fails/405387/1 "2026-06-16T08:15:13Z")

</div>

I’m having the following problem. I’ve been running a Discourse forum for over 10 years, and since I haven’t been able to install updates for some time now, I wanted to set up a new server:

Old server is running: 3.4.0.beta4-dev

New server: Latest version

The backup is already 673.2 MB in size as a .gz file, excluding uploads

Unfortunately, the restoration keeps aborting. The log file contains this error

```plaintext
[2026-06-16 07:54:52] ERROR: could not create unique index “index_incoming_referers_on_path_and_incoming_domain_id”
[2026-06-16 07:54:52] DETAIL: Key (path, incoming_domain_id)=(//, 5) is duplicated.
[2026-06-16 07:54:52] EXCEPTION: psql failed: DETAIL: Key (path, incoming_domain_id)=(//, 5) is duplicated.

[2026-06-16 07:54:52] /var/www/discourse/lib/backup_restore/database_restorer.rb:93:in 'BackupRestore::DatabaseRestorer#restore_dump'
/var/www/discourse/lib/backup_restore/database_restorer.rb:26:in ‘BackupRestore::DatabaseRestorer#restore’
/var/www/discourse/lib/backup_restore/restorer.rb:61:in 'BackupRestore::Restorer#run'
/var/www/discourse/script/spawn_backup_restore.rb:20:in ‘Object#restore’
/var/www/discourse/script/spawn_backup_restore.rb:33:in ‘block in ’
/var/www/discourse/script/spawn_backup_restore.rb:4:in 'Kernel#fork'
/var/www/discourse/script/spawn_backup_restore.rb:4:in ‘’
[2026-06-16 07:54:52] Trying to rollback...

```

What can I do to fix this problem and not lose the last 10 years of data?

Thank you in advance for any help!

---

<div class="post-metadata">

### Author: ![chapoi](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/chapoi/32/537252_2.png) [@chapoi](https://meta.discourse.org/u/chapoi)
#### Post date: [June 16, 2026, 9:48am UTC](https://meta.discourse.org/t/backup-restoration-fails/405387/2 "2026-06-16T09:48:01Z")

</div>

Hello and wow, welcome back after 9 years!

Pretty cool to see such a long running forum.

I think this is the same index problem as talked about here: [Can't restore due to corrupt indexes (with some clues on how to deal with corrupt indexes)](https://meta.discourse.org/t/cant-restore-due-to-corrupt-indexes-with-some-clues-on-how-to-deal-with-corrupt-indexes/137400)

It’s something like this:

The `incoming_referers` table tracks the URL paths that referred visitors to your forum. It has a unique index, meaning no two rows can have the same path + domain combination.

Your database has two rows with `path='//'` and `incoming_domain_id=5`. When it tries to rebuild this unique index during restore, it finds the duplicate and aborts the entire restore transaction.

So you’ll need to find and cleanup that duplicate `incoming_referers` and then make a new backup to restore on the new server.

I found [this topic with instructions](https://meta.discourse.org/t/error-importing-backup-could-not-create-unique-index/207766/7) that might help you

> [@Error importing backup: "could not create unique index"](https://meta.discourse.org/t/error-importing-backup-could-not-create-unique-index/207766/7):
>
> Enter container
> 
> `./launcher enter app`
> 
> Connect to database
> 
> `su postgres -c 'psql discourse'`
> 
> Try to find duplicates
> 
> ```plaintext
> discourse=# select * from incoming_referers where path LIKE '%/search/' ORDER BY incoming_domain_id;`
> 
> id | path | incoming_domain_id
> ------+------------+--------------------
> 3339 | /search/ | 33
> 6257 | /search/ | 91
> 1567 | /search/ | 298
> 1777 | /search/ | 341
> 3010 | /search/ | 418
> 6247 | /search/ | 418
> 4293 | /search/ | 644
> 2899 | /search/ | 653
> 3447 | /search/ | 793
> 3696 | /search/ | 852
> 4395 | /a/search/ | 1050
> 6968 | /search/ | 1305
> 5634 | /search/ | 1387
> 5834 | /search/ | 1437
> 6519 | /search/ | 1637
> 7127 | /search/ | 1787
> 7280 | /search/ | 1827
> (17 rows)
> 
> ```
> 
> Delete duplicate
> 
> `DELETE FROM incoming_referers WHERE path LIKE '%/search/' AND id IN (6247);`
> 
> Then rebuild
> 
> ```plaintext
> 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
> 
> ```

---

<div class="post-metadata">

### Author: ![Michael\_Furtenbach](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/michael_furtenbach/32/134687_2.png) [@Michael\_Furtenbach](https://meta.discourse.org/u/Michael_Furtenbach)
#### Post date: [June 16, 2026, 10:05am UTC](https://meta.discourse.org/t/backup-restoration-fails/405387/3 "2026-06-16T10:05:59Z")

</div>

Thank you very much for the quick response; I’ll give that a try!

---

<div class="post-metadata">

### Author: ![Michael\_Furtenbach](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/michael_furtenbach/32/134687_2.png) [@Michael\_Furtenbach](https://meta.discourse.org/u/Michael_Furtenbach)
#### Post date: [June 16, 2026, 10:24am UTC](https://meta.discourse.org/t/backup-restoration-fails/405387/5 "2026-06-16T10:24:23Z")

</div>

Sorry to bother you, but I seem to be doing something wrong—after running the command “discourse=# select \* from incoming\_referers where path LIKE ‘%/search/’ ORDER BY incoming\_domain\_id;”, I’m getting a syntax error.

---

<div class="post-metadata">

### Author: ![chapoi](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/chapoi/32/537252_2.png) [@chapoi](https://meta.discourse.org/u/chapoi)
#### Post date: [June 16, 2026, 10:31am UTC](https://meta.discourse.org/t/backup-restoration-fails/405387/6 "2026-06-16T10:31:13Z")

</div>

Did you type “discourse=#”? If so, try again without that

---

<div class="post-metadata">

### Author: ![Michael\_Furtenbach](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/michael_furtenbach/32/134687_2.png) [@Michael\_Furtenbach](https://meta.discourse.org/u/Michael_Furtenbach)
#### Post date: [June 16, 2026, 10:36am UTC](https://meta.discourse.org/t/backup-restoration-fails/405387/7 "2026-06-16T10:36:02Z")

</div>

Then I get the error message “bash: syntax error near unexpected token `from’”

For reference, I’m currently at: root@community-app:/var/www/discourse#

---

<div class="post-metadata">

### Author: ![chapoi](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/chapoi/32/537252_2.png) [@chapoi](https://meta.discourse.org/u/chapoi)
#### Post date: [June 16, 2026, 10:45am UTC](https://meta.discourse.org/t/backup-restoration-fails/405387/8 "2026-06-16T10:45:21Z")

</div>

> [@Michael\_Furtenbach](#):
>
> Then I get the error message “bash: syntax error near unexpected token `from’”
> 
> For reference, I’m currently at: root@community-app:/var/www/discourse#

Ah , you’re not in the DB yet.

First run `psql -U discourse discourse` (I think)

And then the prompt should change to `discourse=#`

---

<div class="post-metadata">

### Author: ![Michael\_Furtenbach](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/michael_furtenbach/32/134687_2.png) [@Michael\_Furtenbach](https://meta.discourse.org/u/Michael_Furtenbach)
#### Post date: [June 16, 2026, 10:56am UTC](https://meta.discourse.org/t/backup-restoration-fails/405387/9 "2026-06-16T10:56:20Z")

</div>

Okay, I’ve now also installed “apt install postgresql-client-common.” However, I’m still getting the error “Error: You must install at least one postgresql-client- package.”

---

<div class="post-metadata">

### Author: ![chapoi](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/chapoi/32/537252_2.png) [@chapoi](https://meta.discourse.org/u/chapoi)
#### Post date: [June 16, 2026, 11:05am UTC](https://meta.discourse.org/t/backup-restoration-fails/405387/10 "2026-06-16T11:05:57Z")

</div>

Okay that I don’t know.

Maybe try directly via the rails console then: `rails c`

with

```plaintext
ActiveRecord::Base.connection.execute(<<~SQL)
  SELECT id, path, incoming_domain_id 
  FROM incoming_referers 
  WHERE path = '//' 
  AND incoming_domain_id = 5
SQL

```

That may give you the same without going through the database.

Does that work?

---

<div class="post-metadata">

### Author: ![Michael\_Furtenbach](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/michael_furtenbach/32/134687_2.png) [@Michael\_Furtenbach](https://meta.discourse.org/u/Michael_Furtenbach)
#### Post date: [June 16, 2026, 11:19am UTC](https://meta.discourse.org/t/backup-restoration-fails/405387/11 "2026-06-16T11:19:59Z")

</div>

I’m really, really sorry for acting so stupid.

I’ve now installed Rails, and it seems to have worked. I also ran it with “rails c”. That seems to work too, but when I enter the command, it looks like this:

“root@community:/var/discourse# ActiveRecord::Base.connection.execute(\<\<~SQL)  
-bash: syntax error near unexpected token `\<\<’  
root@community:/var/discourse# SELECT id, path, incoming\_domain\_id  
SELECT: command not found  
root@community:/var/discourse# FROM incoming\_referers  
FROM: command not found  
root@community:/var/discourse# WHERE path = ‘//’  
WHERE: command not found  
root@community:/var/discourse# AND incoming\_domain\_id = 5  
AND: command not found  
root@community:/var/discourse# SQL”

---

<div class="post-metadata">

### Author: ![chapoi](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/chapoi/32/537252_2.png) [@chapoi](https://meta.discourse.org/u/chapoi)
#### Post date: [June 16, 2026, 11:26am UTC](https://meta.discourse.org/t/backup-restoration-fails/405387/12 "2026-06-16T11:26:14Z")

</div>

Don’t worry, maybe my instructions are just not that good 🙂

I will say I’m confused when you say you just installed Rails and can’t access your DB. Maybe it’s all different because it’s an older version, but I think I’m out of my depth now too.

Anyway, once you’re in rails, the prompt should be something different, so from your output, it looks like you aren’t in the rails console yet.

I don’t even think you’re in the actual container. Have you done `./launcher enter app`?

---

<div class="post-metadata">

### Author: ![Michael\_Furtenbach](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/michael_furtenbach/32/134687_2.png) [@Michael\_Furtenbach](https://meta.discourse.org/u/Michael_Furtenbach)
#### Post date: [June 16, 2026, 11:56am UTC](https://meta.discourse.org/t/backup-restoration-fails/405387/13 "2026-06-16T11:56:46Z")

</div>

OK, yeah, that was the problem. The query ran successfully now, and I got this response:

#\<PG::Result:0x00007fbde9732ef0 status=PGRES\_TUPLES\_OK ntuples=1 nfields=3 cmd\_tuples=1\>

---

<div class="post-metadata">

### Author: ![chapoi](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/chapoi/32/537252_2.png) [@chapoi](https://meta.discourse.org/u/chapoi)
#### Post date: [June 16, 2026, 12:02pm UTC](https://meta.discourse.org/t/backup-restoration-fails/405387/14 "2026-06-16T12:02:28Z")

</div>

So, `ntuples=1` means only one row was found, while according to the error log there should be a duplicate… 🤷‍♀️

Sorry, I don’t know what to try next. I’d recommend browsing around on the forum, there seem to be a lot of similar cases (see below this topic in the related section), maybe you’ll find the next clue there.

(Or wait untill a more knowledgeable person breezes by ;))

---

<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: [June 16, 2026, 12:13pm UTC](https://meta.discourse.org/t/backup-restoration-fails/405387/15 "2026-06-16T12:13:29Z")

</div>

It sounds like your old server isn’t a [standard install](https://meta.discourse.org/t/142537?silent=true). Anyway,… what happened in short: an index on your old server got broken over the years (this can happen after OS upgrades), so two identical rows slipped into the `incoming_referers` table. The backup copies them as-is, and the new server then refuses them. So we fix it on the **old** server first, then make a new backup.

**On the OLD server** , open the Rails console:

```plaintext
./launcher enter app
rails c

```

Then paste these lines, one after the other:

```ruby
db = ActiveRecord::Base.connection.current_database
DB.exec("DELETE FROM incoming_referers a USING incoming_referers b WHERE a.id > b.id AND a.path = b.path AND a.incoming_domain_id = b.incoming_domain_id")
DB.exec("REINDEX DATABASE #{ActiveRecord::Base.connection.quote_table_name(db)}")

```

This removes the duplicate and rebuilds all indexes (in case other tables are affected too).

If `REINDEX` finishes without an error, type `exit`, make a **fresh backup on the old server** , and restore that new file. If it shows an error about another table, just paste it here.

---

<div class="post-metadata">

### Author: ![Michael\_Furtenbach](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/michael_furtenbach/32/134687_2.png) [@Michael\_Furtenbach](https://meta.discourse.org/u/Michael_Furtenbach)
#### Post date: [June 16, 2026, 12:28pm UTC](https://meta.discourse.org/t/backup-restoration-fails/405387/20 "2026-06-16T12:28:45Z")

</div>

Thank you very much. Unfortunately, I’m getting an error message on the last line:

“PG::InsufficientPrivilege: ERROR: must be owner of database discourse”

It should actually already be a “standard server.” The installation was performed by the “Discourse” team at the time for a one-time fee.

---

<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: [June 16, 2026, 12:31pm UTC](https://meta.discourse.org/t/backup-restoration-fails/405387/21 "2026-06-16T12:31:53Z")

</div>

Ah, right. Let’s try this.

Leave the Rails console (type `exit`), and while still inside the container (`./launcher enter app`), run:

```plaintext
su postgres -c "reindexdb discourse"

```

When that finishes without an error, make a **fresh backup on the old server** and restore that new file. If it shows an error about a specific table, just paste it here.

---

<div class="post-metadata">

### Author: ![Michael\_Furtenbach](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/michael_furtenbach/32/134687_2.png) [@Michael\_Furtenbach](https://meta.discourse.org/u/Michael_Furtenbach)
#### Post date: [June 16, 2026, 7:25pm UTC](https://meta.discourse.org/t/backup-restoration-fails/405387/22 "2026-06-16T19:25:47Z")

</div>

Thank you so, so much! Everything worked out wonderfully, and without your help, I wouldn’t have stood a chance and would surely have had to painfully start the forum over from scratch soon! THANK YOU!

Thanks also to @chapoi for the great support!

---

<div class="post-metadata">

### Author: ![Andrew\_Rowe](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/andrew_rowe/32/445877_2.png) [@Andrew\_Rowe](https://meta.discourse.org/u/Andrew_Rowe)
#### Post date: [June 17, 2026, 1:42pm UTC](https://meta.discourse.org/t/backup-restoration-fails/405387/23 "2026-06-17T13:42:21Z")

</div>


