I already know that transactions at the serializable level should be retried in case of a serialization failure.
I'm just curious about 2 scenarii where a 40001 error is raised :
- When running an INSERT command.
- When issuing a PREPARE TRANSACTION STATEMENT.
What could be the root cause of a serialization issue in each case ? What is your experience about these particular cases ?
I would like to try to reduce these issues by looking at the concurrent transactions.
TIA.
UPDATE 1
From the PostgreSQL wiki I've learned that among the serializable transactions, the first COMMIT wins. PREPARE seems to behave like a COMMIT so I could understand why it may fail.
But, for the INSERT case, if there is no concurrent serializable transaction that performed a SELECT, I'm missing the point. From what I've seen so far there are only multiple concurrent INSERT.
UPDATE 2
I've found out that I have concurrent SELECT ... FOR SHARE on the same table.
UPDATE 3
There seems to be a pattern here, the transaction last longer than usual when it fails. This is because we are processing files, which may take longer than expected. I'll try to reduce the duration of the transaction by reodering the various tasks.