Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kQjPz-0000FI-6p for pgsql-sql@arkaria.postgresql.org; Fri, 09 Oct 2020 03:50:07 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kQjPx-0003TU-Cj for pgsql-sql@arkaria.postgresql.org; Fri, 09 Oct 2020 03:50:05 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kQjPx-0003TN-4I for pgsql-sql@lists.postgresql.org; Fri, 09 Oct 2020 03:50:05 +0000 Received: from mail-io1-xd41.google.com ([2607:f8b0:4864:20::d41]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kQjPp-0004h6-Rz for pgsql-sql@lists.postgresql.org; Fri, 09 Oct 2020 03:50:04 +0000 Received: by mail-io1-xd41.google.com with SMTP id l8so8688083ioh.11 for ; Thu, 08 Oct 2020 20:49:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:subject:from:to:cc:date:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=jTMLTh3MTph/hT0QfHwkm6/ni71RWCiXLLrOT7IzLpw=; b=I8FuMaPoIBVRH7j4RPArNgsmWCPRK4cv+MXljnPjPPcvm+EaAOrS3X4taS02pBwhJZ K1bdrIN8FebVBZnXqP6YqdYCjBTRPyX0tJyZ1J7vSboR2uu6XUN1hvTZthZM9KjOhwhL tRWz01EcMJZJ9tRTZ4lO1Bzm25tHUtP+OSYofqtLq0KLWgzPvykB0AotMm83TZqHZTS9 +GiUo7TZqMA6Rt7WzNJrWWlLlsST1uFNf9yBd+9TxSf+LnpyKp8pgzk4ANt7C8BSappU xH9VBqhLZpm9Q2IgdRI8zd4HBHOx6+Oh98z6rJK4fKm+z8Bm4IKoRsWnNLyooUcN7KJU 9Dyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:to:cc:date:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=jTMLTh3MTph/hT0QfHwkm6/ni71RWCiXLLrOT7IzLpw=; b=d4ZtB5y4DiP0XJ9SV7aLbFeU6zRTUtLo1HaKOLX31I2IGgM8l3IFv7PalgvTjVgZL4 8DdZehnClI0iarPaYnRqh9PooO/yMOPNIyiKPEZE2Bg3RIuY1/SBp6nd/LN9uV6r4040 Vf6/9S6GvDrzC0ieMEk+GP8Lwhovo9hudPYUztKgbfksZY1bLHE2h1sMBrGP9aaGgkM1 CgqWt8cDqy9J/7KUA9TClBqmsJFVo3eeFmEZquCska0dEmhqVflKsOk71boxagneV0YP 7ca3Wg0QGx6/pjO6tE8mFE6HI8lJkcTPriBaa1HJHGjnl/E06182Q9mnfJCi8k70CMyf RL7Q== X-Gm-Message-State: AOAM532wVXFcgtk6ZB9UChKbUAFRUEubWnC1bAHne7l+R1/TTe1D1Nml ErbDhtwG4bRGUybv5u8KXTDzDa08AQM= X-Google-Smtp-Source: ABdhPJzEJhXxa3PsI/OU/rmF21D3tKEtbfQ9abBkLQ7FySDOVeIA1grwF/QeXdeEGTMR5YPSQ5MBtQ== X-Received: by 2002:a6b:3e41:: with SMTP id l62mr8200609ioa.166.1602215395536; Thu, 08 Oct 2020 20:49:55 -0700 (PDT) Received: from pavlo-debian ([2601:449:c300:22f5:3d3b:da1f:d378:df44]) by smtp.gmail.com with ESMTPSA id b14sm3774716ilg.63.2020.10.08.20.49.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Oct 2020 20:49:55 -0700 (PDT) Message-ID: Subject: Re: libpq CREATE DATABASE operation from multiple treads From: p.sun.fun@gmail.com To: Guillaume Lelarge Cc: pgsql-sql@lists.postgresql.org Date: Thu, 08 Oct 2020 22:49:54 -0500 In-Reply-To: References: <390804abe88e4e9da9049f6e05c841783acaca47.camel@gmail.com> <124ce8dff8402159f20dec1bc1ac27e26ee39c23.camel@gmail.com> <96718FB0-E258-4342-BD6E-BCE6603BCBD5@gmail.com> <058A9601-35F6-42C1-AC4C-8DD4643E418F@gmail.com> <47a7c4ffa62aaf2b86854a657f484f33913207c9.camel@gmail.com> <23F4DE61-F81D-4740-A227-74B5EB41304C@gmail.com> <2631053.1602190588@sss.pgh.pa.us> <9109e992e899b2ed39b070cd12ecdbcdf435fbb6.camel@gmail.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.36.4-2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Fri, 2020-10-09 at 05:44 +0200, Guillaume Lelarge wrote: > Le ven. 9 oct. 2020 à 05:33, a écrit : > > On Thu, 2020-10-08 at 16:56 -0400, Tom Lane wrote: > > > Rob Sargent 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." > > See https://www.postgresql.org/docs/13/sql-createdatabase.html. Yep, you are right. Probably did't read carefully. Thanks for pointing out.