Management won't start due to existing index #2155

Open
opened 2025-11-20 07:04:51 -05:00 by saavagebueno · 3 comments
Owner

Originally created by @rqi14 on GitHub (Aug 6, 2025).

Describe the problem

Hi. I pulled the latest docker images and ran into problems starting the compose project.
I feel the problem is similar to #4148 except for that I'm using sqlite by default.

To Reproduce

Steps to reproduce the behavior:

  1. pull the latest image
  2. do docker compose up -d

Expected behavior

It should start

Are you using NetBird Cloud?

Self-host

NetBird version

netbird version 0.5.3, I believe. I use the latest label

Is any other VPN software installed?

No

Debug output

management-1  | 2025-08-06T16:50:46Z INFO [context: SYSTEM] management/server/telemetry/app_metrics.go:193: enabled application metrics and exposing on http://0.0.0.0:9090
management-1  | 2025-08-06T16:50:46Z INFO [context: SYSTEM] management/server/store/store.go:268: using SQLite store engine
management-1  | 2025-08-06T16:50:46Z INFO [context: SYSTEM] management/server/store/sql_store.go:88: Set max open db connections to 1
management-1  | 2025-08-06T16:50:46Z INFO [context: SYSTEM] management/server/migration/migration.go:262: No plain setup keys found in table setup_keys, no migration needed
management-1  | 2025-08-06T16:50:46Z INFO management/server/migration/migration.go:300: Migration of plain setup key to hashed setup key completed
management-1  | 2025-08-06T16:50:46Z INFO [context: SYSTEM] management/server/migration/migration.go:343: No rows with empty enabled found in table network_resources, no migration needed
management-1  | 2025-08-06T16:50:46Z INFO [context: SYSTEM] management/server/migration/migration.go:357: Migration of empty enabled to default value in table network_resources completed
management-1  | 2025-08-06T16:50:46Z INFO [context: SYSTEM] management/server/migration/migration.go:343: No rows with empty enabled found in table network_routers, no migration needed
management-1  | 2025-08-06T16:50:46Z INFO [context: SYSTEM] management/server/migration/migration.go:357: Migration of empty enabled to default value in table network_routers completed
management-1  | 2025-08-06T16:50:46Z INFO [context: SYSTEM] management/server/migration/migration.go:398: index idx_account_ip already exists on table peers
management-1  | 2025-08-06T16:50:46Z INFO [context: SYSTEM] management/server/migration/migration.go:398: index idx_account_dnslabel already exists on table peers
management-1  | Error: failed creating Store: /var/lib/netbird/: migratePostAuto: failed to insert id csra8s6i3ucc73b4igmg: UNIQUE constraint failed: group_peers.group_id, group_peers.peer_id
management-1 exited with code 1

Additional context

Add any other context about the problem here.

Have you tried these troubleshooting steps?

  • Reviewed client troubleshooting (if applicable)
  • Checked for newer NetBird versions
  • Searched for similar issues on GitHub (including closed ones)
  • Restarted the NetBird client
  • Disabled other VPN software
  • Checked firewall settings
Originally created by @rqi14 on GitHub (Aug 6, 2025). **Describe the problem** Hi. I pulled the latest docker images and ran into problems starting the compose project. I feel the problem is similar to #4148 except for that I'm using sqlite by default. **To Reproduce** Steps to reproduce the behavior: 1. pull the latest image 2. do `docker compose up -d` **Expected behavior** It should start **Are you using NetBird Cloud?** Self-host **NetBird version** `netbird version` 0.5.3, I believe. I use the `latest` label **Is any other VPN software installed?** No **Debug output** ``` management-1 | 2025-08-06T16:50:46Z INFO [context: SYSTEM] management/server/telemetry/app_metrics.go:193: enabled application metrics and exposing on http://0.0.0.0:9090 management-1 | 2025-08-06T16:50:46Z INFO [context: SYSTEM] management/server/store/store.go:268: using SQLite store engine management-1 | 2025-08-06T16:50:46Z INFO [context: SYSTEM] management/server/store/sql_store.go:88: Set max open db connections to 1 management-1 | 2025-08-06T16:50:46Z INFO [context: SYSTEM] management/server/migration/migration.go:262: No plain setup keys found in table setup_keys, no migration needed management-1 | 2025-08-06T16:50:46Z INFO management/server/migration/migration.go:300: Migration of plain setup key to hashed setup key completed management-1 | 2025-08-06T16:50:46Z INFO [context: SYSTEM] management/server/migration/migration.go:343: No rows with empty enabled found in table network_resources, no migration needed management-1 | 2025-08-06T16:50:46Z INFO [context: SYSTEM] management/server/migration/migration.go:357: Migration of empty enabled to default value in table network_resources completed management-1 | 2025-08-06T16:50:46Z INFO [context: SYSTEM] management/server/migration/migration.go:343: No rows with empty enabled found in table network_routers, no migration needed management-1 | 2025-08-06T16:50:46Z INFO [context: SYSTEM] management/server/migration/migration.go:357: Migration of empty enabled to default value in table network_routers completed management-1 | 2025-08-06T16:50:46Z INFO [context: SYSTEM] management/server/migration/migration.go:398: index idx_account_ip already exists on table peers management-1 | 2025-08-06T16:50:46Z INFO [context: SYSTEM] management/server/migration/migration.go:398: index idx_account_dnslabel already exists on table peers management-1 | Error: failed creating Store: /var/lib/netbird/: migratePostAuto: failed to insert id csra8s6i3ucc73b4igmg: UNIQUE constraint failed: group_peers.group_id, group_peers.peer_id management-1 exited with code 1 ``` **Additional context** Add any other context about the problem here. **Have you tried these troubleshooting steps?** - [x] Reviewed [client troubleshooting](https://docs.netbird.io/how-to/troubleshooting-client) (if applicable) - [x] Checked for newer NetBird versions - [x]Searched for similar issues on GitHub (including closed ones) - [ ] Restarted the NetBird client - [ ] Disabled other VPN software - [x] Checked firewall settings
saavagebueno added the triage-needed label 2025-11-20 07:04:51 -05:00
Author
Owner

