https://blog.2ndquadrant.com/what-is-select-skip-locked-for-...
http://www.cybertec.at/skip-locked-one-of-my-favorite-9-5-fe...
Also, duplicate of: https://news.ycombinator.com/item?id=9576864
https://blog.2ndquadrant.com/what-is-select-skip-locked-for-...
http://www.cybertec.at/skip-locked-one-of-my-favorite-9-5-fe...
Also, duplicate of: https://news.ycombinator.com/item?id=9576864
Before that version, the behavior of silently skipping rows that had outstanding locks against them was specified by using "NOWAIT".
The decision of which specific clause to use is driven by which version of PostgreSQL you're using.
How much more plainly can I put that?
> To prevent the operation from waiting for other transactions to commit, use the NOWAIT option. SELECT FOR UPDATE NOWAIT reports an error, rather than waiting, if a selected row cannot be locked immediately.
[0] https://www.postgresql.org/docs/8.1/static/sql-select.html
Somehow, in all the the hundreds of millions (guesstimate) of rows I've used SELECT FOR UPDATE NOWAIT to process without lock conflicts, I've never actually gotten the error. At a guess, because I've generally always also used a LIMIT clause, and there have always been enough unlocked rows available to satisfy that.
Apologies for the noise.
"With NOWAIT, the statement reports an error, rather than waiting, if a selected row cannot be locked immediately. Note that NOWAIT applies only to the row-level lock(s) — the required ROW SHARE table-level lock is still taken in the ordinary way"