Tuesday 4 March 2014

Postgres 9 how to drop a database that is in-use





PostgreSQL's statistics collector is a subsystem that supports collection and reporting of information about server activity

Sample below to identify the procid for database cmdbuild:

postgres=# select * from pg_stat_activity where datname='cmdbuild';

datid datname procpid usesysid
44867 cmdbuild 2467 16384
44867 cmdbuild 2468 16384
(2 rows)

pg_cancel_backend and pg_terminate_backend send signals (SIGINT or SIGTERM respectively) to backend processes identified by process ID. 

postgres=# select pg_terminate_backend(procpid) from pg_stat_activity where datname='cmdbuild';
 pg_terminate_backend 
----------------------
 t
 t
(2 rows)

postgres=# DROP DATABASE cmdbuild;
DROP DATABASE




No comments:

Post a Comment