Re: Creating database problem - Mailing list pgsql-general

From Tom Lane
Subject Re: Creating database problem
Date
Msg-id 16422.1099063614@sss.pgh.pa.us
Whole thread Raw
In response to Creating database problem  ("M.A. Oude Kotte" <marc@solcon.nl>)
List pgsql-general
"M.A. Oude Kotte" <marc@solcon.nl> writes:
> When I try to execute "CREATE DATABASE somename" while connected to
> database template1 as a non-superuser with createdb-rights, I get the
> error message "source database "template1" is being accessed by other
> users". This is correct, as I'm connected to the same server using
> pgAdmin III on a different PC. But my question is, why this error
> message?

It's a locking issue: if the other guy is changing the database while
you copy it, you'd get an inconsistent copy.

The test is not bulletproof, since in theory someone could connect to
the source database after we make the check and alter it underneath us
while the copy is still proceeding.  But it's better than no defense at all.

One possible way to work around the issue is to specify TEMPLATE template0
in CREATE DATABASE; there shouldn't be anybody connected there.

In retrospect it was probably a misfeature that template1 is both the
default database-to-copy and the default database-to-connect-to, but
this usage is so deeply entrenched that no one really wants to change it.

            regards, tom lane

pgsql-general by date:

Previous
From: "Marc G. Fournier"
Date:
Subject: Re: Question regarding the mailing list.
Next
From: "C G"
Date:
Subject: adding missing FROM-clause