Replication DB Postgres
Hi everyone, in my project, I'm getting the following error "Serialization failure: 7 ERROR: canceling statement due to conflict with recovery DETAIL: User query might have needed to see row versions that must be removed"
So part of the solution was analyzing related queries and tunned them, however, this hasn't been enough, and the error persists.
So I went a little deep about this subject in Postgres documentation and I found this as an alternative: "Canceled queries may be retried immediately (after beginning a new transaction, of course). Since query cancellation depends on the nature of the WAL records being replayed, a query that was canceled may well succeed if it is executed again." (https:// www.postgresql.org/docs/current/hot-standby.html#HOT-STANDBY-CONFLICT)
So the first easy solution comes out similar to this: try{ //First try $data = Model::where(conditions)->get(); }catch(QueryException $e){ if(str_contains($e->getMessage(), "User query might have needed to see row versions that must be removed"){ //Retry $data = Model::where(conditions)->get(); } }
This should work, but I feel is not the right way to wrap every part of my code with try and catch for this, Is there any way to wrap this in a general part, like registering a provider?
Have you resolved the problem in another way?
Please or to participate in this conversation.