First, find the activities that are taken place against the target database, you can query thepg_stat_activity view as the following query:

SELECT
    *
FROM
    pg_stat_activity
WHERE
    datname = 'target_database';

 

 Second, terminate the active connections by issuing the following query:

SELECT
    pg_terminate_backend (pg_stat_activity.pid)
FROM
    pg_stat_activity
WHERE
    pg_stat_activity.datname = 'target_database';
Notice that if you use PostgreSQL version 9.1 or earlier, use the procpid column instead of the pid column because PostgreSQL changed procid column to pid column since version 9.2

Third, execute the DROP DATABASE statement:

DROP DATABASE target_database;

 

相关文章:

  • 2022-12-23
  • 2021-06-06
  • 2021-12-15
  • 2021-05-20
  • 2022-01-10
  • 2022-12-23
  • 2021-12-05
猜你喜欢
  • 2021-12-03
  • 2021-12-16
  • 2021-10-20
  • 2022-12-23
  • 2021-07-31
相关资源
相似解决方案