13

I had created an index wrongly and now I am trying to drop that index. Since the table is large, dropping the index is taking lot of time. Is there any other way to drop the index quickly?

2
  • 3
    If it's taking that long, it's probably being locked by some other transaction. Check pg_stat_activity
    – user1822
    Commented Sep 14, 2013 at 6:09
  • See also: postgresql - Why does dropping an index take longer than creating it? - stackoverflow.com/q/26346147 Commented Nov 7, 2019 at 18:38

2 Answers 2

12

You could try DROP INDEX [ CONCURRENTLY ] name

  • CONCURRENTLY

    Drop the index without locking out concurrent selects, inserts, updates, and deletes on the index's table. A normal DROP INDEX acquires exclusive lock on the table, blocking other accesses until the index drop can be completed. With this option, the command instead waits until conflicting transactions have completed.

  • Here's the documentation for postgres 9.2: http://www.postgresql.org/docs/9.2/static/sql-dropindex.html

Note: This feature is not available before postgres 9.2.

3
  • DROP INDEX CONCURRENTLY idx_treenodes_mid_nid ; shows me syntax error
    – user2659199
    Commented Sep 14, 2013 at 6:08
  • 1
    What is the syntax error? Which version of postgres are you using?
    – Mingyu
    Commented Sep 14, 2013 at 6:11
  • ERROR: syntax error at or near "CONCURRENTLY" LINE 1: DROP INDEX CONCURRENTLY idx_treenodes_mid_nid ..... Im using 9.1 version
    – user2659199
    Commented Sep 14, 2013 at 6:21
0

Somehow maintainance_work_mem is not considered as maintenance operations and it does not have any implication to speed up the drop index process.

Dropping the index concurrently seems to be the only option but I won't suggest to directly run it from Pgadmin or Psql terminal. Because if the session gets terminated or due to timeout, it may leave index inconsistent.

Hope this helps. Aj

http://www.postgresql-blog.com/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.