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 1kQj9d-00084C-1D for pgsql-sql@arkaria.postgresql.org; Fri, 09 Oct 2020 03:33:13 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kQj9b-0000wz-5z for pgsql-sql@arkaria.postgresql.org; Fri, 09 Oct 2020 03:33:11 +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 1kQj9a-0000ws-Tk for pgsql-sql@lists.postgresql.org; Fri, 09 Oct 2020 03:33:10 +0000 Received: from mail-il1-x142.google.com ([2607:f8b0:4864:20::142]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kQj9Y-0004Z7-Nx for pgsql-sql@lists.postgresql.org; Fri, 09 Oct 2020 03:33:10 +0000 Received: by mail-il1-x142.google.com with SMTP id b2so7958666ilr.1 for ; Thu, 08 Oct 2020 20:33:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:subject:from:to:date:in-reply-to:references:user-agent :mime-version:content-transfer-encoding; bh=psjVW0khUjjd25PtwUMCIMd8qmRSJTiZob18zG3yr9I=; b=OqzSmFxL3D++egA0ySb+zgiMYEVi6YJrqmvbVOCgF/1XWvXNz6qttJX4ePCb+ptQeg W0y07CbF6rWnbFo3SQ7qS4SJebkrq/WkAx4XL6ZCIpVMgA8Gu1nKBf/mW4z6CbvT3JJn 72PLWiz6TKXKs6mycosYnyCQNP+rhZDEuf4yYOQxE3MLeahoyp3onCziXxwV1KAPLtgn nDhCBi1ZCYIGXgkEXG9D7A54QI6dmLiP/zNdcouYNGJCjLNEkV8y29dOrqLd2fihxt4E MTCmLyjVrpYH+F1/poKWpzY4d2cP6yRK4XWIFD+vbnhHsgAH3gol9r7v2KyM1D4dN9T2 kk4w== 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:date:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=psjVW0khUjjd25PtwUMCIMd8qmRSJTiZob18zG3yr9I=; b=T8/mXQKxbb39Q83s0/DJEX1QE48WjYVKbX7ngoM+hG6DwjH55MN9cXaeuJiOsHn+MN KHEQyQlTYLysk3Zde3B0Z+bFPpFu+f3HgzJmtrPP25G0m6aqYeL68TCP2KwQTK5CXiLy hh72jUwbTFi2o1yn6Hb8IWO9nHRaE+1zxxW3jtyoSEQ+cyxT/F6BsP4awqZjqF16rv8Y ELZZrmOpqo4/kylK1/RQbHuSzd9r0fCTdk5sPtlzRT7kWYLf4sJsFmJLvFeCJZUMcZYp ecJX/I4O7clEFC+ghS2ReCeIKm+7F4722eSDNRG5EcciY3YLkqQmo+sZfupir4obBhyV 46Ig== X-Gm-Message-State: AOAM533RC7XdsQoKr+h4iHsWE+LPAR0J/7Twd61NEHffniciW78Esz93 cB9h6mtF4suQLLfDAuPj2upra3IblUA= X-Google-Smtp-Source: ABdhPJxkysJFzELJbfr3SPmZeGf5D8hKs+k1vHHiDur/HggBUZltZtAgx7tjx/PSyqidD+ksUxYhQQ== X-Received: by 2002:a92:1bd6:: with SMTP id f83mr8560142ill.274.1602214386845; Thu, 08 Oct 2020 20:33:06 -0700 (PDT) Received: from pavlo-debian ([2601:449:c300:22f5:3d3b:da1f:d378:df44]) by smtp.gmail.com with ESMTPSA id s77sm3852574ilk.8.2020.10.08.20.33.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Oct 2020 20:33:06 -0700 (PDT) Message-ID: <9109e992e899b2ed39b070cd12ecdbcdf435fbb6.camel@gmail.com> Subject: Re: libpq CREATE DATABASE operation from multiple treads From: p.sun.fun@gmail.com To: "pgsql-sql@lists.postgresql.org" Date: Thu, 08 Oct 2020 22:33:04 -0500 In-Reply-To: <2631053.1602190588@sss.pgh.pa.us> 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> 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 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.