Re: drop database regardless of connections - Mailing list pgsql-general

From Kev
Subject Re: drop database regardless of connections
Date
Msg-id c3337c85-89c0-4af3-8636-05e49d0e837f@s39g2000prd.googlegroups.com
Whole thread Raw
In response to drop database regardless of connections  (Kev <kevinjamesfield@gmail.com>)
List pgsql-general
> > Anyway, you can use `psql' to query the activity tables using something
> > like "SELECT procpid FROM pg_stat_activity WHERE datname = 'dbtodrop'"
> > and see which backend pids need to be killed, then use 'pg_ctl kill
> > signame pid' to kill them. A bit of powershell, cmd.exe, etc should do
> > the job, though I agree that for win32 a builtin "pg_kill_backend()"
> > function would be nicer, in that you could just execute a query like:

Yep, pg_ctl did the trick in the end.  Thanks!

$ENV{PATH} = ''; # this automatically gets reset (and retainted) after
this script finishes

local our $sth = $dbh->prepare("SELECT procpid FROM pg_stat_activity
WHERE datname=? order by procpid") or die("Couldn't prepare statement:
" . $dbh->diestr);
$sth->execute($ENV{db}) or die("Couldn't execute statement: " . $sth-
>diestr);
local our @data;
while (@data = $sth->fetchrow_array())
{
    $r->print("Killing $data[0]...<br>");
    system('"c:\program files\postgresql\8.3\bin\pg_ctl.exe" kill TERM
' . $data[0]) == 0 or die("Couldn't kill process $data[0].");
}
$sth->finish;
$r->print("All done.");



Kev

pgsql-general by date:

Previous
From: Giorgio Valoti
Date:
Subject: Functions and transactions
Next
From: Kev
Date:
Subject: Re: plperlu and perl 5.10