Duplicate key value violates unique constraint on a table during upgrade

Sounds like the index is corrupted. You can look around at some other topics about corrupt indexes.

First you can try to rebuild the index. Also note that many searches won’t find the duplicate entries because they assume that the index works.