-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
psycopg2.errors.UniqueViolation: duplicate key value violates unique constraint "receipts_linearized_uniqueness" #16138
Comments
Synapse is attempting to upsert a row here (I.e The index in question is |
In the meantime it would be useful if you could provide us with the output of
to see what has gone wrong. |
Here are the outputs:
And about:
Oh. While trying to save our database we did end up recreating some tables manually, including some indexes/constraints… We used this file, ie. the latest "full" version of the schema, as source of truth to try to recreate things exactly as expected by synapse. But I realize only now, with your comment that this file is only giving us version 72 of the schema, which since then has much evolved but only through deltas (73 to 79)… which we have not taken into account in our database repair operations. So I think it's completely our fault :) and that we should be able to save the situation by going through deltas 73 to 79 and finding what changes we failed to apply to the tables we re-created by hand… |
Ahh yes---we have a script to cut a full schema dump (which avoid having to run migrations and background updates) but we haven't run it in a while. Perhaps we ought to do that soon.
Ouch, that sounds painful---but I'm glad we've got a hypothesis for what went wrong. Let us know how you get on and if there are any problems. We can't officially support manual database tinkering... but we might be able to offer some quick suggestions if you see anything strange. |
Sounds like it isn't the cause, but for thoroughness: there was a bunch of issues here (#14406, #14123, #14377), which we think were solved (#14650, #14453, #14915). Some of those issues might have some commands to run to manually poke data around the tables (and I think one of the background updates does this for you?) You might just need to run those. |
Update: We checked all the schema deltas after version 72 and compared to our current tables, and we were happy that the only missing bit was the Therefore we simply ran We did find another similar error in the logs that occurs very very rarely (once every two days on average), which is Apologies for the extraneous ticket, and thanks for your comments that pointed us in the right direction! |
No worries---thanks for confirming!
We see similar errors on Matrix.org. I would guess that two things are racing to insert into |
Description
We encountered a database corruption problem some weeks ago, and had to make many fixes in the database by hand to reach again a consistent state that would allow synapse to run. We were fortunately successful enough, and our instance is now running nicely once more and without any remaining corruption.
However, after this intervention, we noticed our homeserver started having lots of errors labeled
sycopg2.errors.UniqueViolation: duplicate key value violates unique constraint "receipts_linearized_uniqueness"
. This is probably due to this table having obtained new rows it shouldn't have during the corruption, and these lines remained in place as their presence does not directly violates the contraint − in fact, it's adding new rows that Synapse refuses as it would break the constraint.While obviously Synapse is not responsible of external database problems, I thought it was relevant to open this issue as I find it strange that it is not able to recover from such a situation, eg. by deleting old rows before inserting new ones, in order to preserve the uniqueness constraint?
Steps to reproduce
receipts_linearized
tableHomeserver
Private
Synapse Version
1.90.0
Installation Method
Docker (matrixdotorg/synapse)
Database
PostgreSQL v15
Workers
Single process
Platform
Debian 11, no virtualization, synapse and postgre running in Docker containers
Configuration
No response
Relevant log output
Anything else that would be useful to know?
No response
The text was updated successfully, but these errors were encountered: