title: How synchronize multiple machines to insert one single row?
body: <p>I have some code that is running on several machines, and accesses an Oracle database. I use this database (among other things) as a synchronization object between the different machines by locking rows.</p>
  
  <p>The problem I have is that when my process is starting, there is nothing yet in the database to rely on for synchronization, and my processes get oracle exceptions about <code>unique constraint violated</code> since they all try to insert at the same time.</p>
  
  <p>My solution for now is to catch that precise exception and ignore it, but I don't really like having exceptions being thrown in the normal workflow of my application.</p>
  
  <p>Is there a better way to "test and insert" atomically in a database ? Locking the whole table/partition when inserting a row is not an acceptable solution.</p>
  
  <p>I checked <code>merge into</code>, thinking it was my solution, but it produces the same problem.</p>