-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
duplicate key value violates unique constraint "event_push_summary_unique_index2" DETAIL: Key (user_id, room_id, thread_id)=(@myuser:myserver.com, !XJcwvojEyyhGBJngjo:matrix.org, main) already exists. #15736
Comments
I think this is erroring at:
|
Hopefully: #15738 should fix it. Running the following query manually before upgrade should also allow you to upgrade: DELETE FROM event_push_summary AS a WHERE thread_id IS NULL AND EXISTS (
SELECT 1 FROM event_push_summary AS b
WHERE b.thread_id = 'main' AND a.user_id = b.user_id AND a.room_id = b.room_id
); |
Hi, running this, I got Unfortunately trying to upgrade to synapse 1.85 still did not work. I'm not sure if its due to my own tinkering as I said in my original post, but this is the error I got trying to run synapse 1.85
running returns 0 rows |
Huh, that is way more rows than I would expect to see. And if it's deleted rows then why is it still failing the unique constraint :/ Can you run |
Hmm, can you run: select * from event_push_summary where user_id = '@myuser:myserver.com' and room_id = '!XJcwvojEyyhGBJngjo:matrix.org' and thread_id IS NULL; I wonder if you've managed to get multiple rows with a null thread ID somehow |
running
|
Ouch. How did that happen. Annoyingly postgres unique indexes (by default) treat nulls as distinct. I think the following queries should fix it, though it might give the wrong notification counts for some of those rooms: -- Copy the NULL threads to have a 'main' thread ID.
--
-- Note: Some people seem to have duplicate rows with a `NULL` thread ID, in
-- which case we just fudge it with using MAX of the values. The counts *may* be
-- wrong for such rooms, but a) its an edge case, and b) they'll be fixed when
-- the user reads the room.
INSERT INTO event_push_summary (user_id, room_id, notif_count, stream_ordering, unread_count, last_receipt_stream_ordering, thread_id)
SELECT user_id, room_id, MAX(notif_count), MAX(stream_ordering), MAX(unread_count), MAX(last_receipt_stream_ordering), 'main'
FROM event_push_summary
WHERE thread_id IS NULL
GROUP BY user_id, room_id, thread_id;
DELETE FROM event_push_summary AS a WHERE thread_id IS NULL; |
Hi, I ran this and it seems to have worked, deleting a few thousand rows. I'm now running synapse 1.85, thank you |
Thanks for testing the queries out! We'll put out a 1.85.1 that fixes up the schema deltas to do this automatically. |
Description
When upgrading from synapse 1.84 to 1.85. synapse fails to start with the error
psycopg2.errors.UniqueViolation: duplicate key value violates unique constraint "event_push_summary_unique_index2" DETAIL: Key (user_id, room_id, thread_id)=(@myuser:myserver.com, !XJcwvojEyyhGBJngjo:matrix.org, main) already exists.
I had 2 other instances of this error, which I deleted like so
Looking at the db, there is only one corresponding row, I found this with
select * from event_push_summary where user_id = '@myuser:myserver.com' and room_id = '!XJcwvojEyyhGBJngjo:matrix.org' and thread_id = 'main';
I attempted to delete the row like so
delete from event_push_summary where user_id = '@myuser:myserver.com' and room_id = '!XJcwvojEyyhGBJngjo:matrix.org' and thread_id = 'main';
Then I attempted to restart synapse, which gave me a new username and room error that already exists.
However, for this final one, the database reports there are no rows for this, but synapse still gives the same startup error.
I have had to rollback to 1.84.
My setup, I'm running Ubuntu 22.04, running synapse with official docker container. Running official postgres docker image 13.10-alpine
Steps to reproduce
Homeserver
myhomeserver.com
Synapse Version
1.85
Installation Method
Docker (matrixdotorg/synapse)
Database
13.10-alpine
Workers
Multiple workers
Platform
Ubuntu 22.04 with docker containers
Configuration
No response
Relevant log output
Anything else that would be useful to know?
Possibly related #15597
The text was updated successfully, but these errors were encountered: