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 1kQctr-0001ZM-OM for pgsql-sql@arkaria.postgresql.org; Thu, 08 Oct 2020 20:52:31 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kQctq-00084m-Md for pgsql-sql@arkaria.postgresql.org; Thu, 08 Oct 2020 20:52:30 +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 1kQctq-00084e-EF for pgsql-sql@lists.postgresql.org; Thu, 08 Oct 2020 20:52:30 +0000 Received: from mail-pg1-x542.google.com ([2607:f8b0:4864:20::542]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kQcto-0008Ui-H4 for pgsql-sql@lists.postgresql.org; Thu, 08 Oct 2020 20:52:29 +0000 Received: by mail-pg1-x542.google.com with SMTP id b193so4451976pga.6 for ; Thu, 08 Oct 2020 13:52:28 -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=HGpeo+u3bEa0mjp47siuTRKZL+rymCsZZYO0kWIAptg=; b=POKfEROWCpDlaw3yMaMyMCSZM4Y3TbBMkR8XqYNzXLfjUVZe6oz445CT3BomDJDvEF m3yE25yq3LtEaxPrBbAnRooz9gM7Qk0ltaohaHuWVsa1avCVhENlwrnZ3aWVl3JibooB NYFBaImUtX5GxPADjVL3wYb7V/fuVmWdv7qOJ+yQq8qTQiwwIdLzSsoZgML1c1mQrKDh DoJZXNA1pz6O7xYO41v1UZKBMipxGnDhi0R5Z5s1H2kyGwbOB4kdwu+MSk/uuqRIC7vE fbjeAfnNp5mR2ZsudJf4Kq6HlL1jT6K9ON4FF/QpxpysQLljwqcfPqSqWKG4IoO4/GV8 muKg== 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=HGpeo+u3bEa0mjp47siuTRKZL+rymCsZZYO0kWIAptg=; b=Bs+/Jg/ORV4AmIt397OqEzXSaO35R00DI2fvwMXLJ9L0Zi/C/+yjcE3A6VGAw/ydgm TiWPmrGqNFHPik8YFbk9KvA6iFTNRMI8oLuHAKfIkXgV1YnuuD+HB+st/MNWbp+vbyjc HrwdLOoJMyZ34lzb9rfG+jLPbjxTdggrot6Az7xOdvcH3bAKA/jlm/0qxuJJ7a3rqqhn DAXaMGU3Ia3/x28ysHnR+l1TlOPHX6/xPVWi3wKlMZ5AsYQoHq38LBMm32ipCs9QidmQ fb2SmFY3aT8+ZeQ97FGutWF+HRnVyTRJF2ORFoJHMSu97nvlnlyyzbATAzRtmyWZNIGx Wnfw== X-Gm-Message-State: AOAM532COx4O3tbPefUF7e5kNBCglPA4sfQEgRU4oZqj22Ou4hQh170Q HP5/b1HT4E7IjWgF1mYo1dZthmQb2MA= X-Google-Smtp-Source: ABdhPJxLKTxHd3JYchGbLNkpnXjf9bBMlSHKi8y+8yK6Xyttty9QMgZdDP8z6ZGKnDdmML+WDSvmyQ== X-Received: by 2002:a17:90a:4f0f:: with SMTP id p15mr803882pjh.10.1602190347192; Thu, 08 Oct 2020 13:52:27 -0700 (PDT) Received: from pavlo-debian ([204.147.87.6]) by smtp.gmail.com with ESMTPSA id f18sm8372326pfe.153.2020.10.08.13.52.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Oct 2020 13:52:26 -0700 (PDT) Message-ID: 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 15:52:22 -0500 In-Reply-To: <2624889.1602189369@sss.pgh.pa.us> References: <390804abe88e4e9da9049f6e05c841783acaca47.camel@gmail.com> <124ce8dff8402159f20dec1bc1ac27e26ee39c23.camel@gmail.com> <2624889.1602189369@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: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Thu, 2020-10-08 at 16:36 -0400, Tom Lane wrote: > p.sun.fun@gmail.com writes: > > Indeed, this is a FATAL_ERROR. From two threads I got: > > // Thread #1 > > FATAL_ERROR: ERROR: source database "template1" is being accessed > > by > > other users > > DETAIL: There is 1 other session using the database. > > You'd be better off to connect to some other database than template1; What would be the best strategy to create a database from user standpoint of view? If we have an API to create a database on a server. The user doesn't know about database(s) yet. The possible option would be: to check the result status and if is not COMMAND_OK, probably connection should be dropped and established again. May be not so elegant but at least safe and stable. > not only just for this purpose, but in general. If you are issuing > random commands in template1, there's a risk of modifying that > database > unexpectedly and thereby changing the contents of databases created > in future. > > regards, tom lane