Postgresql: duplicate key value violates unique constraint "oc_filecache_extended_pkey"

Which general topic do you have

postgresql generates the message ‘duplicate key value violates unique constraint “oc_filecache_extended_pkey”’ multiple times a day. Log entries look like,

2026-09-27 00:30:43.380 MDT [1989941] nextcloud@nextcloud ERROR:  duplicate key value violates unique constraint "oc_filecache_extended_pkey"
2026-09-27 00:30:43.380 MDT [1989941] nextcloud@nextcloud DETAIL:  Key (fileid)=(821) already exists.
2026-09-27 00:30:43.380 MDT [1989941] nextcloud@nextcloud STATEMENT:  INSERT INTO "oc_filecache_extended" ("fileid", "creation_time") VALUES($1, $2)
2026-09-27 00:30:43.415 MDT [1989941] nextcloud@nextcloud ERROR:  duplicate key value violates unique constraint "oc_filecache_extended_pkey"
2026-09-27 00:30:43.415 MDT [1989941] nextcloud@nextcloud DETAIL:  Key (fileid)=(822) already exists.
2026-09-27 00:30:43.415 MDT [1989941] nextcloud@nextcloud STATEMENT:  INSERT INTO "oc_filecache_extended" ("fileid", "creation_time") VALUES($1, $2)

This is similar to Database errors in postgresql log (duplicate key value), which is now closed.

There are a number of bugs on this sort of issue already open.

root@hawk:~# pre postgres ; nextcloud --version
postgresql	17+278		all
postgresql-17	17.11-0+deb13u1		amd64
postgresql-client	17+278		all
postgresql-client-17	17.11-0+deb13u1		amd64
postgresql-client-common	278		all
postgresql-common	278		all
postgresql-common-dev	278		all
Nextcloud version 3.16.7-1~deb13u1 (Debian built)
Git revision 5584b240f9299c236ba99206b53577460fc12516
Using Qt 6.8.2, built against Qt 6.8.2
Using Qt platform plugin 'xcb'
Using 'OpenSSL 3.5.7 9 Jun 2026'
Running on Debian GNU/Linux 13 (trixie), x86_64
root@hawk:~# 

I get this for other constraints as well. previews_file_uniq_idx, mimetype_id_index, and notes_meta_file_user_index.

root@hawk:/var/log/postgresql# zgrep 'duplicate key value violates unique constraint' postgresql-17-main.log* | grep -v oc_filecache_extended_pkey
…