Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gNJNQ-00064K-0w for pgsql-general@arkaria.postgresql.org; Thu, 15 Nov 2018 15:16:16 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gNJNN-0000Xo-VC for pgsql-general@arkaria.postgresql.org; Thu, 15 Nov 2018 15:16:13 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gNJNN-0000XV-Mz for pgsql-general@lists.postgresql.org; Thu, 15 Nov 2018 15:16:13 +0000 Received: from out5-smtp.messagingengine.com ([66.111.4.29]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gNJNC-0002Mb-1q for pgsql-general@postgresql.org; Thu, 15 Nov 2018 15:16:13 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 0C7BA220AD; Thu, 15 Nov 2018 10:16:00 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Thu, 15 Nov 2018 10:16:00 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:references:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm1; bh=T 1AFqyhJiuaNAYbisMemu4/3+ku2YUXco2qJOblbExY=; b=hxrT2isxnLNBiSSyL ucBflGm4lVPfF5XRXqIoJyoq9M0ve6WcEUonz6hbZTFyVcatlX86we84t27KN3mM VaARbJZkB/QriehhO+CJ2G3sK3oJjHgwx+eXsN6GXlkK4dfakYTEvG1ybkbVv8of Dxy4lZhE5iW/BDGA4V2dGSJopMU59h7U0GXtmf8WZklmVHIV+AdBvKbE2siFyz2e dBru9fzdd10ohXSAtepxnc1Hprq8zJuVP/TpCJOow9NueQkyPRVyeEhL87X4X1CV w1BSEOJgYje5zZlOxQW7iPUsSiYgoTxXp2aJKw6xEOjW27h4Us2l/HZUPaS5IVCr Dv/RA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; bh=T1AFqyhJiuaNAYbisMemu4/3+ku2YUXco2qJOblbE xY=; b=NkX9Mfr82ah9RwMpajgZwFGNTdw9EntSu4glSiM8HhggLlzzmKOfGIqcl Gzn6MUxDAgbdRkbp2TM2RHgTquC3tFE5Impax+cf8dU1qHtEko0EQhXEvp8sQa9y nBkKcdqzjgUFmXG9Lxxe7ZJez0Ao1yE+3RcLIK00ME2339/TvPJlYbqDK2sgxbst /9KN3nk+2c4QqowslSWf0NuPGcWb+FY1zPawlZw6M2KpUkdtUEwJH3TYjyUYjFWq DRTZ8jKwBDVeaiUCfnvMnePu4Vuq6ydv48F5sWVnjr+XxrmSdpOckfSsxJ39ypAV Qef3lO7kT9oNnfgHGmK7+vjXw19GQ== X-ME-Sender: X-ME-Proxy: Received: from [192.168.1.3] (unknown [71.212.134.3]) by mail.messagingengine.com (Postfix) with ESMTPA id 078D2E469E; Thu, 15 Nov 2018 10:15:58 -0500 (EST) Subject: Re: db-connections (application architecture) To: Mark Moellering , Postgres General References: From: Adrian Klaver Message-ID: Date: Thu, 15 Nov 2018 07:15:56 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 11/15/18 7:09 AM, Mark Moellering wrote: > So, I am working on some system designs for a web application, and I > wonder if there is any definitive answer on how to best connect to a > postgres database. > > I could have it so that each time a query, or set of queries, for a > particular request, needs to be run, a new connection is opened, queries > are run, and then connection is closed / dropped. > > OR, I could create a persistent connection that will remain open as long > as a user is logged in and then any queries are run against the open > connection. > > I can see how, for only a few (hundreds to thousands) of users, the > latter might make more sense but if I need to scale up to millions, I > might not want all of those connections open. > > Any idea of how much time / overhead is added by opening and closing a > connection everytime? > > Any and all information is welcome. Connection pooling? In no particular order: https://pgbouncer.github.io/ http://www.pgpool.net/mediawiki/index.php/Main_Page > > Thanks in advance > > -- Mark M -- Adrian Klaver adrian.klaver@aklaver.com