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 1i1HdB-0003rs-IG for pgsql-jdbc@arkaria.postgresql.org; Fri, 23 Aug 2019 22:02:01 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1i1Hd8-0003aK-VN for pgsql-jdbc@arkaria.postgresql.org; Fri, 23 Aug 2019 22:01:58 +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 1i1Hd8-0003a8-L7 for pgsql-jdbc@lists.postgresql.org; Fri, 23 Aug 2019 22:01:58 +0000 Received: from mail-pf1-x441.google.com ([2607:f8b0:4864:20::441]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i1Hd5-0003gU-ND for pgsql-jdbc@lists.postgresql.org; Fri, 23 Aug 2019 22:01:58 +0000 Received: by mail-pf1-x441.google.com with SMTP id w2so7364043pfi.3 for ; Fri, 23 Aug 2019 15:01:55 -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=hxbCTLpth1on7g22Cl1bVl0SqbVbX5/ZCGhxYTzbiSc=; b=h0qP6LqyLesW4TGhxEH8FwjYEzsMEVqkULF4+jjw5/V1TolFkTSQ7w5+npDYw7xtlW Z3E4l/M+XKg9xz/FZzzgeXYqMNNMCiviyynPReAgdiRFuaW2qmLLlG4xOdKedOO/fcWJ fyB+s+xxr3x326YpO5rQABnSxxti1PkcxjfnXAXD6gRmTXkK6EM9MEfopfigcEG3EVUU jZwSlyu4ncuaOXO0JwkqqBDsl6shTXgjBvHCw8c5wf3w5CG2vIqkJtz2VVLcE2vjSxzX oLo3pKfLYiq4BJMcuIv/kLeMZZBoMkS5iTKsF0pyZdqaDa1ToCBZh8/e5b0uc/iCr0Cs FNbQ== 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=hxbCTLpth1on7g22Cl1bVl0SqbVbX5/ZCGhxYTzbiSc=; b=U1Q7yCPJIOsFMMFeKrj18fzbWmXlpHkslxJuXUtjfqh3GSEfNMX+uJRCmAHce/Fxxi Olo+Q7dICvSa7dPlEfXLZE5wMJCDDqm1Czs7jSAuMnwOs2CV66JsiIophDtySaIOBeRH 0wxLDzmmoJJE+Ibt+BEW4H2z8G45YRcyj3A+BTZiPfjCrCA/3qMOC+ZwTSjT8N2UxyME dvtOIN2JvDG/I9QdugRLizrn7kpYnCsX44Fmr2s8HVmOW6E+8lHsMC71Rcf1kBIqmiaL Yh3LLTmWbiw6bKAqL+vpyjkDcGhRqb3PIuoLl1VuuzfNbPZsRFou+umzlxtjml3iLVsa Tw8A== X-Gm-Message-State: APjAAAU+lobcQysRPAEPii465grHRrCy0qW+KIds+OOxJDDv6OmARPM1 NNl1lESvwMWU7h0A+ypEfcA= X-Google-Smtp-Source: APXvYqyDACdhzxlVs9WVHPWcLoh7hFSzIZC3SeyJpThXGgMufiQ26k5V/PR9kHd85vqz4CLLa9zbRg== X-Received: by 2002:a17:90a:3266:: with SMTP id k93mr7560092pjb.46.1566597240795; Fri, 23 Aug 2019 14:54:00 -0700 (PDT) Received: from [10.7.105.51] ([65.200.105.250]) by smtp.gmail.com with ESMTPSA id a11sm3090829pju.2.2019.08.23.14.53.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 23 Aug 2019 14:54:00 -0700 (PDT) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.11\)) Subject: Re: Recommendations for PGBouncer interacting with HikariCP From: Steven Schlansker In-Reply-To: Date: Fri, 23 Aug 2019 14:53:59 -0700 Cc: Joseph Hammerman , pgsql-jdbc@lists.postgresql.org Content-Transfer-Encoding: quoted-printable Message-Id: <4CA0AE1D-0C0B-4CEB-9CF8-20B61761ED80@gmail.com> References: To: Dave Cramer X-Mailer: Apple Mail (2.3445.104.11) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk > On Aug 23, 2019, at 1:39 PM, Dave Cramer wrote: >=20 > On Wed, 21 Aug 2019 at 21:03, Joseph Hammerman = wrote: > Hi pgsql-jdbc email distribution list, >=20 > We have recently added PGBouncer into our stack. We have done this in = part, to protect the database. Our Java userbase is accustomed to using = HikariCP / Hibernate for connection pooling. They would prefer to = continue to use the connection pooler, in order to not have GC churn on = connection spin up and tear down (in addition to additional latency = introduced by having to perform the three-way handshake more often). >=20 >> Is there any published material / does anyone have any knowledge of = how these tools should interact or not interact? >=20 > JDBC should work fine with pgbouncer.=20 Most things do, although there are some caveats. For example if you = have anything attached to your server session *outside* of a txn (say, server-side prepared statements or session vars) and you configure your pgbouncer for transaction pooling, you can end up = creating some extremely difficult to understand behaviors. = https://pgbouncer.github.io/faq.html#how-to-use-prepared-statements-with-t= ransaction-pooling So you do have to be a little bit careful. > =20 >> HikariCP wants to keep many long running idle_in_transaction = connections open, which saturates the backend connection pool. >=20 > That's strange why is it keeping them in transaction ? One would think = once you closed (returned the connection) it should commit it. My personal experience working with JDBC and HikariCP is that 99.9% of = the time, "idle in transaction" means that some programmer somewhere actually did not close their resource. I did end up finding numerous = bugs, both in my $WORK's code as well as in Java libraries we use, = although to the best of my memory the roots of problems we found were never in either = PgJDBC nor HikariCP. To diagnose these nasty issues, we took a pretty extreme method: on = every checkout from the HikariCP pool, we generate a UUID and print a tagged stack trace to a file. We then set `application_name` to = "app_name-$UUID". When our DBAs found an "idle in txn" connection that we did not know = where it came from, we would immediately have the app and could then look up the stack trace of the last allocation site using the = application_name in pg_stat_activity. =46rom there it was usually straightforward, if painful, to diagnose the = problem: "Oh I opened a Hibernate session and handed it off to a = Reactive actor that threw an exception but it never got handled and so the = Connection was never closed and the whole thing got leaked. Whoops. = But look at how *fast* Reactive is!!!" Hope that gives you some ideas.