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 1kQc2G-0007kB-SU for pgsql-sql@arkaria.postgresql.org; Thu, 08 Oct 2020 19:57:08 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kQc2F-00021u-F3 for pgsql-sql@arkaria.postgresql.org; Thu, 08 Oct 2020 19:57:07 +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 1kQc2F-00021n-91 for pgsql-sql@lists.postgresql.org; Thu, 08 Oct 2020 19:57:07 +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 1kQc2D-00084y-Bl for pgsql-sql@lists.postgresql.org; Thu, 08 Oct 2020 19:57:06 +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 098Jv3JR2623292; Thu, 8 Oct 2020 15:57:03 -0400 From: Tom Lane To: p.sun.fun@gmail.com cc: pgsql-sql@lists.postgresql.org Subject: Re: libpq CREATE DATABASE operation from multiple treads In-reply-to: <390804abe88e4e9da9049f6e05c841783acaca47.camel@gmail.com> References: <390804abe88e4e9da9049f6e05c841783acaca47.camel@gmail.com> Comments: In-reply-to p.sun.fun@gmail.com message dated "Thu, 08 Oct 2020 14:46:24 -0500" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2623290.1602187023.1@sss.pgh.pa.us> Date: Thu, 08 Oct 2020 15:57:03 -0400 Message-ID: <2623291.1602187023@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk p.sun.fun@gmail.com writes: > I run this function using only one thread and everything works great. > If I use two threads, the PQresultStatus(res) != PGRES_COMMAND_OK. Are you trying to use the same PGconn from multiple threads? That will not work --- at least not without interlocks that libpq on its own does not provide. > Can the server handle CREATE DATABASE requests in parallel? Sure. But they have to be issued over different connections. Any given connection can only do one thing at a time. regards, tom lane