@mrpk1906 commented on GitHub (Aug 7, 2025):

@rqi14

The problem is caused by a duplicate value in the peers column of the groups table in the store.db database.

Workaround

  1. Open the store.db file using a SQLite browser, such as DB Browser for SQLite.
  2. Run the following SQL query to locate the problematic row:
SELECT * FROM  "groups" WHERE id="csra8s6i3ucc73b4igmg";
  1. Identify and remove the duplicate value in the peers column.
  2. Save the changes and copy the updated store.db file back into the mount volume.
  3. Restart the service.

Fix

I think we need to check and remove the duplication in the column peers first.

@pascal-fischer Can you take a look?
https://github.com/netbirdio/netbird/blob/main/management/server/store/store.go#L362

@mrpk1906 commented on GitHub (Aug 7, 2025): @rqi14 The problem is caused by a duplicate value in the `peers` column of the `groups` table in the `store.db` database. ### Workaround 1. Open the `store.db` file using a SQLite browser, such as [DB Browser for SQLite](https://sqlitebrowser.org/). 2. Run the following SQL query to locate the problematic row: ```sql SELECT * FROM "groups" WHERE id="csra8s6i3ucc73b4igmg"; ``` 3. Identify and remove the duplicate value in the `peers` column. 4. Save the changes and copy the updated `store.db` file back into the mount volume. 5. Restart the service. ### Fix I think we need to check and remove the duplication in the column `peers` first. @pascal-fischer Can you take a look? https://github.com/netbirdio/netbird/blob/main/management/server/store/store.go#L362
Author
Owner

@rqi14 commented on GitHub (Aug 7, 2025):

@rqi14

The problem is caused by a duplicate value in the peers column of the groups table in the store.db database.

Workaround

1. Open the `store.db` file using a SQLite browser, such as [DB Browser for SQLite](https://sqlitebrowser.org/).

2. Run the following SQL query to locate the problematic row:

SELECT * FROM "groups" WHERE id="csra8s6i3ucc73b4igmg";

3. Identify and remove the duplicate value in the `peers` column.

4. Save the changes and copy the updated `store.db` file back into the mount volume.

5. Restart the service.

Fix

I think we need to check and remove the duplication in the column peers first.

@pascal-fischer Can you take a look? https://github.com/netbirdio/netbird/blob/main/management/server/store/store.go#L362

Hi. I downgraded to 0.51.2 and it works fine. I feel it is the latest version of code that causes problems. I checked and there does not seem to be duplicated value. The code is trying to add values identical to the existing and that causes the error.

@rqi14 commented on GitHub (Aug 7, 2025): > [@rqi14](https://github.com/rqi14) > > The problem is caused by a duplicate value in the `peers` column of the `groups` table in the `store.db` database. > ### Workaround > > 1. Open the `store.db` file using a SQLite browser, such as [DB Browser for SQLite](https://sqlitebrowser.org/). > > 2. Run the following SQL query to locate the problematic row: > > > SELECT * FROM "groups" WHERE id="csra8s6i3ucc73b4igmg"; > > 3. Identify and remove the duplicate value in the `peers` column. > > 4. Save the changes and copy the updated `store.db` file back into the mount volume. > > 5. Restart the service. > > > ### Fix > > I think we need to check and remove the duplication in the column `peers` first. > > [@pascal-fischer](https://github.com/pascal-fischer) Can you take a look? https://github.com/netbirdio/netbird/blob/main/management/server/store/store.go#L362 Hi. I downgraded to 0.51.2 and it works fine. I feel it is the latest version of code that causes problems. I checked and there does not seem to be duplicated value. The code is trying to add values identical to the existing and that causes the error.
Author
Owner

@pascal-fischer commented on GitHub (Aug 7, 2025):

Hi @rqi14 @mrpk1906,
you are right, the migration does not handle duplicates on the group peers source.
Removing the duplicates from the JSON string will work. I created a PR to ignore duplicated values during the migration.

Sorry for that! The next release should include the fix.

@pascal-fischer commented on GitHub (Aug 7, 2025): Hi @rqi14 @mrpk1906, you are right, the migration does not handle duplicates on the group peers source. Removing the duplicates from the JSON string will work. I created a PR to ignore duplicated values during the migration. Sorry for that! The next release should include the fix.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: SVI/netbird#2155