title: ShareLock and ExclusiveLock with postgres database
body: <p>I was checking the lock in logs of one application which is running in heroku and its shows so many lock from delayed_jobs and increment_counter, also these time i got so many timeouts</p>
  
  <pre><code>sql_error_code = 00000 LOG: process 129728 still waiting for ShareLock on 
  transaction 1296511670 after 1000.149 ms
  
  2017-06-02T16:24:58+00:00 app 
  postgres.129728 - - [TEST] [7-2] sql_error_code = 00000 DETAIL: Process
  holding the lock: 129457. Wait queue: 129728.
  
  02 Jun 2017 20:24:58.338198 &lt;134&gt;1 2017-06-02T16:24:58+00:00 app
  postgres.129728 - - [TEST] [7-3] sql_error_code = 00000 CONTEXT: while 
  locking tuple (75,2) in relation "delayed_jobs"
  
  LOG: process 129429 acquired ExclusiveLock on tuple (878044,83) of relation
  16953 of database 16385 after 3220.356 ms
  
  02 Jun 2017 20:24:58.338591 &lt;134&gt;1 2017-06-02T16:24:58+00:00 app 
  postgres.129728 - - [TEST] [7-4] sql_error_code = 00000 STATEMENT: UPDATE 
  "delayed_jobs" SET locked_at = '2017-06-02 16:24:57.033870', locked_by = 
  'host:a96aff72dae123123e pid:4' WHERE id IN (SELECT id FROM 
  "delayed_jobs" WHERE ((run_at &lt;= '2017-06-02 16:24:57.032776' AND (locked_at 
  IS NULL OR locked_at &lt; '2017-06-02 12:24:57.032817') OR locked_by = 
  'host:a96aff72dae123123e pid:4') AND failed_at IS NULL) 
  ORDER BY priority ASC, run_at ASC LIMIT 1 FOR UPDATE) RETURNING *
  
   sql_error_code = 00000 DETAIL: Process holding the lock: 129495. Wait queue: 
   3276.
  
   02 Jun 2017 20:25:09.279197 &lt;134&gt;1 2017-06-02T16:25:08+00:00 app  
   postgres.3276     
   - - [TEST] [7-3] sql_error_code = 00000 CONTEXT: while updating tuple 
   (878034,120) in relation "messages"
  
  
   02 Jun 2017 20:25:09.279248 &lt;134&gt;1 2017-06-02T16:25:08+00:00 app 
   postgres.3276
   - - [TEST] [7-4] sql_error_code = 00000 
   STATEMENT: UPDATE "messages" SET 
   "item_no" = COALESCE("item_no", 0) + 1 WHERE "messages"."id" = 
   48290879
  </code></pre>
  
  <p>I think this is not a normal lock, is there any way to fix these kind of lock?</p>