Re: drop database regardless of connections

From: Kev <kevinjamesfield(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: drop database regardless of connections
Date: 2008-04-07 15:10:28
Message-ID: c3337c85-89c0-4af3-8636-05e49d0e837f@s39g2000prd.googlegroups.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Kev 2008-04-07 15:14:22 Re: plperlu and perl 5.10
Previous Message Douglas McNaught 2008-04-07 14:53:34 Re: slow pgsql tables - need to vacuum?