title: Remove pg_lock from postgres 9.6.6 without any PID
body: <p>We had a task which was stuck so I used <code>SELECT pg_cancel_backend(&lt;pid of the process&gt;)</code> to kill the task. However the lock that the task hold didn't go away and now one of my table is locked.</p>
  
  <p>I am trying to run a <code>COPY</code> command on the table and it gets stuck with <code>wait_event_type = Lock</code>.</p>
  
  <hr>
  
  <p>System being Used:</p>
  
  <blockquote>
    <p>Server: AWS RDS db.m4.xlarge<br>
    DB: PostgreSQL 9.6.6</p>
  </blockquote>
  
  <hr>
  
  <blockquote>
    <p>select * from pg_locks;</p>
  </blockquote>
  
  <pre><code>locktype      | database | relation | page | tuple | virtualxid | transactionid | classid | objid | objsubid | virtualtransaction |  pid  |       mode       | granted | fastpath
  --------------+----------+----------+------+-------+------------+---------------+---------+-------+----------+--------------------+-------+------------------+---------+----------
  relation      |    16390 |    19694 |      |       |            |               |         |       |          | -1/24019935        |       | RowExclusiveLock | t       | f
  transactionid |          |          |      |       |            |      24019935 |         |       |          | -1/24019935        |       | ExclusiveLock    | t       | f
  </code></pre>
  
  <p><br></p>
  
  <blockquote>
    <p>select * from pg_prepared_xacts where transaction=24019935;</p>
  </blockquote>
  
  <pre><code>transaction |             gid              |           prepared           |  owner   | database
  ------------+------------------------------+------------------------------+----------+----------
  24019935    | PGDIRTY:dirty_state::9994733 | 2018-06-27 13:40:12.88981-08 | postgres | pg
  </code></pre>
  
  <p><br>
  I already tried doing the step suggested in <a href="https://stackoverflow.com/questions/42952635/remove-locks-without-a-pid-in-postgres">Remove locks without a pid in postgres</a>, but it doesn't show any pgid.</p>
  
  <p>I also tried rebooting my database but the lock still persists.</p>
  
  <p>Can anyone help me figure out how to get rid of this lock ?</p>
  
  <p>Thanks</p>