Re: libpq CREATE DATABASE operation from multiple treads - Mailing list pgsql-sql

From Guillaume Lelarge
Subject Re: libpq CREATE DATABASE operation from multiple treads
Date
Msg-id CAECtzeWQJpT9rzDY1-xJQSUjKC7Du+kpKm4d1pUJ4_E9GrhEHw@mail.gmail.com
Whole thread Raw
In response to Re: libpq CREATE DATABASE operation from multiple treads  (p.sun.fun@gmail.com)
Responses Re: libpq CREATE DATABASE operation from multiple treads  (p.sun.fun@gmail.com)
List pgsql-sql
Le ven. 9 oct. 2020 à 05:33, <p.sun.fun@gmail.com> a écrit :
On Thu, 2020-10-08 at 16:56 -0400, Tom Lane wrote:
> Rob Sargent <robjsargent@gmail.com> writes:
> > OK, well that’s a special db.  Didn’t know it was that special,
> > though!
>
> It's not that special.  The issue here is that each session is
> connecting
> to template1 and then trying to clone template1.  You can't clone an
> active database, because you might not get a consistent copy.  CREATE
> DATABASE knows that its own session isn't concurrently making any
> changes, so it allows copying the current database --- but it can't
> know what some other session is doing, so if it sees some other
> session
> is also connected to the source database, it spits up.
>
> As I already said, routinely connecting to template1 is pretty bad
> practice to start with, so the preferred answer is "don't do that".
>
>                       regards, tom lane

Thank you, guys. I will switch to the "postgres" database as a default
one. IMHO, it is worth adding to the documentation into the CREATE
DATABASE section. I am glad that PostgreSQL has a strong community that
stays behind the product.

It's already in the documentation:

"Although it is possible to copy a database other than template1 by specifying its name as the template, this is not (yet) intended as a general-purpose “COPY DATABASE” facility. The principal limitation is that no other sessions can be connected to the template database while it is being copied. CREATE DATABASE will fail if any other connection exists when it starts; otherwise, new connections to the template database are locked out until CREATE DATABASE completes. See Section 22.3 for more information."

pgsql-sql by date:

Previous
From: p.sun.fun@gmail.com
Date:
Subject: Re: libpq CREATE DATABASE operation from multiple treads
Next
From: p.sun.fun@gmail.com
Date:
Subject: Re: libpq CREATE DATABASE operation from multiple treads