Re: Drop database / database in use question - Mailing list pgsql-general

From Tom Lane
Subject Re: Drop database / database in use question
Date
Msg-id 4170.1224203817@sss.pgh.pa.us
Whole thread Raw
In response to Drop database / database in use question  ("Dan Armbrust" <daniel.armbrust.list@gmail.com>)
Responses Re: Drop database / database in use question  ("Dan Armbrust" <daniel.armbrust.list@gmail.com>)
List pgsql-general
"Dan Armbrust" <daniel.armbrust.list@gmail.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

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: postgresql on 64-bit windows
Next
From: "Tim Uckun"
Date:
Subject: Question about NOT NULL and default values.