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 1kQc9U-00083C-Eo for pgsql-sql@arkaria.postgresql.org; Thu, 08 Oct 2020 20:04:36 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kQc9T-0007RZ-Bw for pgsql-sql@arkaria.postgresql.org; Thu, 08 Oct 2020 20:04:35 +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 1kQc9T-0007RS-3W for pgsql-sql@lists.postgresql.org; Thu, 08 Oct 2020 20:04:35 +0000 Received: from mail-pl1-x62a.google.com ([2607:f8b0:4864:20::62a]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kQc9Q-00010A-2S for pgsql-sql@lists.postgresql.org; Thu, 08 Oct 2020 20:04:34 +0000 Received: by mail-pl1-x62a.google.com with SMTP id bb1so3304839plb.2 for ; Thu, 08 Oct 2020 13:04:31 -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=EKDKQVvXrzVuw1I+PdOTED8FXc3MOJCst4jI2OmI5gA=; b=kDt1XMOz4moRNChSG/385GqiRwfDxOPmE1Or0iZrf8uUUqjfFW6xGk6RpvTSAzvNlT fJGvTfyoMdooomVWs9zDtTKoukJwzQszzObjpSue0B+/+FnqSFQnAMS/mkqMy+gpjmmn lNEeTJ9EFiA9X+2pte5BTuBidQXVjs1BnmlVJbdGpsY/Xb9BDL2v8s2WkAy6FhSHSIZi PmpPzXJ8paSXfdE5SvdlZLcmeUqAJLeSywYnGh5Grh9h5otEklHtf51CI+2XY26lqbfj bclmpXJ8OQ/5+BnInQ+Zs85PaDT1GYJnE5p14d1cfgUQITbj8oboukjimftGYQOEMK3F 0fYw== 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=EKDKQVvXrzVuw1I+PdOTED8FXc3MOJCst4jI2OmI5gA=; b=DBVc+diWWyizLHes7L7OhMUyGkFbzqEwWGpdo0xh9JVGNGLodkBJzkmsi5cnQlenS/ DOLClLMgPYpplCzdjE8MHuK+ahvBmXURhnWM8G3prpfAHvoGKxHloyi1PSOl7oJVn0Ym L7ho3Yl3D575MHeFLacaU4RbEFlCUbHsGwqE7UP6RoRwVBFOXzf5r32ujdsqFRmYUMPT ABHmaimMbJJzBLpQ1C1fkUozPT3Fgx/cPJDo12uvAZTGsH32ik6crFTjP1mp0E02RvX5 eiIo39yAtvdwcq3Q6cmd2XShABK7HKjgfNjo0IEGKI2OPOzH+HePaJygMscT1fGuvUqw z4gw== X-Gm-Message-State: AOAM530dcpYJxc00AHdvVh/SBcnnJp8v2YscKXR2urkNbElHdvXjSBQR KVLGK6CKivHlJBgz8V7+0sUo3DJuu6M= X-Google-Smtp-Source: ABdhPJx/Xi3wkqQhPhDQCkPZ+CwcJn4JCkD96zgaAMblaCt46hOEWYw8Sui6iZqPFmVwgkpPf6Arqw== X-Received: by 2002:a17:902:a5ca:b029:d3:7d11:2a80 with SMTP id t10-20020a170902a5cab02900d37d112a80mr8694718plq.58.1602187469925; Thu, 08 Oct 2020 13:04:29 -0700 (PDT) Received: from pavlo-debian ([204.147.87.6]) by smtp.gmail.com with ESMTPSA id p3sm8054414pjj.38.2020.10.08.13.04.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Oct 2020 13:04:29 -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:04:24 -0500 In-Reply-To: <2623291.1602187023@sss.pgh.pa.us> References: <390804abe88e4e9da9049f6e05c841783acaca47.camel@gmail.com> <2623291.1602187023@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 Hi Tom. Thanks for the quick response. In the function that I execute in each thread, I create a new PGconn at the beginning. I expect that every function caller (thread) should use a unique PGconn. I would not expect that PGconn can be shared between threads. The documentation explicitly says that. On Thu, 2020-10-08 at 15:57 -0400, Tom Lane wrote: > 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