You should consider using `SKIP LOCKED` feature from Postgres. Find more info here: https://www.postgresql.org/docs/9.5/sql-select.html#SQL-FOR-UPDATE-SHARE  It is also explained in details on this blog post: https://www.2ndquadrant.com/en/blog/what-is-select-skip-locked-for-in-postgresql-9-5/