Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1svbmh-00GNTA-Ul for pgsql-general@arkaria.postgresql.org; Tue, 01 Oct 2024 12:15:20 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1svbmh-00FplE-1d for pgsql-general@arkaria.postgresql.org; Tue, 01 Oct 2024 12:15:19 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1svbmg-00Fpl5-AF for pgsql-general@lists.postgresql.org; Tue, 01 Oct 2024 12:15:18 +0000 Received: from mail-lj1-x236.google.com ([2a00:1450:4864:20::236]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1svbmd-001xHy-KR for pgsql-general@lists.postgresql.org; Tue, 01 Oct 2024 12:15:17 +0000 Received: by mail-lj1-x236.google.com with SMTP id 38308e7fff4ca-2fad6de2590so19714071fa.0 for ; Tue, 01 Oct 2024 05:15:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727784914; x=1728389714; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=ftntgUPKm1jVaJuos55hIPCF3sQ43D/fEPc36q4e9d8=; b=mPnbLt/WVN9wrPCv6jld0Xp9eHIM8M15dRExO0tejTgtkrc6XYzMxAOtDMJkhCMP/K Dt3PqowNqZ61hv37n0W6f2NXS5lBs4PZfZECTyYgyZdkky1Vi8NYtKB6WXs1o7mUDnev gHjPkF+p2eNtUmoNKOgIq6exHuTZMoDcXAE06Gk2RD1ofhrBgWkw8yYR0zamVLn7ARmo IdbCwbeIfoQ/207jeAqqCcBgLijfswwE+1ZKlydo14JlGKgmwZeB1mOCit5sVJKrGOWk 5RKpm0kXdGrjzLa5TseMa3lsyasBlEWkYnsZrDpFz6YiwQ4h1NneuK1L6dGJOc2lRSwK +vnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727784914; x=1728389714; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=ftntgUPKm1jVaJuos55hIPCF3sQ43D/fEPc36q4e9d8=; b=CF22OlVI7lCHGQ7Wu0wt12Ug8ebkyLar47kj0wfcgUnn3fu8i29OlG4htze8BFAZLz xS2bcd/7VhzM11g46JeAOaLAMtVCufcxXnYx7pJ8bkEyuMe/kQ9XvJQLBEhdS9I47Lj3 qmB4TdjbsM0dLn3g9tW9v35LDe7sLuZ9jnmPN81CEjBOFTj73bPui1x+TAQUw4GEC8uJ ksGZHJsAXaAg0aY/IwhCL1BhOGe3jwjynmisxl/2L+QOUCM2nriVluLw/yeBPCjNArhh VwZo5Z7EEzn8Idpi3eODEazi2HwvP4zxZAWUyYup+zDedaBOFGWdb+6M/F7AGZL6Pso2 U9RQ== X-Forwarded-Encrypted: i=1; AJvYcCW2UEX3hRvQT7ntcOGZFrkU0ofm5mSyvPYdJZSMPucqkf/3uoEFJr/ZxcItGDidKEAKhCUHFf6Vrm3OmdnM@lists.postgresql.org X-Gm-Message-State: AOJu0YzupfoE4BIi0c+dpIjBvdMwjbN76eBF4X8F15p0AvUBuysoV/UD MNLFdlBNyypM9MY0UGfnF4x62269P9e30aJI46jAsX+69sEAWz+FSXFqn4gNoQWgzRKSWV2XdeI 7Ga0Fdyj3YggmWOEhis5E9tfP1Ew= X-Google-Smtp-Source: AGHT+IEiNQAKmP7dlI/h2KBkG0pm7/nleZ3et0rLUPoPF/2j81rh4KRfl0SHkG8NBlQPeoHZihxU+Fu55klwN5HAWAs= X-Received: by 2002:a2e:4e09:0:b0:2f0:27da:6864 with SMTP id 38308e7fff4ca-2f9d3e49851mr90401661fa.17.1727784913507; Tue, 01 Oct 2024 05:15:13 -0700 (PDT) MIME-Version: 1.0 References: <3133182a-35c4-4a81-be60-8ab227c0fbc0@aklaver.com> In-Reply-To: From: Greg Sabino Mullane Date: Tue, 1 Oct 2024 08:14:36 -0400 Message-ID: Subject: Re: Question on session timeout To: sud Cc: Adrian Klaver , pgsql-general Content-Type: multipart/alternative; boundary="000000000000049b400623694603" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000049b400623694603 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, Oct 1, 2024 at 1:57=E2=80=AFAM sud wrote: > *Where are you getting the ~2000 count from?* > Seeing this in the "performance insights" dashboard and also its matching > when I query the count of sessions from pg_stat_activity. > So I'm guessing this is perhaps RDS or Aurora? Stating that up front can be helpful. > As you described, a long time open transaction with a session state as > "idle" will be threatening as that will cause locking > No, idle is fine, "idle in transaction" is bad. :) Is it correct to assume the session in pg_stat_activity with very old > XACT_START are the one which are part of long running > You need to look at the "state" column as your primary bit of information. Second most important is how long something has been in that state, which you can find with now() - state_change. The best way to learn all of this is to open a few concurrent sessions in psql and experiment. > We have max_connections set as 5000. > That's quite high. But if you never reach that high, it doesn't matter a whole lot. "Database connection" touching ~2000 then coming down till 200. And we see > uneven spikes in those, it seems to be matching with the pattern , when w= e > have some errors occurring during the insert queries which are submitted = by > the Java application to insert the data into the tables. > (What sort of errors?) 2000 is high. Clearly, you are not pooling connections, or not pooling them well. If you are using plain Postgres, look into setting up pgbouncer. If using something managed (e.g. RDS) look into their particular pooling solution. Or fix your application-level pooling. Cheers, Greg --000000000000049b400623694603 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Tue, Oct 1, 2024 at 1:57=E2=80=AFAM su= d <suds1434@gmail.com> wrot= e:
Where are you get= ting the ~2000 =C2=A0count from?
Seeing this in the "performanc= e insights" dashboard and also its matching when I query the count of = sessions from pg_stat_activity.

=
So I'm guessing this is perhaps RDS or Aurora? Stating that up fro= nt can be helpful.
=C2=A0
As you describe= d, a long time open transaction with a session state as "idle" wi= ll be threatening as that will cause locking
<= br>
No, idle is fine, "idle in transaction" is bad. :)= =C2=A0

Is it correct to assume the s= ession in pg_stat_activity with very old XACT_START are the one which are p= art of long running

<snip re= st of question>

You need to look at the "s= tate" column as your primary bit of information. Second most important= is how long something has been in that state, which you can find with now(= ) - state_change. The best way to learn all of this is to open a few concur= rent sessions in psql and experiment.
=C2=A0
We have max_connections set as 5000.
<= br>
That's quite high. But if you never reach that high, it d= oesn't matter a whole lot.

"= ;Database connection" touching ~2000 then coming down till 200. And we= see uneven spikes in those, it seems to be matching with the pattern , whe= n we have some errors occurring during the insert queries which are submitt= ed by the Java application to insert the data into the tables.
<= /blockquote>

(What sort of errors?) 2000 is high.=C2=A0C= learly, you are not pooling connections, or not pooling them well. If you a= re using plain Postgres, look into setting up pgbouncer. If using something= managed (e.g. RDS) look into their particular pooling solution. Or fix you= r application-level pooling.

Cheers,
Gre= g

--000000000000049b400623694603--