2

I have tried below commands as postgres(super) user and the owner user:

Drop index <index_name>;
Drop index <index_name> cascade;
Drop index concurrently <index_name>;

The query does not give any error but is in the hung state forever till cancelled.

3
  • 2
    Your statements are ok in general. You have probably other tasks running in your database which preventing the completion. Commented Oct 17, 2017 at 5:34
  • Yes, that can be the case. Is there any way to find out which query/session is using the index? Commented Oct 17, 2017 at 5:40
  • 3
    wiki.postgresql.org/wiki/Lock_Monitoring Commented Oct 17, 2017 at 5:48

1 Answer 1

5

Your statements are ok in general. There are other processes having locks on the indices preventing the drop statements from finishing. You can see the active statements with

SELECT * FROM pg_stat_activity;

You should set log_statement appropriately if necessary.

Edit: pg_locks will give you information about specific locks:

SELECT a.datname,
         c.relname,
         l.transactionid,
         l.mode,
         l.GRANTED,
         a.usename,
         a.query, 
         a.query_start,
         age(now(), a.query_start) AS "age", 
         a.pid 
    FROM  pg_stat_activity a
     JOIN pg_locks         l ON l.pid = a.pid
     JOIN pg_class         c ON c.oid = l.relation
    ORDER BY a.query_start;
Sign up to request clarification or add additional context in comments.

2 Comments

Yes, it worked. After closing the dependent sessions, I was able to drop the index.
@CraigRinger: You are right. I've extended my answer.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.