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 1mSMu9-0007au-9G for pgsql-general@arkaria.postgresql.org; Mon, 20 Sep 2021 17:16:33 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mSMu7-0004wV-Ix for pgsql-general@arkaria.postgresql.org; Mon, 20 Sep 2021 17:16:31 +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 1mSMu7-0004wN-AI for pgsql-general@lists.postgresql.org; Mon, 20 Sep 2021 17:16:31 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mSMtz-00034F-Px for pgsql-general@postgresql.org; Mon, 20 Sep 2021 17:16: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 18KHGKFo1817784; Mon, 20 Sep 2021 13:16:20 -0400 From: Tom Lane To: Abhay Gupta cc: "pgsql-general@postgresql.org" Subject: Re: Azure Postgresql High connection establishment time In-reply-to: References: Comments: In-reply-to Abhay Gupta message dated "Mon, 20 Sep 2021 08:58:21 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1817782.1632158180.1@sss.pgh.pa.us> Date: Mon, 20 Sep 2021 13:16:20 -0400 Message-ID: <1817783.1632158180@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Abhay Gupta writes: > we are noticing the connection establishment is taking around 200-300 ms. Not sure whether that's out of line or not, since you've provided no background data (e.g. is the connection across a network link? how busy is the server? what encryption and authentication are you using?). However ... > The connection establishment time is very high as our functions are written > to be very high performance. ... if you are looking for good performance, the last thing you should be doing is making a connection per query. Postgres backend processes are pretty heavyweight things. Even after the connection is complete, there's overhead involved in populating caches and so forth. You'd be well-served to use a connection pooler and/or try to keep an application's connection open once made. regards, tom lane