Open FourSeventy opened 1 year ago
Update on this. I looked at all of the insert and update queries that run in transactions. I only have 4 queries that run in transactions. I made sure that they all update tables in the same order. I still end up getting into a deadlock somehow. I'm working to lock down the exact queries that are getting deadlocked, but I know that one of the queries that is caught in the deadlock is a simple update not part of any transactions. Here is that query UPDATE conversions SET sent_to_capi=true WHERE id = ANY($1)
Here is the breakdown of the four services that write to the database concurrently and the tables that they write to in order
service1
accounts -> campaigns -> adsets -> ads -> admetrics
service2
customers -> users -> sessions -> conversions
service3
customers -> users -> sessions -> conversions
service4
customers -> users -> sessions -> surveys -> conversions -> pageviews
Second update. I'm currently running an experiment with just the first three immvs, data_hourly_sessions, data_hourly_conversions, and data_hourly_admetrics. So far no deadlocks. These immvs don't have any JOINs so its possible that the immvs with the joins are causing the issue.
@FourSeventy I am sorry for a late reply. I have not succeeded to reproduce the deadlock yet. For investigation, could you please provide more details?
Firstly, may I have definitions of tables involving to these IMMV
Here is the breakdown of the four services that write to the database concurrently and the tables that they write to in order
Does each service access these tables in this order in a separate transaction?
Here is that query UPDATE conversions SET sent_to_capi=true WHERE id = ANY($1)
This query is not included in any above transactions and executed in the other transaction?
I have a database that has 9 immv's that all create slightly different views of the same few base tables. These base tables are regularly inserted to and updated concurrently by around 5 different external services and processes. They are updated rapidly, but the updates are only to a few thousand records, which is a small faction of the total number of rows. The base tables have tens of millions of records in them.
The problem I am facing is that my update and insertion processes all become deadlocked. The error messages look like this
Relation 191517 and relation 191769 are immvs. Unfortunately I don't know which one they are because I dropped the views right away when they were deadlocking and didn't have time to look it up.
Do I have too many immvs on the same tables? Is updating the db from multiple threads not supported with immvs?
Below are my immv definitions.