Re: Drop database / database in use question

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Dan Armbrust" <daniel(dot)armbrust(dot)list(at)gmail(dot)com>
Cc: "pgsql general" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Drop database / database in use question
Date: 2008-10-17 00:36:57
Message-ID: 4170.1224203817@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"Dan Armbrust" <daniel(dot)armbrust(dot)list(at)gmail(dot)com> writes:
> First, after validating some passwords, my installer will run this command:
> psql -c "select datname from pg_stat_activity where datname='fred'" -U
> username -d template1
> I then scan the output looking for 'fred'. My (perhaps incorrect)
> assumption is that if I don't find the database name 'fred' in the
> output, then I can assume that no process is using this database, and
> I should be able to drop it.

There are obvious race conditions in that assumption. Why don't you
just try the drop and see if it succeeds?

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tim Uckun 2008-10-17 03:09:10 Question about NOT NULL and default values.
Previous Message Tom Lane 2008-10-17 00:33:56 Re: postgresql on 64-bit windows