# \[Site Down :(\] Upgrade\\Rebuild Failure - DB Migration Issue?

**URL:** <https://meta.discourse.org/t/site-down-upgrade-rebuild-failure-db-migration-issue/268359>\
**Category:** Self-hosting\
**Created:** [June 14, 2023, 8:49pm UTC](https://meta.discourse.org/t/site-down-upgrade-rebuild-failure-db-migration-issue/268359 "2023-06-14T20:49:04Z")\
**Posts on this page:** 10\
**Page:** 1

## AI-generated summary

The user [SouperC](/t/-/268359/1) encountered a rebuild failure during a Discourse upgrade, with errors indicating duplicate usernames (`racerx`). [JammyDodger](/t/-/268359/2) pointed to similar issues and referenced past discussions about `username_lower` conflicts. [SouperC](/t/-/268359/6) confirmed the issue was with two users named `racerx` and sought guidance on resolving it. [pfaffman](/t/-/268359/5) clarified that commands must be run inside the container. [Canapin](/t/-/268359/7) and [Simon_Manning](/t/-/268359/8) provided SQL steps to fix the duplicates by identifying the conflicting user IDs and updating one username to a unique value, such as `racerx2`. [SouperC](/t/-/268359/9) confirmed the fix worked, though they used a slightly different approach to update the `username_lower` column, successfully completing the rebuild.

<div class="post-metadata">

**Author:** ![SouperC](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/souperc/32/62875_2.png) [@SouperC](https://meta.discourse.org/u/SouperC)\
**Post date:** [June 14, 2023, 8:49pm UTC](https://meta.discourse.org/t/site-down-upgrade-rebuild-failure-db-migration-issue/268359/1 "2023-06-14T20:49:04Z")

</div>

Upgrading to current version of Discourse today, the rebuild is failing and I’m not exactly sure what’s causing it. The install was quite a few iterations behind (I think 2.8x). The docker image update went fine when I went to upgrade Discourse I was asked to do a manual pull & rebuild (Most of the time I get asked this) however the rebuild has been unsuccessful.

Here’s the results of a search for “error” using discourse-doctor. Apologies for screenshots, the web based VNC client I have does not seem to support copy/paste

 ![image](https://global.discourse-cdn.com/meta/original/4X/4/4/6/446be5590c64428ba73bdb43071066e9d80c6302.png)

 ![image](https://global.discourse-cdn.com/meta/original/4X/5/c/8/5c8b3392cc962608efb82ea9151f64c7dcae32bf.png)

![image](https://global.discourse-cdn.com/meta/original/4X/e/5/a/e5ae0b334a216da43234813d504f397f846d6c73.png)

 ![image](https://global.discourse-cdn.com/meta/original/4X/7/7/1/77142b8c968470a3214f4a7e6546542faa2fb48b.png)

---

<div class="post-metadata">

**Author:** ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)\
**Post date:** [June 14, 2023, 8:57pm UTC](https://meta.discourse.org/t/site-down-upgrade-rebuild-failure-db-migration-issue/268359/2 "2023-06-14T20:57:40Z")

</div>

It seems to think you have two users called `racerx`. I think there’s a topic about a similar issue here:

> [@Import failing with \`could not create unique index\`](https://meta.discourse.org/t/import-failing-with-could-not-create-unique-index/154693/6):
>
> We also had 8 users which had a duplicate `username_lower` (too many mike’s and marco’s). We renamed those by updating both `username` and `username_lower`. From the user data we noticed that the first corruption has happened in December 2019.

Also a more recent one here too:

> [@PG::UniqueViolation Problem during 3.1.0.beta4 upgrade](https://meta.discourse.org/t/pg-uniqueviolation-problem-during-3-1-0-beta4-upgrade/262163/3):
>
> Thanks for your reply. Yes, I am able to start / enter the app, I am also doing as you suggested. discourse=# REINDEX TABLE users; ERROR: could not create unique index "index\_users\_on\_username\_lower" DETAIL: Key (username\_lower)=(mostafa11) is duplicated. The problem is duplicates keep coming, I have a lot of user over 300K. Is there any way to check how many duplicates or list all of them? For fixing, I was updating the username\_lower like this: I was appending some number at the end. U…

---

<div class="post-metadata">

**Author:** ![SouperC](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/souperc/32/62875_2.png) [@SouperC](https://meta.discourse.org/u/SouperC)\
**Post date:** [June 14, 2023, 9:07pm UTC](https://meta.discourse.org/t/site-down-upgrade-rebuild-failure-db-migration-issue/268359/3 "2023-06-14T21:07:08Z")

</div>

Thanks I will start down that path… wish me luck..

---

<div class="post-metadata">

**Author:** ![SouperC](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/souperc/32/62875_2.png) [@SouperC](https://meta.discourse.org/u/SouperC)\
**Post date:** [June 14, 2023, 9:37pm UTC](https://meta.discourse.org/t/site-down-upgrade-rebuild-failure-db-migration-issue/268359/4 "2023-06-14T21:37:48Z")

</div>

I’m stuck on how to kickoff the re indexing. I’ve been able to start (Although it’s not web accessible) and enter the app but no luck moving forward from that.

![image](https://global.discourse-cdn.com/meta/original/4X/c/9/0/c90ada25cb59fc1a099727fc7069c8a28c08e48e.png)

---

<div class="post-metadata">

**Author:** ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)\
**Post date:** [June 15, 2023, 12:46am UTC](https://meta.discourse.org/t/site-down-upgrade-rebuild-failure-db-migration-issue/268359/5 "2023-06-15T00:46:22Z")

</div>

You need to run those commands inside the container. Something like

```plaintext
./launcher start app
./launcher enter app

```

Before you `sudo postgres`

Edit: oh, you got in the container.

That `postgres -c` needs `sudo ` before it.

---

<div class="post-metadata">

**Author:** ![SouperC](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/souperc/32/62875_2.png) [@SouperC](https://meta.discourse.org/u/SouperC)\
**Post date:** [June 15, 2023, 1:33am UTC](https://meta.discourse.org/t/site-down-upgrade-rebuild-failure-db-migration-issue/268359/6 "2023-06-15T01:33:43Z")

</div>

I guess sudo wouldn’t work, but su did and now I’m poking around in postgres.

So now I need to figure out how to actually fix the duplicates. The query appears to be..

`UPDATE users SET username_lower = 'xxx' WHERE id = xxx;`

I tried a couple of variations to no avail. As you can tell I’m not 100% sure what the correct syntax here as the error is column related.

 ![image](https://global.discourse-cdn.com/meta/original/4X/a/7/2/a72e08999af09bc2ba6f0e763e8312bcf65aa11f.png)

I’ll keep digging. I don’t know how many dups I have yet either…

/edit… it’s just racerx. DAMMIT RACERX!

![image](https://global.discourse-cdn.com/meta/original/4X/5/4/e/54ede9f50cdabc5ffaa055a95e7d49a96e7d5149.png)

---

<div class="post-metadata">

**Author:** ![Canapin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/canapin/32/119591_2.png) [@Canapin](https://meta.discourse.org/u/Canapin)\
**Post date:** [June 15, 2023, 9:22am UTC](https://meta.discourse.org/t/site-down-upgrade-rebuild-failure-db-migration-issue/268359/7 "2023-06-15T09:22:19Z")

</div>

Did you figure out how to fix it?

I’d return the users’ ID (which is unique) as well to identify them properly and then rename one of these two users 🙂

---

<div class="post-metadata">

**Author:** ![Simon\_Manning](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon_manning/32/198596_2.png) [@Simon\_Manning](https://meta.discourse.org/u/Simon_Manning)\
**Post date:** [June 15, 2023, 10:23am UTC](https://meta.discourse.org/t/site-down-upgrade-rebuild-failure-db-migration-issue/268359/8 "2023-06-15T10:23:07Z")

</div>

Expanding on what @Canapin has said, in case you haven’t already figured it out, it should be straightforward to get the usernames unique since you’ve already established that `racerx` is the only duplicated username.

First, if you haven’t already, make sure `racerx2` doesn’t already exist so you aren’t just moving the problem to a different username: (If you get an id, try a different username.)

```sql
SELECT id FROM users WHERE username_lower = 'racerx2';

```

Once you have an unused username, get the IDs of the duplicate `racerx` accounts:

```sql
SELECT id from users WHERE username_lower = 'racerx';

```

Pick one, doesn’t matter which though I would use the highest, then change its username: (Substituting `racerx2` for a different username if needed and `12345` with the `racerx` ID you picked.)

```sql
UPDATE users SET username_lower = 'racerx2' WHERE id = 12345;

```

---

<div class="post-metadata">

**Author:** ![SouperC](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/souperc/32/62875_2.png) [@SouperC](https://meta.discourse.org/u/SouperC)\
**Post date:** [June 19, 2023, 12:57pm UTC](https://meta.discourse.org/t/site-down-upgrade-rebuild-failure-db-migration-issue/268359/9 "2023-06-19T12:57:51Z")

</div>

Update (Was in drafts for a few days, sorry) Looks like I got it figured out. Not sure if it what I did was the right approach, but it rebuilt successfully.

Found it hard to modify\append the racerx value in the username\_lower column using the syntax so I went about it another way. by looking up the IDs for the rows and modifiying the username\_lower value in a specific row.

First I tried to get a report of any rows in the users table that had “racerx” in the username\_lower column.

`select all from users where username_lower ='racerx';`

From this I decided I’d modify racerx to racerx2, I can’t remember exactly what I typed to make that happen. I _think_ it was UPDATE SET from users username\_lower racerx to racerx2

---

<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:** [July 19, 2023, 12:58pm UTC](https://meta.discourse.org/t/site-down-upgrade-rebuild-failure-db-migration-issue/268359/10 "2023-07-19T12:58:49Z")

</div>

Closed on July 19, 2023, 12:58pm UTC

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