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 1vmX08-00D7En-1M for pgsql-general@arkaria.postgresql.org; Sun, 01 Feb 2026 12:56:28 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vmWz6-009pWs-0n for pgsql-general@arkaria.postgresql.org; Sun, 01 Feb 2026 12:55:25 +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.96) (envelope-from ) id 1vmWz5-009pWV-2G for pgsql-general@lists.postgresql.org; Sun, 01 Feb 2026 12:55:24 +0000 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1vmWz4-000000002Ey-1sW7 for pgsql-general@lists.postgresql.org; Sun, 01 Feb 2026 12:55:23 +0000 Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-2a7d98c1879so22507165ad.3 for ; Sun, 01 Feb 2026 04:55:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1769950521; cv=none; d=google.com; s=arc-20240605; b=LasI/Wj2uE/CAE+4uXOBBEZRR1C4ZXhrnyn3+LcNi/AiI4pKSq52ll1+X0PvVMP3Fm CNsGxPZizI95yHP9ivYL0WLgbdmmH0Gy+QopgpOj51x82AFanOIyWW9PTOAK42XRN6y1 Ah9bzZWqomwkKP8I9TXCQ5kgnNtLqOPVPD7kSGVGxZYcNni4BC1fEBnXfbKOWi/iXqIn 4BDyvOyP1QOw5uo5HY1X6unNKNPZxqR3KdArV1Gv8Do9ZM8kTnSjlMwiVRmq9DF8Kec/ MBgB+Um6n/oC82GyA1ZnU6nEkqv9bUYQhynfeznwTQiDerQ1Zwsd9fV6gUHSzNkxP9fQ W7Jw== 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=eb6PdlaeK8pBqtwj7cQHzWuP9fgvaM1BW36WeEuhyhY=; fh=U9Vkrj/8YXu+wNKP4ImG87p6jlJYRxuB/zicT9qNons=; b=R9AxHx0LhQALYWyFFdYNpfMC1uvL8Ea5n3EeaO6ddMmf+zGvj0p1gSSL60m68lJS9w 2B/txJijxWelhR/qC6YHwnk7mJfcu0Fv4bji9IlVBzR9HGc7vr7tJatYAF/mVP8XNLnJ dNnY7mJo7oP5x8Jr7gApmbLHjP9dfFASwIq3si5KIkRcZ43m7Pe5Z5B3nH5a31jvtu1+ onQUNTtCPzuyvenTHL8IICj17C2IzCtgPtRzF4bLc6+m12IIwZZcCrhZcNRlveuuUkLL gKSzFiMsJDi6+H18KiuJ67OCIZAjUxckcWBgQQbsMPTxSmPIQ4E40dtI8O2Ff4bG0CIU Bljw==; 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=dbtune.com; s=google; t=1769950521; x=1770555321; 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=eb6PdlaeK8pBqtwj7cQHzWuP9fgvaM1BW36WeEuhyhY=; b=ELLhkD62GJd/BwQ/eIjpTn2kgn4QjHIGvNK/vr3+9357yIPUTVOHFCgUKb6s9H7o0x AKHUXcF1xRXfo3GYGtOBga4+xaxr06C4ymBlqY+ALbwdgbGAN86erSGk0CWhSW4YAjrO n22MhHG04l39DRyqwKVWMj6lja0HZDaw9W3z1bCX6fy7VYUljN/RixdJM7Jw1DLXhRfJ aD5ED5RSV1/UBSRJeBZfdhjqhXG5q/aSCmXex+4gDQpnzbZi9EiWoEyFhZf20pERs42F S5ObUDuSoPKs4ycgplO8xiaZ3Lj4gF9Fd2ZRyk6eh3PIW5xYbHgQRfilZJB63QmUX+kQ bZ+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769950521; x=1770555321; 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=eb6PdlaeK8pBqtwj7cQHzWuP9fgvaM1BW36WeEuhyhY=; b=K/nwQS4NWL191qL0RmMdRaFSEFxJKUmJKxf8NgCC7Guh43VOuJTni8maZFNDKZYeop nnXLKwgWjQ64K5tMjstBl68ea0SvSB0DpxRNuQUc3ziwd2EH1RdIhzVMMs+fvn7iI2/6 +8t7AorZT0BFYkhU+oPEXP/YvNiBHl7eNI1ibVrHtlEYDi/eYUCGgdyhnNgo5rGiXJ70 jvngssieBfxrz6lhLWlKn7iyWjWP5FEF0T082HuLwma0OCXZV2ZLPPHSPgk8yMxYff32 xntaUzEgQSuXMYd8qVson41q6p7wOQOjv0pffx1CMXo0XmEphiKqdqckWAA050X5b1N9 xpaw== X-Gm-Message-State: AOJu0Yx5K2WXO79HQ5qSDgPx1LKW5OkoY10notCcw0mz7E25zQm0XHhK u+8gevPZWcrh+FwVg+KUU22x4S9GbygYvdUQV7G+g2Ja36Z2VrigyrwfUriFOqH7W54p/rpozFY 8F3YFk6L+ncZRTYPwyGkdBj5bZk/63TTMUwSbi15X0wSt6OfQ7wSlqTw= X-Gm-Gg: AZuq6aIeqfa8JxszT1utLVm4aQ0yXXoJ5wl0Y5+q6Y+9U7R9XQG3OkvNMk1Vxrv3g++ z+n6WBHtdt5VGhyUUeN9f/SE9ws2Xmba/c+bbHt42z6F1dGxtwbcTFGINaKXBtdaYIELhtFXv3e eP/f+FCmGLBf1RhbJZMvmhxI4CujBHEne4dAind5lpRgxPTReWzMsR11u8L9Bd8mZq8acjDFBsD ffEXvwvG740WA3lxVzhjhzn8nwpfff62jedHxEy3HiiTuEehrtnJEgjI3lUB5Ewx6HkBy56 X-Received: by 2002:a17:903:2f4c:b0:2a0:823f:4da6 with SMTP id d9443c01a7336-2a8d9a52635mr70579235ad.50.1769950521188; Sun, 01 Feb 2026 04:55:21 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Luigi Nardi Date: Sun, 1 Feb 2026 13:54:54 +0100 X-Gm-Features: AZwV_Qggm6LTfGRTXVyn9UvWrb-64Bwm8Rm_1JicRCchSYE9pzBb3fOslPVHdcY Message-ID: Subject: Re: Top -N Query performance issue and high CPU usage To: pgsql-general Content-Type: multipart/alternative; boundary="00000000000015f4520649c2b821" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --00000000000015f4520649c2b821 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Sat, Jan 31, 2026 at 10:05=E2=80=AFPM Ron Johnson wrote: > 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 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 requirement? and you normally d= o >> 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 shoul= d >> 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 pl= an >> , 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 it= s >> 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. >> > > The DBtune Free Edition can help you find the correct adjustments for work_mem and other server parameters . It's designed to help optimize your PostgreSQL runtime for your current hardware setup. > -- > Death to , and butter sauce. > Don't boil me, I'm still alive. > lobster! > --00000000000015f4520649c2b821 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable




The=C2=A0DBtune Free Edition=C2=A0can help you find the = correct adjustments for work_mem and=C2=A0other server parameters. It's designed to help optimize you= r PostgreSQL runtime for your current hardware setup.

=C2=A0
--
Death to <Redac= ted>, and butter sauce.
Don't boil me, I'm still alive.
<= div>
<Redacted> lobster!
--00000000000015f4520649c2b821--