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 1lvR6m-0005cM-NN for pgsql-general@arkaria.postgresql.org; Mon, 21 Jun 2021 21:05:28 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lvR6l-00009w-Mf for pgsql-general@arkaria.postgresql.org; Mon, 21 Jun 2021 21:05:27 +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 1lvR6l-00009o-CX for pgsql-general@lists.postgresql.org; Mon, 21 Jun 2021 21:05:27 +0000 Received: from mail-oi1-x233.google.com ([2607:f8b0:4864:20::233]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1lvR6j-0004ix-CY for pgsql-general@lists.postgresql.org; Mon, 21 Jun 2021 21:05:26 +0000 Received: by mail-oi1-x233.google.com with SMTP id t140so21452630oih.0 for ; Mon, 21 Jun 2021 14:05:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language; bh=2JiJTgHOFFnieXyhqYo/Ffcn2QynNZFzWYdj1ikBlEM=; b=P5ZOcpP/Y9v4Itpbdan/TUsINKnibn41gCseTgTIqw++t9ob8DxV2svXjvXkys9Mwf NtiGnfQX4oCaj8DjeWb8hk7Yh7yAas7/NFQvOHqDiH0OLmPFkzui/5C9YrW9geUP1FS5 tcryTblqSukxpuTttthg2W50qMPWOYJCDTf8UQGmCZO9hMX1tnczI+EnKmLJRUIbpJrE fmiKvshvRJHVQew1R/OVTp406Iq3lfKUVqhDVcDDuMCF453vd/iw4o4Y18Klv4K8eD7q dOyS/qU7OTFwowK5ZwlEudzME23IRqvZzDMZ7bGu9ReejMAB/i8b0flo2/FGMZdaZM5M huDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=2JiJTgHOFFnieXyhqYo/Ffcn2QynNZFzWYdj1ikBlEM=; b=cTKaCaB9Txr0dvoHem9lYkq1x8qu4bFbcSipR2pNW9WF3NQwG8VGlHq1NszjphXHzZ Fa+A+SA+jgRjeR3W9tXg2N7x55SO3DpQCLDqCquYA8eO5vUwtO4yrmd80GAjsvq/vObG LQYLU0jLSNPISJCYnxt3hgWJiRgt1InG1s3kMaNOuFYwaG62nBQSP7ANbakFBPJTnth7 EN+UW67Xa2XqWIH+YTP6Yivq55v1k92bmjH8eFPJGRvz4F57sElDbOC0+iH4CHhDPozV arfLbr61N1xvzryTYUU1S92sQXamuyyi5Xh6RZOIj9Gag0bxa9DrAHPN5vv/fh9fEWNl Gskg== X-Gm-Message-State: AOAM530pKVLl/yLODm3kFtbQNgC6NdDNLqd+3tRWsm6WxfFoPkaWw8QY gPAWb9nBBI7JA6sTuAj+78eVN4cDRABYoQ== X-Google-Smtp-Source: ABdhPJwJIN8iBEvFdKYTkIJNBeWxvm3V8YPRQJ/M9PuughoOedRaSrWLh2RbsgiQ0UIS2q8QQWfHkg== X-Received: by 2002:aca:c492:: with SMTP id u140mr338846oif.20.1624309524316; Mon, 21 Jun 2021 14:05:24 -0700 (PDT) Received: from [192.168.88.10] (ip174-67-141-204.no.no.cox.net. [174.67.141.204]) by smtp.googlemail.com with ESMTPSA id a74sm3807136oib.21.2021.06.21.14.05.23 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 21 Jun 2021 14:05:23 -0700 (PDT) Subject: Re: How to automatically delete idle client connections? To: pgsql-general@lists.postgresql.org References: From: Ron Message-ID: Date: Mon, 21 Jun 2021 16:05:22 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/alternative; boundary="------------CD88E3A728A1ED2B729C3D58" Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------CD88E3A728A1ED2B729C3D58 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit On 6/21/21 5:17 AM, David Rowley wrote: > On Mon, 21 Jun 2021 at 21:59, Yu Watanabe wrote: >> I have tried setting idle_in_transaction_session_timeout , however, this does not delete idle sessions. >> >> Would there be any expiry settings to delete client idle sessions automatically ? > There is idle_session_timeout in PostgreSQL 14, but that's not much > use to you, since a) it's not out yet, and b) you're using 12. > > I guess you could do something like: > > SELECT pg_terminate_backend(pid) FROM pg_stat_Activity where state = > 'idle' and state_change < NOW() - INTERVAL '1 hour'; > > Change '1 hour' to whatever you like and maybe*set up a cron job* to run that. That's what we did. -- Angular momentum makes the world go 'round. --------------CD88E3A728A1ED2B729C3D58 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 7bit On 6/21/21 5:17 AM, David Rowley wrote:
On Mon, 21 Jun 2021 at 21:59, Yu Watanabe <yu.w.tennis@gmail.com> wrote:
I have tried setting  idle_in_transaction_session_timeout   , however, this does not delete idle sessions.

Would there be any expiry settings to delete client idle sessions automatically ?
There is idle_session_timeout in PostgreSQL 14, but that's not much
use to you, since a) it's not out yet, and b) you're using 12.

I guess you could do something like:

SELECT pg_terminate_backend(pid) FROM pg_stat_Activity where state =
'idle' and state_change < NOW() - INTERVAL '1 hour';

Change '1 hour' to whatever you like and maybe set up a cron job to run that.

That's what we did.

--
Angular momentum makes the world go 'round.
--------------CD88E3A728A1ED2B729C3D58--