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 1kQcxm-0001jB-Mc for pgsql-sql@arkaria.postgresql.org; Thu, 08 Oct 2020 20:56:34 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kQcxj-0003Zq-NZ for pgsql-sql@arkaria.postgresql.org; Thu, 08 Oct 2020 20:56:31 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kQcxj-0003Zj-Hp for pgsql-sql@lists.postgresql.org; Thu, 08 Oct 2020 20:56:31 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kQcxh-0008WH-FA for pgsql-sql@lists.postgresql.org; Thu, 08 Oct 2020 20:56:30 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 098KuSrF2631054; Thu, 8 Oct 2020 16:56:28 -0400 From: Tom Lane To: Rob Sargent cc: p.sun.fun@gmail.com, "pgsql-sql@lists.postgresql.org" Subject: Re: libpq CREATE DATABASE operation from multiple treads In-reply-to: <23F4DE61-F81D-4740-A227-74B5EB41304C@gmail.com> 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> Comments: In-reply-to Rob Sargent message dated "Thu, 08 Oct 2020 14:50:31 -0600" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <2631052.1602190588.1@sss.pgh.pa.us> Content-Transfer-Encoding: 8bit Date: Thu, 08 Oct 2020 16:56:28 -0400 Message-ID: <2631053.1602190588@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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