Postgresql DROP TABLE doesn't work

前端 未结 7 1258
别跟我提以往
别跟我提以往 2020-12-08 02:43

I\'m trying to drop a few tables with the \"DROP TABLE\" command but for a unknown reason, the program just \"sits\" and doesn\'t delete the table that I want i

7条回答
  •  我在风中等你
    2020-12-08 03:13

    Just do

    SELECT pid, relname
    FROM pg_locks l
    JOIN pg_class t ON l.relation = t.oid AND t.relkind = 'r'
    WHERE t.relname = 'Bill';
    

    And then kill every pid by

    kill 1234
    

    Where 1234 is your actual pid from query results.

    You can pipe it all together like this (so you don't have to copy-paste every pid manually):

    psql -c "SELECT pid FROM pg_locks l 
        JOIN pg_class t ON l.relation = t.oid AND t.relkind = 'r' 
        WHERE t.relname = 'Bill';" | tail -n +3 | head -n -2 | xargs kill
    

提交回复
热议问题