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 1svWji-00Fi4O-1A for pgsql-general@arkaria.postgresql.org; Tue, 01 Oct 2024 06:51:54 +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 1svWjh-00BnyV-D4 for pgsql-general@arkaria.postgresql.org; Tue, 01 Oct 2024 06:51:53 +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 1svWjg-00Bny3-U8 for pgsql-general@lists.postgresql.org; Tue, 01 Oct 2024 06:51:53 +0000 Received: from mail-oa1-x2b.google.com ([2001:4860:4864:20::2b]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1svWjd-001uwx-UW for pgsql-general@lists.postgresql.org; Tue, 01 Oct 2024 06:51:51 +0000 Received: by mail-oa1-x2b.google.com with SMTP id 586e51a60fabf-2877d7ae431so16258fac.0 for ; Mon, 30 Sep 2024 23:51:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727765509; x=1728370309; 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=zoGL1mDzmJJvHvIL/mpwiysxd1H9nmDQ2U1Gsq8Lgjc=; b=ZPHBtYgurjiiH58ewuTitQeiwfSCJqmR4ykRw8PwZMBQ20k5C1vz4tXAJLBlkpF9lk TbYkNkp7LVhVrkjcU2FIZWbw0BxcOLW4SEmBSaPtinIsRPAltr+PD9aiP3xWyE4dnNzR Skhb38TKQ0Q+vczcdrRWHb7B9kit4vU8L65uASeEzRWsnMfEnTOvX3vsvY6NmsXkdEDd M4vyvXeBYf4m7MzCspGJ984WZaxcHMq5NbjUD1VBEf/4edwUCtGFijIRxhwjGEApOwvO E8aZxQeMQt+QUEzWMyoyW66oj+K8Sgn7ghxLPSR4669uySFM7OeLL7QhGsnqWHLcWGzQ 7hTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727765509; x=1728370309; 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=zoGL1mDzmJJvHvIL/mpwiysxd1H9nmDQ2U1Gsq8Lgjc=; b=Im82N97teb0oAI/JkArF/rEkdYJFimlBiSKUi0RW1VQ3wcabw6A93WOnn8/wFpBtGm i8zg/vA3frDMzsYV5bLMYsBnB6ql2as6A9yKOyI1iB/Ak4mgrQzUND6wp5BQ3+sDTTbs a7bxW/ENUu5QpXB/jdbXnL+WvWimAwLdJcRnNouzjnXwVjLYNodptgyOCeO8RYt1VkA+ 066vBi4QKr7MOYir1iXOf2gp+5370OE2MRurrxq/F05HYEbUi+rXqu8K2OzdbAbHyVKx AvKu6GyQgqhpkOyLTjIydK9IxPn3VEPt+0t6tMVcj18O2rdrfAjDXfEN6793sr9+KNWX aeTA== X-Gm-Message-State: AOJu0YytC5wiHkvS9Vyc6VqixO8zc2i7RrgyUv5wXyH/vMc0uqFXmJqA JM5+fOFEj6TmJ62jgSwrEAkCJqTOeONAmqFT+m52z7oWWjHc3dyS6X/4wZzsH/t2TgzS4spk77d XtI8NZLBVRqpaPVXukF3wnQCrOcg= X-Google-Smtp-Source: AGHT+IG1wHNmD7qL0wGl37xNuzlZPeKvC90/ty/uLOMPFNl903PhpjbiJ0AGuajWWwdSqBCwGioVhP733Lw9LZ31Dso= X-Received: by 2002:a05:6870:9613:b0:270:4219:68fe with SMTP id 586e51a60fabf-287109f5cc7mr7979686fac.1.1727765509205; Mon, 30 Sep 2024 23:51:49 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: yudhi s Date: Tue, 1 Oct 2024 12:21:37 +0530 Message-ID: Subject: Re: Suggestion for memory parameters To: Philip Semanchuk Cc: pgsql-general Content-Type: multipart/alternative; boundary="0000000000006e7c04062364c102" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000006e7c04062364c102 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, Sep 30, 2024 at 8:46=E2=80=AFPM Philip Semanchuk < philip@americanefficient.com> wrote: > > > > On Sep 26, 2024, at 7:03=E2=80=AFAM, yudhi s > wrote: > > > > In a RDS postgres ... > > > Is it fine to let it use "FreeLocalStorage" unless it goes till zero? > > Hi Yudhi, > FreeLocalStorage and some of the other things you ask about are specific > to AWS RDS, so you might have better luck getting answers on an > RDS-specific mailing list. We also use RDS-hosted Postgres and so I > completely understand how Postgres and RDS are intertwined. > > We have had runaway queries exhaust FreeLocalStorage. It has been quite a > while since that happened, so my memories are hazy, but I=E2=80=99m prett= y sure > that when we used all of FreeLocalStorage, the result was that Postgres > restarted. It might be equivalent to using all memory and disk space on a > standalone system. Once there=E2=80=99s no storage left, behavior is unpr= edictable > but we can=E2=80=99t be surprised if things crash. Usually our runaway qu= eries got > killed before FreeLocalStorage filled up, but not always. > > I second Veem=E2=80=99s suggestion to set work_mem on a per-session basis= . Also > note that the doc for work_mem says, =E2=80=9Cthe total memory used could= be many > times the value of work_mem; it is necessary to keep this fact in mind wh= en > choosing the value." > > > https://www.postgresql.org/docs/current/runtime-config-resource.html#GUC-= WORK-MEM > > Thank you. When I execute the query with explain (analyze, buffers),I see the section below in the plan having "sort method" information in three places each showing ~75MB size, which if combined is coming <250MB. So , does that mean it's enough to set the work_mem as ~250MB for these queries before they start? But yes somehow this query is finished in a few seconds when i execute using explain(analyze,buffers) while if i run it without using explain it runs for ~10minutes+. My expectation was that doing (explain analyze) should actually execute the query fully. Is my understanding correct here and if the disk spilling stats which I am seeing is accurate enough to go with? Limit (cost=3D557514.75..592517.20 rows=3D300000 width=3D1430) (actual time=3D2269.939..2541.527 rows=3D300000 loops=3D1) Buffers: shared hit=3D886206, temp read=3D38263 written=3D56947 I/O Timings: temp read=3D70.040 write=3D660.073 -> Gather Merge (cost=3D557514.75..643393.02 rows=3D736048 width=3D1430= ) (actual time=3D2269.938..2513.748 rows=3D300000 loops=3D1) Workers Planned: 2 Workers Launched: 2 Buffers: shared hit=3D886206, temp read=3D38263 written=3D56947 I/O Timings: temp read=3D70.040 write=3D660.073 -> Sort (cost=3D556514.73..557434.79 rows=3D368024 width=3D1430) (actual time=3D2227.392..2279.389 rows=3D100135 loops=3D3) Sort Key: column1, column2 Sort Method: external merge Disk: *77352kB* Buffers: shared hit=3D886206, temp read=3D38263 written=3D569= 47 I/O Timings: temp read=3D70.040 write=3D660.073 Worker 0: Sort Method: external merge Disk: *75592kB* Worker 1: Sort Method: external merge Disk: *74440kB* -> Parallel Append (cost=3D0.00..64614.94 rows=3D368024 width=3D1430) (actual time=3D0.406..570.105 rows=3D299204 loops=3D3) --0000000000006e7c04062364c102 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


=
On Mon, Sep 30, 2024 at 8:46=E2=80=AF= PM Philip Semanchuk <phi= lip@americanefficient.com> wrote:


> On Sep 26, 2024, at 7:03=E2=80=AFAM, yudhi s <learnerdatabase99@gmail.com= > wrote:
>
> In a RDS postgres ...

>=C2=A0 Is it fine to let it use "FreeLocalStorage" unless it = goes till zero?

Hi Yudhi,
FreeLocalStorage and some of the other things you ask about are specific to= AWS RDS, so you might have better luck getting answers on an RDS-specific = mailing list. We also use RDS-hosted Postgres and so I completely understan= d how Postgres and RDS are intertwined.

We have had runaway queries exhaust FreeLocalStorage. It has been quite a w= hile since that happened, so my memories are hazy, but I=E2=80=99m pretty s= ure that when we used all of FreeLocalStorage, the result was that Postgres= restarted. It might be equivalent to using all memory and disk space on a = standalone system. Once there=E2=80=99s no storage left, behavior is unpred= ictable but we can=E2=80=99t be surprised if things crash. Usually our runa= way queries got killed before FreeLocalStorage filled up, but not always.
I second Veem=E2=80=99s suggestion to set work_mem on a per-session basis. = Also note that the doc for work_mem says, =E2=80=9Cthe total memory used co= uld be many times the value of work_mem; it is necessary to keep this fact = in mind when choosing the value."

https://www.postgre= sql.org/docs/current/runtime-config-resource.html#GUC-WORK-MEM

<= /blockquote>

Thank you.

When I = execute the query with explain (analyze, buffers),I see the section below i= n the plan having "sort method" information in three places each= =C2=A0showing ~75MB size, which if combined is coming <250MB. So , does = that mean it's enough to set the work_mem as ~250MB for these queries b= efore they start?

=C2=A0But yes somehow this query= is finished in a few seconds when i execute using explain(analyze,buffers)= while if i run it without using explain it runs for ~10minutes+. My expect= ation was that doing (explain analyze) should actually execute the query fu= lly. Is my understanding correct here and if the=C2=A0disk spilling stats w= hich I am seeing is accurate=C2=A0enough to go with?

Limit =C2=A0(cost=3D557514.75..592517.20 rows=3D= 300000 width=3D1430) (actual time=3D2269.939..2541.527 rows=3D300000 loops= =3D1)
=C2=A0 Buffers: shared hit=3D886206, temp read=3D38263 written=3D5= 6947
=C2=A0 I/O Timings: temp read=3D70.040 write=3D660.073
=C2=A0 -&= gt; =C2=A0Gather Merge =C2=A0(cost=3D557514.75..643393.02 rows=3D736048 wid= th=3D1430) (actual time=3D2269.938..2513.748 rows=3D300000 loops=3D1)
= =C2=A0 =C2=A0 =C2=A0 =C2=A0 Workers Planned: 2
=C2=A0 =C2=A0 =C2=A0 =C2= =A0 Workers Launched: 2
=C2=A0 =C2=A0 =C2=A0 =C2=A0 Buffers: shared hit= =3D886206, temp read=3D38263 written=3D56947
=C2=A0 =C2=A0 =C2=A0 =C2=A0= I/O Timings: temp read=3D70.040 write=3D660.073
=C2=A0 =C2=A0 =C2=A0 = =C2=A0 -> =C2=A0Sort =C2=A0(cost=3D556514.73..557434.79 rows=3D368024 wi= dth=3D1430) (actual time=3D2227.392..2279.389 rows=3D100135 loops=3D3)
= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 Sort Key: column1, column2=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 Sort Method: external = merge =C2=A0Disk: 77352kB
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 Buffers: shared hit=3D886206, temp read=3D38263 written=3D56947<= br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 I/O Timings: temp read= =3D70.040 write=3D660.073
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 Worker 0: =C2=A0Sort Method: external merge =C2=A0Disk: 75592kB<= br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 Worker 1: =C2=A0Sort Me= thod: external merge =C2=A0Disk: 74440kB
=C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 -> =C2=A0Parallel Append =C2=A0(cost=3D0.00..64= 614.94 rows=3D368024 width=3D1430) (actual time=3D0.406..570.105 rows=3D299= 204 loops=3D3)

=C2=A0
--0000000000006e7c04062364c102--