stac-utils / pgstac

Schema, functions and a python library for storing and accessing STAC collections and items in PostgreSQL
MIT License
153 stars 39 forks source link

Deadlock between search requests and ingestion process #311

Open drnextgis opened 1 month ago

drnextgis commented 1 month ago

We are encountering numerous errors when using stac-fastapi-pgstac for POST /search requests, such as the following:

DETAIL:  Process 20810 waits for AccessShareLock on relation 18359 of database 16399; blocked by process 600.
Process 600 waits for AccessExclusiveLock on relation 152918537 of database 16399; blocked by process 20810.
HINT:  See server log for query details.

In this instance, 18359 refers to the partition_steps materialized view, and 152918537 refers to the _items_491914_202410 (item partition). It seems likely that this issue is caused by an ongoing ingestion process (using pypgstac) during the search, which triggers a table lock on the mentioned partition. I'm curious about how the partition_steps view might be impacted by the ingestion and what strategies can mitigate this issue. Could the update_partition_stats_q function be contributing to the problem? For context: the usage queue is enabled, but perhaps the frequency at which it is triggered needs adjustment.