Skip site navigation (1) Skip section navigation (2)

Re: dropdb: database removal failed: active sessions

From: John R Pierce <pierce(at)hogranch(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: dropdb: database removal failed: active sessions
Date: 2011-08-29 20:39:40
Message-ID: 4E5BF90C.20901@hogranch.com (view raw or flat)
Thread:
Lists: pgsql-general
On 08/29/11 12:22 PM, JD Wong wrote:
> I cannot dropdb.  Postgres throws me:
> dropdb: database removal failed: ERROR:  database "database1" is being 
> accessed by other users
> DETAIL:  There are 1 other session(s) using the database.
>
> the "select datname,current_query,query_start from pg_stat_activity ;" 
> query gives me:
>
>          datname         |                                             
>          current_query                                                 
>       |          query_start
> -------------------------+--------------------------------------------------------------------------------------------------------------------------+-------------------------------
> ...
>  database1             | <IDLE>                                       
>                                                                       
>       | 2011-08-29 15:07:31.423596-04
>
> Is the drop being prevented by the active query from database2?  If 
> not how can I kill the <IDLE> query that must be preventing deletion.


any connection to the database, even idle, will prevent a drop database.

try...

     select pg_terminate_backend(procpid) from pg_stat_activity where 
datname = 'database1';

that will snuff those processes.  then you can drop the database, 
assuming the clients don't immediately reconnect.


-- 
john r pierce                            N 37, W 122
santa cruz ca                         mid-left coast


In response to

Responses

pgsql-general by date

Next:From: Alan HodgsonDate: 2011-08-29 20:46:22
Subject: Re: heavy swapping, not sure why
Previous:From: Lonni J FriedmanDate: 2011-08-29 20:36:07
Subject: heavy swapping, not sure why

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group