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.96) (envelope-from ) id 1vmI9u-00A6Ci-1m for pgsql-general@arkaria.postgresql.org; Sat, 31 Jan 2026 21:05:34 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vmI9s-0098xq-2A for pgsql-general@arkaria.postgresql.org; Sat, 31 Jan 2026 21:05:33 +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.96) (envelope-from ) id 1vmI9s-0098xb-0m for pgsql-general@lists.postgresql.org; Sat, 31 Jan 2026 21:05:33 +0000 Received: from mail-oi1-x22a.google.com ([2607:f8b0:4864:20::22a]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1vmI9q-00000000Pke-2lTD for pgsql-general@lists.postgresql.org; Sat, 31 Jan 2026 21:05:32 +0000 Received: by mail-oi1-x22a.google.com with SMTP id 5614622812f47-45f0b597eb4so2074302b6e.2 for ; Sat, 31 Jan 2026 13:05:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1769893528; cv=none; d=google.com; s=arc-20240605; b=ZPuXBKqEHFDzmZenvwBWIlKirCOk1iWwAJAHyJ6JTAedfQ7ejXc8Ty2b1IXnY3C/ht EI7V5r99rR27A8XsllEk98ZannrZDuBLnd3W6w3rlSvLS1NwUGpSf1+spUA4dxIiFnPk NoeA+V6GkREOllrBCzKthN3cH6BUVgmWzPIGnrEz8erol+0zHhX3XR8d8l0igp+HMPLF M5dNuITFx9Zn67eH17qpUXgC67Ao4RCTuxNMS94iFgh9VCNpVvJ/05NJAD59nuEG2MKD WPpNgE5FQAlmBkLkCivV2Ym9vUhdrA/KwROt7H0a35Sud+tCXY+tNW4VbSE/mRhQUhxI iEsg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=tQCsc8EM0ltdVvRTY3nbPyoQBMEmoEsqKSa/bteWvxg=; fh=U9Vkrj/8YXu+wNKP4ImG87p6jlJYRxuB/zicT9qNons=; b=clksaHBQA8rwowUnlOFLIUtI5qzwKdZS+BjbwkeBo9GsLSN/4w2S5/V5nKaeD2Lnk5 gZvhhBbWjl2hRAK/w+bayv2LA61ArYqdwM/d76lhej7H8CcN4RpGgZQMv6v3w101DC6L 0iD9KNKScvdFcw4nKEPza4wmTdnR9R/v7gDefnNM1PR5yMx+rbbLj7FIVVrwut/aBqNt M3Oa2BLJJGmmXJpv37mesWnOP/6qmym7lmiPWJUp7UMcAn9B0500rgozHrwnRUxYpmaM gFNObMsihTRz0iX2//KOunIiJL0V79Jl3meBGaNQNC/RCPijRvhFbcB4kseTE/ot2neW nUjw==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1769893528; x=1770498328; darn=lists.postgresql.org; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=tQCsc8EM0ltdVvRTY3nbPyoQBMEmoEsqKSa/bteWvxg=; b=KjRdKX+u1OVMz7xem0wcfWSH3u2B1wb4I+a0JMbjwDH2FbaoWTfi/xQu/SXfhdRDQa OnpxAIS08QZvDd0ZH3ktUtUgVveGPIa83VPz+wLTpDt0Rk2z+dbFPNQxhpfcu2Sjxt1y YS9qonF4NzLY/BPrDC1SpI/1dxWNB9PAND48OTyTRXuFfdS94kly8rGHYXhnk3Hp9HyP kdQ6TSHSrMcULDx1b+0bxyuOXMTT73KIvLAGWZ0/fF+lRX2OO/PY3NYKaxO8UEhmamuE ydiEhJ2x2Ipsc4Fsh5sii1VZV6t7ybVC1LD4+Vszui3sdmK8WpUGj/6FF5CfZgghvY/k KXAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769893528; x=1770498328; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=tQCsc8EM0ltdVvRTY3nbPyoQBMEmoEsqKSa/bteWvxg=; b=Il6ifrVmcGNEgAH99//QfpUWVCjaSFJDAFVN6i8zOZcyvSsdaWX6yxVSbfNqHDodS6 kHFJq1VwWav1wo6QDu1+UeE4eE97h4MkeAZOxGfQukEHslvnHW7C+Wp/xsxq8lAo3XEN f6n67kF5D+UrKcsN9E0R0Uw/52eLpvNM+8LTEm7TPQyOA8r/OuDUhy/wC7pissthNsqt aF1Svbz0Nnkug8iDleqLdvsPbu4I5oMzPGIYvXw5RDHgg3OiIJGH9oFMtvmExkjR4IHV bAZCF3FcJBq4aC+oXlcXX8qL0KFXNQ0NEJSksCg3qgZtbYqDKPOSqUzJ09Li7UN52L4D Q2KA== X-Gm-Message-State: AOJu0Yzc8ks+xUCFb2FphuF1oj5Y1h1ZlXWcMQRKzKRXNj62uAeLcC0A JO3+g+i6QsYRgAVs6je0HXeQioCTcO92HCqSgI+2hzLaZqgpwEXNxwEaC5HtsqArSxilVD9fRTM nDdLH3unpUlBwZKPhYsRjvgOluYH0Ksom78tP X-Gm-Gg: AZuq6aI5tzxfuHPvduyzkNiKW1znBSSGuFEkJw3apFKZz46m2JwIme4LEuH3K1newlP 8I3nw9qYqIK3iC0za4FrxjysdZgq8E7/ZKPjD3m43WJ5i0hvu9adG4De+LKTWE44UAS6v8moacE eO9e0pshrVYskla1L4HWS6qyaJzyS9x3Fqk1/y2SBQLhi1RG9psO2cggEXwrk+DvMBnWFbA4FnX fqhBEp/VbiaTaFWKSUptB12EVm2qDZHJraceKpf2khlS0/TtWHFWJOl9QN88FLKayqL6ljV X-Received: by 2002:a54:489a:0:b0:45f:42d6:2fff with SMTP id 5614622812f47-45f42d63aadmr1881242b6e.32.1769893528501; Sat, 31 Jan 2026 13:05:28 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Ron Johnson Date: Sat, 31 Jan 2026 16:05:17 -0500 X-Gm-Features: AZwV_QgdpXR9xyIDj3HUTNv0aT_ajGMXGspUw_k1zktLyMO6_VaSsd1ViP8Pmx0 Message-ID: Subject: Re: Top -N Query performance issue and high CPU usage To: pgsql-general Content-Type: multipart/alternative; boundary="0000000000000e85430649b57327" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000000e85430649b57327 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Sat, Jan 31, 2026 at 2:47=E2=80=AFPM yudhi s wrote: > Thank you. > >> >> 1) Without even looking at the plan I'm going to say 2-VCPU and 16GB RAM >> and is insufficient resources for what you want to do. >> >> > Can you please explain a bit in detail, how much minimum VCPU and RAM wil= l > be enough resources to suffice this requirement? and you normally do that > calculation? > > >> 2) You will need to provide the schema definitions for the tables >> involved. >> >> Do you mean table DDL or just the index definitions on the tables should > help? > > Also i was trying to understand , by just looking into the "explain > analyze" output, is there any way we can tie the specific step in the pla= n > , which is the major contributor of the cpu resources? Such that we can > then try to fix that part rather than looking throughout the query as its > big query? > It looks like 71% (748ms of a total 1056ms) of elapsed time is taken by the c_1.tran_date external sort on line 150. That, obviously, is what you should work on. 1. You say you increased work_mem. From what, to what? 2. But that it did not reduce execution time. Please post the EXPLAIN from after increasing work_mem. 3. Did you remember to run SELECT pg_reload_conf(); after increasing work_mem? 4. Is there an index on APP_schema.txn_tbl.tran_date? And if any suggestion to improve the TOP-N queries where the base table may > have many rows in it. > --=20 Death to , and butter sauce. Don't boil me, I'm still alive. lobster! --0000000000000e85430649b57327 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Sat, Jan 31, 2026 at 2:47=E2=80=AFPM y= udhi s <learnerdatabase99= @gmail.com> wrote:
Thank you.=C2=A0

1) Without even looking at the plan I'm going to say 2-VCPU and 16GB RA= M
and is insufficient resources for what you want to do.


