title: Drop index locks
body: <p>My Postgres version is 9.6</p>
  
  <p>I tried today to drop an index from my DB with this command:</p>
  
  <pre><code>drop index index_name;
  </code></pre>
  
  <p>And it caused a lot of locks - the whole application was stuck until I killed all the sessions of the drop (why it was devided to several sessions?).</p>
  
  <p>When I checked the locks I saw that almost all the blocked sessions execute that query:</p>
  
  <pre><code>SELECT a.attname, format_type(a.atttypid, a.atttypmod),
  pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod    
  FROM
  pg_attribute a LEFT JOIN pg_attrdef d
                         ON a.attrelid = d.adrelid AND a.attnum = d.adnum
  WHERE a.attrelid = &lt;index_able_name&gt;::regclass
  AND a.attnum &gt; 0 AND NOT a.attisdropped
  ORDER BY a.attnum;
  </code></pre>
  
  <p>Is that make sense that this will block system actions?                                       </p>
  
  <p>So I decided to drop the index with concurrently option to prevent locks.</p>
  
  <pre><code>drop index concurrently index_name;
  </code></pre>
  
  <p>I execute it now from PGAdmin (because you can't run it from noraml transaction).</p>
  
  <p>It run over that 20 minutes and didnt finished yet. Index size is 20MB+-.</p>
  
  <p>And when I'm checking the DB for locks I see that there is a select query on that table and that's blocks the drop command.</p>
  
  <p>But when I took this select and execute in another session - this was vary fast (2-3) seconds.</p>
  
  <p>So why is that blocking my drop? is there another option to do that? maybe to disable index instead?</p>