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 1vmGpE-009hum-1S for pgsql-general@arkaria.postgresql.org; Sat, 31 Jan 2026 19:40:08 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vmGpA-008wG7-1K for pgsql-general@arkaria.postgresql.org; Sat, 31 Jan 2026 19:40:05 +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 1vmGp9-008wFx-2n for pgsql-general@lists.postgresql.org; Sat, 31 Jan 2026 19:40:04 +0000 Received: from mail-ej1-x635.google.com ([2a00:1450:4864:20::635]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vmGp8-000NO9-1K for pgsql-general@lists.postgresql.org; Sat, 31 Jan 2026 19:40:03 +0000 Received: by mail-ej1-x635.google.com with SMTP id a640c23a62f3a-b8de761c13eso351528766b.1 for ; Sat, 31 Jan 2026 11:40:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1769888400; cv=none; d=google.com; s=arc-20240605; b=VKfsnU/AygX0kO/1C9kb647GUPX1ay38UrsV2W/Pe/TtPe4992ZK6rgrBHdBG5BFay tBrUfQMRRfZzqXfEkrc/MjSxvC/4STcICz150fTrD4wuaQO9VhVZNeKMzjtgAmf884Su MMc1q6YFDHhpGNT/RxI7shtuNKDfp05hDa8i+F7cMgRPjyc+uyEtwsLcWdZuUefHkbXi LmyFUTVk8tjQrZsqUvg7vPlIOR32zP0qhlK7XHrmBR1b/x2kXTAaMXMyMsvvozIJs/4C +bafWn2itFMR0UgKisaGApmtbtb90khepbhuo9Z2HNDj4tP0doyyayM/g5R811YA5XmC D/xA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=zsP9xU0YzxqMxBu3k8VcR4DjS96dZjONM/oCy0adBmA=; fh=5Bds47lg1NlU1kMy8XwtfIHO/yqzLaWdGK2ckg7trmA=; b=lNFKf1mTFHAXUzU7TDd4NX68fU3hMAs/Kv+HgFFgr1H/DDeaR1p6wmh71JZBXeP6GM 5uBUzSAT5LTgjb9fH17HXHuCUE63kpcFs6LXV5Ul/ex/736QoxVML+u6ER2xMfzuvHw9 uLi0q+7x3ObZKprWWyZVZxDVPnT2EO1PbWn9Ff4xZiAp6adlidpSFp/uP1n8fObV1mbY HejKqwo7z+xxjVEYFxgwdDPVyw83LyrSuKU4t0slK2hSPR/VTYPwAf9Gv3oAyBvLDlIi 3KTjO7vxklX+eshhYCbLRpFwQyhOgq9vYPDMfVL06hIisPNuk+SucNT+q61Mf1rEN7Dm Jdfw==; 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=1769888400; x=1770493200; 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=zsP9xU0YzxqMxBu3k8VcR4DjS96dZjONM/oCy0adBmA=; b=TEDyrtT8NSumBU5pipwdGpm9KThXfpmYDa3I6Im9AWeKabGuhRIn+9ISvEt6J6v/et CtoaUOElOV40P8sgNTHA7wU28F8CA1FrjVoWkoDDrQ1624oTxT7i2jWl9y1N35Rmgoe6 SssBCwgz3JBALxt1tuIMnRdmMP6S0bI0nEGWrXoCddm05n9oupX2zWAtSEwZBNXFl5Rr 1hYdwF/F9N64jWV9peuVPZf/1JCSd64AFWrGkBFmdLlNpNbTFQ8cePdP5v8eHr/eFRhN oi/+kc/1o7voWIVMJoiU3txpPJqjZ93mey/J5fTHhOtpHD51VoKDZ4uUzInUULQVmb3b P4ew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769888400; x=1770493200; h=cc: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=zsP9xU0YzxqMxBu3k8VcR4DjS96dZjONM/oCy0adBmA=; b=WFhXlNOufqnZpQRbxWQVzkUKFS4mzSRXJCQGtyolnuT65YjBPe8Lo8e+TuO0WKC2+D K8enSuo+39VXDl6owe/K6htQsfSbFcT687KnH1WB/xW1CrP//w+t2hZK5S/3g0mrF44v ks/X7oMTvTA6+XmgLiofUtZ1C9DiatmhL08xMOqd4FPxImq1Xet1giiahHEU96KpuM+h SbZVEfaAqhQk+d6mPt26esRh9hmsXTAq6tz6z3y38QPibD6L2QKD0JAqIvftwL2kPiI+ oS7kq95FccbYLFiKsr/jdD07iy3bloLF4iESlilakpN1uk1QQPWsoSGVYl/rQpGLH6ZP nzKQ== X-Gm-Message-State: AOJu0YxaYftVKqi8mbhzqKyvUecZdF2f/OBvsYzuzuq/Avpgl0A6sh1T Pppe++hXmw/SGieZq0oKA1GMXLETu2F1n2NNfY5SiBddVTWXRcDW4HWQ0WncfRYXhdcAW8JLL5l QowTlsZq5D/hbDLrzmqM9WtLPPp05A7I= X-Gm-Gg: AZuq6aLJwP38Qz2Gdf9q9BlKAOdjolQHlNzHzNclEmUHpiRNfxHmBWD1TnztGam7gGF baWk0SDuTHjFzwt9rsJ6e/1ZYmmeEpZ4skjfHV61QwENZaRx/VUW3lIWfkLQrrKmbni4TDFX7XV 8R8PVyC4iJ5fIIb1Cn/Nn0UExpyW88GhRJin/zmVLYKTYL9jtV4W/msARS66rw/8jOWJt4J/Lol vuGWXU7m2V7mKQhnbLVxnu+EvOnOjndNbMlMtACm/UEpEuoeflaRsi8TZZ+iA1KiXW23oqp74wR RC9Us/juACJOyl5E/JiLxUvs X-Received: by 2002:a17:907:e84a:b0:b88:31c1:c76e with SMTP id a640c23a62f3a-b8dff5b8612mr378246866b.16.1769888399914; Sat, 31 Jan 2026 11:39:59 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: yudhi s Date: Sun, 1 Feb 2026 01:09:47 +0530 X-Gm-Features: AZwV_QhxTHq7umFgauGQewJ3QUR11NWg7WVjqNWGuE9bAbsIp1UrlL_420xDFtM Message-ID: Subject: Re: Top -N Query performance issue and high CPU usage To: David Mullineux Cc: pgsql-general Content-Type: multipart/alternative; boundary="0000000000005e7b890649b44149" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000005e7b890649b44149 Content-Type: text/plain; charset="UTF-8" > > >> > Plan says it's using temp files for sorting....I would suggest you > increase work_mem for this to avoid temp.fike creation...Although not the > answer to all your problems, it would be a good start . > > Even setting work_mem to 64MB remove all the "temp read" and showig all memory reads, but still we are seeing similar cpu spike when executing this query from multiple sessions and also the response time is staying same. --0000000000005e7b890649b44149 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


Plan says it's using temp files for sorting....I would s= uggest you increase work_mem for this to avoid temp.fike creation...Althoug= h not the answer to all your problems, it would be a good start .


Even setting= work_mem to 64MB remove all the "temp read" and showig all memor= y reads, but still we are seeing similar cpu spike when executing this quer= y from multiple sessions and also the response time is staying same.=C2=A0<= /div>
--0000000000005e7b890649b44149--