title: Deadlock while bulk inserts in Postgres
body: <blockquote>
    <p>PG::TRDeadlockDetected: ERROR: deadlock detected\nDETAIL: Process 5449
    waits for ShareLock on transaction 1712360; blocked by process
    1325.\nProcess 1325 waits for ShareLock on transaction 1712346; blocked by process 5449.\nHINT: See server log for query
    details.\nCONTEXT: while inserting index tuple (663142,4) in relation
    "contacts"\n:</p>
  </blockquote>
  
  <p>Getting deadlock while performing concurrent bulk inserts on table Contact.
  This table also has unique constraint on column phone. 
  ,Also there are parallel reads on this table.</p>
  
  <p>Query on which deadlock  occurs is </p>
  
  <pre><code>INSERT INTO contacts (phone, name, email, external_id, created_at, updated_at) VALUES #{values} ON CONFLICT DO NOTHING;
  
  where values is list  of tuples(phone, name, email, external_id, created_at, updated_at) of size 300 to 400.
  </code></pre>
  
  <p>Primary key of this table is uuid and default value is <code>gen_random_uuid()</code></p>