Re: Waiting for Disconnect - Mailing list pgsql-general

From Tom Lane
Subject Re: Waiting for Disconnect
Date
Msg-id 27143.1114150594@sss.pgh.pa.us
Whole thread Raw
In response to Waiting for Disconnect  (David Wheeler <david@kineticode.com>)
Responses Re: Waiting for Disconnect
List pgsql-general
David Wheeler <david@kineticode.com> writes:
> I have some tests that create a database, run a bunch of tests against
> it, and then drop it. But I was running into an issue where I'd get
> this error even after I disconnected from the test database:

>    ERROR:  source database "foo" is being accessed by other users

Yeah, I've seen this too.  The problem is that the backend you were
using hasn't exited yet when you try to issue the DROP DATABASE.
This is a bit surprising given the small amount of work normally
needed for a backend to exit.  (If it has to drop temp tables or
something, that might be another story, but I've seen it happen
with no such cleanup work needed.)

As best I can tell, it happens because the kernel has simply given
no, none, zero cycles to the orphaned backend, preferring instead
to run your shell, psql, and the postmaster.  I suppose this is
because some scheduler heuristic inside the kernel has decided that
the backend is a "background" process that deserves low priority.
I get the impression that some platforms are more prone to this than
others, which is consistent with the idea that it's a scheduler issue.

The only real solution I know of is to sleep for a little before
trying to issue the DROP DATABASE.  Certainly, adding more database
traffic as you suggest isn't going to improve matters.

            regards, tom lane

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: debug levels in server
Next
From: David Wheeler
Date:
Subject: Re: Waiting for Disconnect