Select unlocked row in Postgresql

后端 未结 14 2121
你的背包
你的背包 2020-12-13 06:20

Is there a way to select rows in Postgresql that aren\'t locked? I have a multi-threaded app that will do:

Select... order by id desc limit 1 for update
         


        
14条回答
  •  清歌不尽
    2020-12-13 06:37

    What are you trying to accomplish? Can you better explain why neither unlocked row updates nor full transactions will do what you want?

    Better yet, can you prevent contention and simply have each thread use a different offset? This won't work well if the relevant portion of the table is being updated frequently; you'll still have collisions but only during heavy insert load.

    Select... order by id desc offset THREAD_NUMBER limit 1 for update
    

提交回复
热议问题