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 1sA3YD-007FhO-74 for pgsql-general@arkaria.postgresql.org; Thu, 23 May 2024 08:11:50 +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 1sA3YC-009lUW-WD for pgsql-general@arkaria.postgresql.org; Thu, 23 May 2024 08:11:49 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sA3YC-009lUN-Ja for pgsql-general@lists.postgresql.org; Thu, 23 May 2024 08:11:48 +0000 Received: from mail-ua1-x930.google.com ([2607:f8b0:4864:20::930]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sA3Y7-000LVy-Ug for pgsql-general@lists.postgresql.org; Thu, 23 May 2024 08:11:48 +0000 Received: by mail-ua1-x930.google.com with SMTP id a1e0cc1a2514c-804579f4130so62361241.3 for ; Thu, 23 May 2024 01:11:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716451902; x=1717056702; 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=1MH0hofyYKYRlZ6o03JVu/yw0wCdTrez3VL5ea+FhPs=; b=AOQFGmnZ/cm/EEk5PpoDpmcAezHE3utc1rrshFsP0k9/2yjDNqAegpSLdebFHLtP6l dii+JK5vEhSRcjvySi0s5v+mQdz2sIksRhCSQ0MXH7sEUhnoYGGp5NF8IFjD4c1WmRNK SLU4n/usOZas7uLhe+csQtygdy2TUV1o7uEgOB5HTE8K0EzXsVYYGJYw142zolhPK+pw YvEUITyN5JvGguIEi0bq0ifOT2nDTfZZI+R1/xjDa1Gc4z82m1ESz/UCDipoZUNgKBiL bf10ULUlxtbLFS21ZwQ9/t3GpmNw2J591zLWllCHYk2DykJOjnXfLQ92TnpVo/ophnfN x5Dw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716451902; x=1717056702; 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=1MH0hofyYKYRlZ6o03JVu/yw0wCdTrez3VL5ea+FhPs=; b=GYMK5MjAIe5PCUUt81YyB/pnutEzt1OEnq2m11JQ/z88vf+gOJBcmSYmycEB8giLsr yvt0vU/bdTFqkrX4HcmaR6xhIi0+kVo8R2S4TmkaoL/KiUunmm/ac0cGhtTnhzjSl8P/ 3jvmlfzIt5Z4DgoppfdMqwEomUMxkFoSd+Fa1U/mu7b/LQltAV4PQx/gGKrfLZaeo7q2 hZ1zfJOCol4HjQRJUokvuAL+GqUmAk6+TPsQpRj414a7+UR1s6wafEIR6MhgtDBNw40/ QJZj5eeVSm8xiOd5atHc/UX0D7I4BKIASSZsLa0Pcl4DboEmaOVdyEhgLuPEQ+XoL8tS Z8zg== X-Gm-Message-State: AOJu0YwDX6eGIr7AjiNuma7IZ6CqxEwUKntixGiJR7JNFWKO+6cy8kPw Q3jTYNqbRSolyQvs/UOJ0Ump7Ae/5BRk8ec0BDHzn710TiVd+eNMcLamPMjvB4Gmyghuwa/j/HK 5s1JJmsN0/untngunxFppxN5i62o= X-Google-Smtp-Source: AGHT+IG8awGkYESDr7X2gA+8Cx85weJdH7tXbikSDGq/ZKUt49Ly6frxLZ/55tDUiW9qrmNd7nCncyESMCEKXVWHJMo= X-Received: by 2002:a05:6102:10da:b0:47a:4231:d720 with SMTP id ada2fe7eead31-4890094de66mr3690985137.8.1716451902352; Thu, 23 May 2024 01:11:42 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: sud Date: Thu, 23 May 2024 13:41:31 +0530 Message-ID: Subject: Re: Long running query causing XID limit breach To: Laurenz Albe Cc: pgsql-general Content-Type: multipart/alternative; boundary="000000000000e9f8aa06191a99dc" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000e9f8aa06191a99dc Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, May 23, 2024 at 1:22=E2=80=AFPM Laurenz Albe wrote: > On Thu, 2024-05-23 at 02:46 +0530, sud wrote: > > It's RDS postgres version 15.4. We suddenly saw the > "MaximumUsedTransactionIDs" > > reach to ~1.5billion and got alerted by team members who mentioned the > database > > is going to be in shutdown/hung if this value reaches to ~2billion and > won't be > > able to serve any incoming transactions. It was a panic situation. > > > > I have heard of it before , because of the way postgres works and the > XID being > > a datatype of length 32 bit integer can only represent (2^32)/2=3D~2 > billion > > transactions. However, as RDS performs the auto vacuum , we thought tha= t > we need > > not worry about this issue. But it seems we were wrong. And we found on= e > adhoc > > "SELECT '' query was running on the reader instance since the last > couple of > > days and when that was killed, the max xid (MaximumUsedTransactionIDs) > dropped > > to 50million immediately. > > This has nothing to do with autovacuum running. > PostgreSQL won't freeze any rows above the xmin horizon (see the > "backend_xmin" > column in "pg_stat_activity"). > > > So I have few questions, > > > > 1)This system is going to be a 24/7 up and running system which will > process > > ~500million business transactions/day in future i.e. ~4-5billion > rows/day > > inserted across multiple tables each day. And as I understand each ro= w > will > > have XID allocated. So in that case , does it mean that, we will need > > (5billion/24)=3D~200million XID/hour and thus , if any such legitimat= e > > application "SELECT" query keeps running for ~10 hours (and thus keep > the > > historical XID alive) , then it can saturate the > "MaximumUsedTransactionIDs" > > and make the database standstill in 2billion/200million=3D~10hrs. Is = this > > understanding correct? Seems we are prone to hit this limit sooner > going forward. > > Yes, that is correct. You cannot run such long-running queries with a > transaction rate like that. > > When you mean transaction ,does it mean one commit ? For example if it's inserting+committing ~1000 rows in one batch then all the 1000 rows will be marked as one XID rather than 1000 different XID. and so we should look for batch processing rather than row by row types processing. Is the understanding correct? > One thing you could consider is running the long-running queries on a > standby > server. Replication will get delayed, and you have to keep all the WAL > around for the standby to catch up once the query is done, but it should > work. > You'd set "max_streaming_standby_delay" to -1 on the standby. > > We have the "Select query" running on a reader instance , but still the writer instance was showing up "MaximumUsedTransactionIDs" reaching 1.5billion, so it means both the instance as part of same cluster so sharing same XIDs, and as per your suggestion we should run this in separate standby cluster altogether which does not share same XID. Is this understanding correct? or it can be handled even with another reader instance by just tweaking some other parameter so that they won't share the same XID? --000000000000e9f8aa06191a99dc Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

On Thu, May 23, 2024 at 1:22=E2=80=AFPM L= aurenz Albe <laurenz.albe@cy= bertec.at> wrote:
On Thu, 2024-05-23 at 02:46 +0530, sud wrote:
> It's RDS postgres version 15.4. We suddenly saw the "MaximumU= sedTransactionIDs"
> reach to ~1.5billion and got alerted by team members who mentioned the= database
> is going to be in shutdown/hung if this value reaches to ~2billion and= won't be
> able to serve any incoming transactions. It was a panic situation.
>
> I have heard of it before , because of the way postgres works and the = XID being
> a datatype of length 32 bit integer can only represent (2^32)/2=3D~2 b= illion
> transactions. However, as RDS performs the auto vacuum , we thought th= at we need
> not worry about this issue. But it seems we were wrong. And we found o= ne adhoc
> "SELECT '' query was running on the reader instance since= the last couple of
> days and when that was killed, the max xid (MaximumUsedTransactionIDs)= dropped
> to 50million immediately.

This has nothing to do with autovacuum running.
PostgreSQL won't freeze any rows above the xmin horizon (see the "= backend_xmin"
column in "pg_stat_activity").

