Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>when you create a table, you get an exclusive lock on it that lasts to the end of the transaction. Even if you then go ahead and drop it.</p> <p>So if I start a tx and create a temp table:</p> <pre><code>steve@steve@[local] *=# create temp table foo(foo_id int); CREATE TABLE steve@steve@[local] *=# select * from pg_locks where pid = pg_backend_pid(); locktype | database | relation | page | tuple | virtualxid | transactionid | classid | objid | objsubid | virtualtransaction | pid | mode | granted ---------------+----------+-----------+------+-------+------------+---------------+---------+-----------+----------+--------------------+-------+---------------------+--------- virtualxid | | | | | 2/105315 | | | | | 2/105315 | 19098 | ExclusiveLock | t transactionid | | | | | | 291788 | | | | 2/105315 | 19098 | ExclusiveLock | t relation | 17631 | 10985 | | | | | | | | 2/105315 | 19098 | AccessShareLock | t relation | 17631 | 214780901 | | | | | | | | 2/105315 | 19098 | AccessExclusiveLock | t object | 17631 | | | | | | 2615 | 124616403 | 0 | 2/105315 | 19098 | AccessExclusiveLock | t object | 0 | | | | | | 1260 | 16384 | 0 | 2/105315 | 19098 | AccessShareLock | t (6 rows) </code></pre> <p>These 'relation' locks aren't dropped when I drop the table:</p> <pre><code>steve@steve@[local] *=# drop table foo; DROP TABLE steve@steve@[local] *=# select * from pg_locks where pid = pg_backend_pid(); locktype | database | relation | page | tuple | virtualxid | transactionid | classid | objid | objsubid | virtualtransaction | pid | mode | granted ---------------+----------+-----------+------+-------+------------+---------------+---------+-----------+----------+--------------------+-------+---------------------+--------- virtualxid | | | | | 2/105315 | | | | | 2/105315 | 19098 | ExclusiveLock | t object | 17631 | | | | | | 1247 | 214780902 | 0 | 2/105315 | 19098 | AccessExclusiveLock | t transactionid | | | | | | 291788 | | | | 2/105315 | 19098 | ExclusiveLock | t relation | 17631 | 10985 | | | | | | | | 2/105315 | 19098 | AccessShareLock | t relation | 17631 | 214780901 | | | | | | | | 2/105315 | 19098 | AccessExclusiveLock | t object | 17631 | | | | | | 2615 | 124616403 | 0 | 2/105315 | 19098 | AccessExclusiveLock | t object | 17631 | | | | | | 1247 | 214780903 | 0 | 2/105315 | 19098 | AccessExclusiveLock | t object | 0 | | | | | | 1260 | 16384 | 0 | 2/105315 | 19098 | AccessShareLock | t (8 rows) </code></pre> <p>In fact, it added two more locks... It seems if I continually create/drop that temp table, it adds 3 locks each time.</p> <p>So I guess one answer is that you will need enough locks to cope with all these tables being added/dropped throughout the transaction. Alternatively, you could try to reuse the temp tables between queries, simply truncate them to remove all the temp data?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload