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 1jo9Sl-0004Ri-9I for pgsql-general@arkaria.postgresql.org; Wed, 24 Jun 2020 17:45:31 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jo9Sk-00034W-3H for pgsql-general@arkaria.postgresql.org; Wed, 24 Jun 2020 17:45:30 +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 1jo9Sj-00034P-QC for pgsql-general@lists.postgresql.org; Wed, 24 Jun 2020 17:45:29 +0000 Received: from mail-qk1-x731.google.com ([2607:f8b0:4864:20::731]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jo9Sf-0000hl-V0 for pgsql-general@lists.postgresql.org; Wed, 24 Jun 2020 17:45:29 +0000 Received: by mail-qk1-x731.google.com with SMTP id l6so2641231qkc.6 for ; Wed, 24 Jun 2020 10:45:25 -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 :content-transfer-encoding:message-id:references:to; bh=mrKsgY4eyOypiyndAD1cpXDEp8r//KPSN2tbHGQ2sDc=; b=E/iyZxU4J6JH4NKyWacEbhXW21xxLdx5PBx9Xy+oJJg26O97Ux1AzK8PIQQjiKxvZ2 ag4pi1oTKtD257U7XWFnXtr9j4uSotZUMCavO/1uWiH/yxB5qAGuff+xogW2SlsuUaFz 9zv1HMsMRFAXgPSxHmDre7twgsodXrsKYHXIanstAIg5jGENVGVK+KE6Cma43eQUOrpC z0OA7VmcVhikDXSbyNXtgofQ1gCyAcRAuKYsAQgy5twFfPIVB6h1kmfOfYLsYdE5HrmK RftckS4mCK+tz/yd81PLLWe1VwdzqFOQsAuZd/LytlvJ+mWBXRQ/S/xzswKjgqYA9rIW s/yw== 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 :content-transfer-encoding:message-id:references:to; bh=mrKsgY4eyOypiyndAD1cpXDEp8r//KPSN2tbHGQ2sDc=; b=BZHnm3Uv6xiNGhLHS7qubtVnNGsBYnWXmIqNYT4ZEx66AhtpghKv6FZnnSqrlgig/Y nOQWFFcT8dzSmMx3gwe377tWK3bUD9BrFFY3lJEE9z5248SEi3s3I8ciz7xrwGJzMbnw LenH4YOt7rk1G1PSVLnLX7xA7AOx0GKWmyW1uZYDgCxdootA3x/KxMyfKlpAp72QpWwO 7+SbISZFSKs0IzR0jhxiCKGH16swR5rUWR4Qf0poSTpQmX5narSgCcM8lOZWKcHNDeJ1 2ZTF61Sni7j88JwEkZHBEfVOT+p+P+d0aPmKrG/xDo0s/rxK7pNsJcALa7jOM4fYeVon 4bEw== X-Gm-Message-State: AOAM531GKvXplPeyXTN7Z5RZzyH2pnyMZHATnKPzoyMdFli+54pDKDLA 3yHpHB93rUh3WA5wsnhntMpSsGlR X-Google-Smtp-Source: ABdhPJxo2W1UNepu4lcZ8aOxbqtlPoRGZXwIllEGOnodR+q4/80lI/N/aIxUXpdatdUriDezTnzZHA== X-Received: by 2002:a05:620a:24b:: with SMTP id q11mr26604543qkn.277.1593020723367; Wed, 24 Jun 2020 10:45:23 -0700 (PDT) Received: from [192.168.1.4] (pints.com. [206.248.184.17]) by smtp.gmail.com with ESMTPSA id u7sm3709938qku.119.2020.06.24.10.45.22 for (version=TLS1 cipher=ECDHE-ECDSA-AES128-SHA bits=128/128); Wed, 24 Jun 2020 10:45:22 -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: <87366lpbno.fsf@gmail.com> Date: Wed, 24 Jun 2020 13:45:21 -0400 Content-Transfer-Encoding: quoted-printable Message-Id: References: <87366lpbno.fsf@gmail.com> To: pgsql-general@lists.postgresql.org X-Mailer: Apple Mail (2.3124) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk > On Jun 23, 2020, at 8:09 PM, Tim Cross wrote: >=20 > Sounds like your web app may not be closing connections once it has > finished with them? The fact your seeing idle connections would seem = to > support this. I would be verifying there isn't a code path in your > client application which is failing to close a connection correctly. = Seeing > connections go up and down in the gem may not be telling you the full = story - could > be that your client connection objects are being destroyed in your = app, > but are not closing the connection correctly so PG is unaware the = client > has finished.=20 Hi Tim. I can=E2=80=99t speak for the gem. I=E2=80=99m assuming its = garbage collection is working. But yes, it does look that way. I found = someone else who was having similar issues as myself: = https://stackoverflow.com/questions/60843123/djangopostgres-fatal-sorry-to= o-many-clients-already I=E2=80=99m also seeing the connection count rise overnight from = crontabs. =20 For some clarity, the gem is Sequel, which is on top of the PG gem = (Ruby). I=E2=80=99ve spoken to the Sequel author and he says everything = is fine. I have some evidence it=E2=80=99s a connection issue and the = gem is doing its job, as I=E2=80=99m seeing it=E2=80=99s happening = elsewhere with crontabs and other clients. =20 > Typically, due to the overhead of making a connection, you don't want > your client app/web app to create a new connection for every query. > Instead, you would use some type of connection pool. Many development > languages support some form of pooling as part of their db connection > library (don't know about Ruby, but JS, Python, PHP, Java, Perl all = do) > and there are external 3rd party solutions like pgbouncer which sit > between your client and the database and work a bit like a connection > broker which will manage a pool of connections. That=E2=80=99s why I=E2=80=99m thinking installing a connection pooler = would solve all of this. pgbouncer is what I=E2=80=99m looking at now.=20= > =46rom the description of what your doing, I would first look to see = what > level of connection pooling your development language supports. This > will likely be easier to configure and use than setting up a whole > additional bit of infrastructure which is probably far more powerful > than you need. I will do that. This is all new. =20 > I would also go through your code and make sure that every time you > create a database connection, there is some code which is closing that > connection once your finished with it. This is a frequent source of > problems, especially during development when your code might throw an > error and the code you have to disconnect does not get executed or you > simply forget to issue a disconnect when your finished.=20 The issue here is that it=E2=80=99s all in the gem. The gem is actually = an ORM, built on top of the PG gem. So all the database connection = stuff is inside there. It=E2=80=99s so abstracted that I don=E2=80=99t = know when the actual calls are made. It=E2=80=99s a DSL so the workings = aren=E2=80=99t evident when making queries. It was suggested I install = a logger to see what and when queries are actually made. =20 > A connection pool can help in tracking down such issues as well. Most > pooling solutions will allow you to set a max pool size. In addition = to > enabling you to 'reserve' a set number of connections for a client, = you > will know which client seems to be running out of connections, helping > to identify the culprit.=20 That SO link above suggests I=E2=80=99m not alone. So installing a = connection pooler seems the right thing to do. Good to know about the = reservations. That is better feedback. Cheers, Bee