Re: libpq CREATE DATABASE operation from multiple treads

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Rob Sargent <robjsargent(at)gmail(dot)com>
Cc: p(dot)sun(dot)fun(at)gmail(dot)com, "pgsql-sql(at)lists(dot)postgresql(dot)org" <pgsql-sql(at)lists(dot)postgresql(dot)org>
Subject: Re: libpq CREATE DATABASE operation from multiple treads
Date: 2020-10-08 20:56:28
Message-ID: 2631053.1602190588@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Rob Sargent <robjsargent(at)gmail(dot)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

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2020-10-08 20:57:34 Re: libpq CREATE DATABASE operation from multiple treads
Previous Message p.sun.fun 2020-10-08 20:52:22 Re: libpq CREATE DATABASE operation from multiple treads