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 1gZqD9-00075B-Iv for pgsql-general@arkaria.postgresql.org; Thu, 20 Dec 2018 04:45:27 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gZqD8-0000a1-5Y for pgsql-general@arkaria.postgresql.org; Thu, 20 Dec 2018 04:45:26 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gZqD7-0000Zt-QP for pgsql-general@lists.postgresql.org; Thu, 20 Dec 2018 04:45:25 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gZqD3-0007lW-MO for pgsql-general@lists.postgresql.org; Thu, 20 Dec 2018 04:45:24 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id wBK4jK1a022293; Wed, 19 Dec 2018 23:45:20 -0500 From: Tom Lane To: Joshua White cc: Pavel Stehule , Ron , pgsql-general Subject: Re: Does idle sessions will consume more cpu and ram? If yes,how to control them In-reply-to: References: <20181220012718.GI27104@paquier.xyz> Comments: In-reply-to Joshua White message dated "Thu, 20 Dec 2018 15:01:01 +1100" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <22291.1545281120.1@sss.pgh.pa.us> Content-Transfer-Encoding: 8bit Date: Wed, 19 Dec 2018 23:45:20 -0500 Message-ID: <22292.1545281120@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Joshua White writes: > On Thu, 20 Dec 2018 at 14:35, Pavel Stehule wrote: >> čt 20. 12. 2018 v 2:41 odesílatel Ron napsal: >>> So it's best to kill connections that have been idle for a while? >> sure - one hour idle connection is too old. > I'd also assess closing the connection from the client end once its task is > done - that would reduce the number of idle connections in the first place. IMO, "has it been idle a long time" is the wrong question. The right question is "how likely is it to start doing something useful soon". Certainly, leaving sessions sit doing nothing for a long time isn't helpful. They consume RAM, they have to be accounted for by other sessions, and if you're doing any DDL, they consume CPU time maintaining their own caches in response to catalog changes. But it's also true that starting a new session has a lot of overhead --- so you don't want to kill a session that was just about to start doing some useful work. regards, tom lane