Can you please explain a bit in detail= , how much minimum VCPU and RAM will be enough resources to suffice this re= quirement? and you normally do that calculation?
=C2=A0
2) You will need to provide the schema definitions for the tables involved.=

Do you mean table DDL or just the index definitio= ns=C2=A0on the tables should help?

Also i was tryi= ng to understand , by just looking into the "explain analyze" out= put, is there any way we can tie the specific step in the plan , which is t= he major contributor of the cpu resources? Such that we can then try to fix= that part rather than looking throughout the query as its big query?=C2=A0= =C2=A0

It looks like 71% = (748ms of a total 1056ms) of elapsed time is taken by the=C2=A0c_1.tran_date=C2=A0 external sort on line 150.

That, obviously, is what you should work on.

1. You say you increased work_mem.=C2=A0 From what, to wh= at?
2. But that it did not reduce execution time.=C2=A0 Please po= st the EXPLAIN from after increasing work_mem.
3. Did you remembe= r to run SELECT pg_reload_conf(); after increasing work_mem?
4. I= s there an index on=C2=A0APP_schema.txn_tbl.<= /span>tran_date?

<= blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-l= eft:1px solid rgb(204,204,204);padding-left:1ex">
And if any suggestion to improve the TOP-N queries w= here the base table may have many rows in it.

--=
Dea= th to <Redacted>, and butter sauce.
Don't boil me, I'm st= ill alive.
<Redacted> lobster!
--0000000000000e85430649b57327--