> So I have few questions,
>
> 1)This system is going to be a 24/7 up and running system which will p= rocess
>=C2=A0 =C2=A0~500million business transactions/day in future i.e. ~4-5b= illion rows/day
>=C2=A0 =C2=A0inserted across multiple tables each day. And as I underst= and each row will
>=C2=A0 =C2=A0have XID allocated. So in that case , does it mean that, w= e will need
>=C2=A0 =C2=A0(5billion/24)=3D~200million XID/hour and thus , if any suc= h legitimate
>=C2=A0 =C2=A0application "SELECT" query keeps running for ~10= hours (and thus keep the
>=C2=A0 =C2=A0historical XID alive) , then it can saturate the "Max= imumUsedTransactionIDs"
>=C2=A0 =C2=A0and make the database standstill in 2billion/200million=3D= ~10hrs. Is this
>=C2=A0 =C2=A0understanding correct? Seems we are prone to hit this limi= t sooner going forward.

Yes, that is correct.=C2=A0 You cannot run such long-running queries with a=
transaction rate like that.


When you mean transaction ,does it mea= n one commit ? For example if it's inserting+committing ~1000 rows in o= ne batch then all the 1000 rows will be marked as one XID rather than 1000 = different XID. and so we should look for batch processing rather than row b= y row types processing. Is the understanding correct?
=C2=A0
One thing you could consider is running the long-running queries on a stand= by
server.=C2=A0 Replication will get delayed, and you have to keep all the WA= L
around for the standby to catch up once the query is done, but it should wo= rk.
You'd set "max_streaming_standby_delay" to -1 on the standby.=


We have the "Select query&quo= t; running on a reader instance , but still the writer instance was showing= up "MaximumUsedTransactionIDs" reaching 1.5billion, so it means = both the instance as part of same cluster so sharing same XIDs, and as per = your suggestion we should run this in separate standby cluster altogether= =C2=A0which does not share same XID. Is this understanding correct? or it c= an be handled even with another reader instance by just tweaking some other= parameter so that they won't share the same XID?
--000000000000e9f8aa06191a99dc--