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 1jnrHy-00014n-Td for pgsql-general@arkaria.postgresql.org; Tue, 23 Jun 2020 22:21:10 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jnrHx-0000OX-Py for pgsql-general@arkaria.postgresql.org; Tue, 23 Jun 2020 22:21:09 +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 1jnrHx-0000OO-FH for pgsql-general@lists.postgresql.org; Tue, 23 Jun 2020 22:21:09 +0000 Received: from mail-qt1-x829.google.com ([2607:f8b0:4864:20::829]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jnrHv-0007Q8-Du for pgsql-general@postgresql.org; Tue, 23 Jun 2020 22:21:09 +0000 Received: by mail-qt1-x829.google.com with SMTP id g13so148206qtv.8 for ; Tue, 23 Jun 2020 15:21:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=bIQ0jY1dqoo85O5nsNOQ7mQRIkTdSFejRlukxq43hTU=; b=ZQvgJDneagEJn62oX8XwE8j8e91LOrH6yufRA7TZAecJzu50ZwGIJ1Qx7Unj+DSWUY 3dLYhtVL7fwt7OyZYkSHRxkO8Cwy5+KOD1wW+WTqTU9qAMAdjdduLPSCxHZZw8JoRKAb GDORyd4PEv883oQCdugaDn2fFrkx7quFDPCJQErQciRQAndkNrYg4lGn0OxXF/RrxVBb a6vNvAQ8rv5Tt7xCdAfuBe8ab5/FZNILbDd/JPHOdmUYO3ImCFAnTQJFaABKrG3Ei67U 7LQlD8RDQ7/tFrymy3grtk8cBSk8fmDhpcVafgwscUMyECoabV0d6FPTZ08CtxCqSRij lTDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=bIQ0jY1dqoo85O5nsNOQ7mQRIkTdSFejRlukxq43hTU=; b=qQKdicbw6gzPwXEapzWAFpFRsh0qa8klBY/kI9mSYQK18sFlZXDFcXtPA1otlAKfPu myIyBKPT41cNLIs0yYSlIx7NGzE77mbWAiqZPorTfGbpzK0EcL1VNRv3c+QHj6APwkyE /XsYBj/4HboU6Znzq00MGc3kY2X0nfwJyQhiBmPbiIWemCCCtsdluRxOHvlyn6ACsm+9 jEZ/byFj7eC97A8gwdP+LqwhR4eGkTOct9tBxJ38AcaSDZHM9UYeTCa6XUQKVCxWxdpD 5maN9Zy3w3CgetuQcPKvgPuk7aV3mtzOEb1W/E5d2Dvs4DuUO6Rr6oyh+RJ/Dr5slwuJ 1/1w== X-Gm-Message-State: AOAM532zTmOA6LXykCEVYg4jhwmdQU1Pk4+pLLw6JyshWmqgG2aXSIdN EUbhsQb7S6faH4hUJqSF/kg= X-Google-Smtp-Source: ABdhPJxlH+4zVsoCRuCLV0OigZR9h0KpUctuhrPut9gDx/nF/eBtqyljlGt+r91Y17xwgZDiUhowig== X-Received: by 2002:ac8:1ac4:: with SMTP id h4mr10670965qtk.249.1592950865578; Tue, 23 Jun 2020 15:21:05 -0700 (PDT) Received: from [192.168.1.4] (pints.com. [206.248.184.17]) by smtp.gmail.com with ESMTPSA id f4sm875161qtv.59.2020.06.23.15.21.04 (version=TLS1 cipher=ECDHE-ECDSA-AES128-SHA bits=128/128); Tue, 23 Jun 2020 15:21:05 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 9.3 \(3124\)) Subject: Re: Persistent Connections From: "Bee.Lists" In-Reply-To: Date: Tue, 23 Jun 2020 18:21:04 -0400 Cc: Submit Postgresql General Content-Transfer-Encoding: quoted-printable Message-Id: <92839D36-01AB-4C1D-BDF5-1FB2919785C6@gmail.com> References: To: Michael Lewis X-Mailer: Apple Mail (2.3124) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk >=20 > On Jun 23, 2020, at 4:51 PM, Michael Lewis wrote: >=20 > Do you see anything in pg_stat_activity that stays idle for a while = and then *does* disappear on its own? Perhaps some types of connections = are doing client side/application stuff before telling the DB to close = the connection. I=E2=80=99m finding those queries sticking around. These queries are = very simple. Last login type of stuff. =20 > Idle means the query finished and that was the last query run. It = isn't active or waiting on another process, that connection is open by = idle. OK. The page that I load up is a dashboard and has a handful of = queries. =46rom the looks of it, it looks like they=E2=80=99re still = working, but idle. But you=E2=80=99re saying they=E2=80=99re just open = connections? Why would they remain open? I check for numbackends this way: pgconns=3D'psql -c "select datid, datname, numbackends, xact_commit, = stats_reset from pg_stat_database where datname in = ('\=E2=80=99'mydbname'\'');=E2=80=9D' > It sounds like a good time to set one up. OK, some further questions: Who do the connections belong to? Not the client, not the server = (apparently). Is there one that=E2=80=99s independent and behaves as = the front end of connection management? > I would increase the limit directly, or with a pooler and research = which connections are behaving, and which are taking too long to close = or not closing at all. You could set up a process to snapshot = pg_stat_activity every minute or 5 and trace which pids are terminating = properly, and/or make logging very verbose. How do I go about researching connection behaviour? I guess a pooler = should be investigated first. I have that pgconns already logging, so = I=E2=80=99ll do one for pg_stat_activity. =20 Once I find culprits, what options do I have? Not sure why new = connections are made when these idle past connections seem valid and = usable. =20 There is agreement that ORMs shouldn=E2=80=99t be managing a connection = pool, and this doesn=E2=80=99t achieve to do that. I=E2=80=99ll be = looking into a pooler. This client (the gem is Sequel, btw) uses what = it assumes are valid connections, but that=E2=80=99s where it fails as = the database apparently disconnects prematurely. The gem has a = procedure to check how long since the last pool was investigated for = legit connections, but I think that=E2=80=99s irrelevant. It=E2=80=99s = finding what it=E2=80=99s told are legit connections, which are not. = It=E2=80=99s been lied to. =20 Cheers, Bee=