'Postgres query is getting lock while executing through shell script

The below query is getting locked by executing through perl

ALTER TABLE base_table
   DETACH PARTITION part_table;

By using this query

  select pid,state, 
       usename, 
       pg_blocking_pids(pid) as blocked_by, 
       query as blocked_query
from pg_stat_activity
where cardinality(pg_blocking_pids(pid)) > 0;
  pid  | state  | usename  | blocked_by |           blocked_query            
-------+--------+----------+------------+------------------------------------
 20521 | active | parttest | {20306}    |         ALTER TABLE BASE        +
       |        |          |            |    DETACH PARTITION part_table
       |        |          |            | 
(1 row)

Can you please suggest me how to solve this issue?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source