I have been noticing that sometimes we get a lot of open connections for a long time. Enabling enhanced metrics in RDS PostgreSQL I saw the following:
It seems this tuple wait event is making a lot of queries wait. I have taken a look and it seems it is from locks. I have run the query they suggest in the docs but it does not return anything, so not sure what is happening. In the Top sql queries you can see the following:
The queries are something like this (sorry for it being incomplete, RDS does not give me the full query):
UPDATE "customers_customer" SET "follow_up_date" = (CASE WHEN ("customers_customer"."id" = 140005033) THEN NULL WHEN ("customers_customer"."id" = 138501530) THEN NULL WHEN ("customers_customer"."id" = 140000447) THEN NULL WHEN ("customers_customer"."id" = 139999963) THEN NULL WHEN ("customers_customer"."id" = 140016560) THEN NULL WHEN ("customers_customer"."id" = 139998510) THEN NULL WHEN ("customers_customer"."id" = 138485030) THEN NULL WHEN ("customers_customer"."id" = 138507549) THEN NULL WHE
I'm not sure but I think this query comes from a mass update call on the Django ORM to a the customer model on the follow up date field.
So how can I debug this problem? Or mitigate it in the future? For now is not killing the database, but queries were starting to pile up and we have had problems with that in the past. If you need more information, please drop a comment below!