nextcloud / nextcloud/backup

[Nextcloud] duplicate key value violates unique constraint "fs_storage_path_hash"

Open
#341 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
272
Forks
37
PR merge metrics
No merged PRs in 30d

Description

Hey folks,
I migrated my database from MariaDB to PSQL this weekend using this command:

Versions

Backup = 1.0.6
Nextcloud Server = Nextcloud Hub II 23.0.0

DB Migration

docker exec -u <id www user>:<gid www user> -ti <containerID> php occ db:convert-type --all-apps --password="<db-pw>" pgsql nextcloud db-postgres nextcloud

This did not report any errors etc so I assume nextcloud migrated with success.

Error Picture

However, after the migration was done I encountered strange behavior, since nextcloud often switches to maintenance back and forth (almost minutewise). I looked up and saw in Postgres stuff like that:

docker-nextcloud-db-postgres-1  | 2022-06-22 04:03:44.235 UTC [381225] DETAIL:  Key (objecttype, objectid, systemtagid)=(files, 390134, 19) already exists.
docker-nextcloud-db-postgres-1  | 2022-06-22 04:03:44.236 UTC [381225] DETAIL:  Key (objecttype, objectid, systemtagid)=(files, 390131, 153) already exists.
docker-nextcloud-db-postgres-1  | 2022-06-22 04:03:44.237 UTC [381225] DETAIL:  Key (objecttype, objectid, systemtagid)=(files, 390107, 153) already exists.
docker-nextcloud-db-postgres-1  | 2022-06-22 04:03:44.237 UTC [381225] DETAIL:  Key (objecttype, objectid, systemtagid)=(files, 390107, 37) already exists.
[...]

and this...

docker-nextcloud-db-postgres-1  | 2022-06-22 04:07:41.198 UTC [381226] ERROR:  duplicate key value violates unique constraint "fs_storage_path_hash"
docker-nextcloud-db-postgres-1  | 2022-06-22 04:07:41.198 UTC [381226] DETAIL:  Key (storage, path_hash)=(14, 2f5b76cbc822adadc9782549ce5258a7) already exists.
docker-nextcloud-db-postgres-1  | 2022-06-22 04:07:41.198 UTC [381226] STATEMENT:  INSERT INTO "oc_filecache" ("mimepart", "mimetype", "mtime", "size", "etag", "storage_mtime", "permissions", "name", "parent", "checksum", "path_hash", "path", "storage") VALUES($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13)
docker-nextcloud-db-postgres-1  | 2022-06-22 04:08:58.225 UTC [381226] ERROR:  duplicate key value violates unique constraint "fs_storage_path_hash"
docker-nextcloud-db-postgres-1  | 2022-06-22 04:08:58.225 UTC [381226] DETAIL:  Key (storage, path_hash)=(14, 213cd3df74fcae566453aff6e878f7f2) already exists.
docker-nextcloud-db-postgres-1  | 2022-06-22 04:08:58.225 UTC [381226] STATEMENT:  INSERT INTO "oc_filecache" ("mimepart", "mimetype", "mtime", "size", "etag", "storage_mtime", "permissions", "name", "parent", "checksum", "path_hash", "path", "storage") VALUES($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13)
docker-nextcloud-db-postgres-1  | 2022-06-22 04:09:19.657 UTC [381226] ERROR:  duplicate key value violates unique constraint "fs_storage_path_hash"
docker-nextcloud-db-postgres-1  | 2022-06-22 04:09:19.657 UTC [381226] DETAIL:  Key (storage, path_hash)=(14, 94ad1a9b370fcdc1b4bfdb427a89831f) already exists.
docker-nextcloud-db-postgres-1  | 2022-06-22 04:09:19.657 UTC [381226] STATEMENT:  INSERT INTO "oc_filecache" ("mimepart", "mimetype", "mtime", "size", "etag", "storage_mtime", "permissions", "name", "parent", "checksum", "path_hash", "path", "storage") VALUES($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13)
[...]

DB investigation

Running the following in Postgres gave me the clue that somethis is wrong with the backup app or at least with its database entries:

select * from oc_filecache where storage=14;

Which looks like this:
image

Reset

After Runnin the following command, the entities are still persistent within the database:

docker exec -u <id www user>:<gid www user> -ti <containerID> php occ backup:reset

I'd like to use the Backup app in the future so any help would be appreciated.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the reported php occ db:convert-type migration and php occ backup:reset entry points, then inspect the oc_filecache rows and fs_storage_path_hash violations described in the logs. Reproduce the MariaDB-to-PostgreSQL migration if possible and determine why duplicate file-cache entries remain after reset. Done means the migration and reset no longer leave recurring unique-constraint errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
php, postgresql
Domain
databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.