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 1tP2XT-009qGk-3w for pgsql-performance@arkaria.postgresql.org; Sat, 21 Dec 2024 16:41:15 +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 1tP2XS-00ALJe-Ew for pgsql-performance@arkaria.postgresql.org; Sat, 21 Dec 2024 16:41:14 +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 1tP2XS-00ALJW-4B for pgsql-performance@lists.postgresql.org; Sat, 21 Dec 2024 16:41:13 +0000 Received: from mail-oi1-x230.google.com ([2607:f8b0:4864:20::230]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1tP2XL-000vZe-AF for pgsql-performance@lists.postgresql.org; Sat, 21 Dec 2024 16:41:13 +0000 Received: by mail-oi1-x230.google.com with SMTP id 5614622812f47-3eb939021bfso1479766b6e.3 for ; Sat, 21 Dec 2024 08:41:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734799266; x=1735404066; 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=ZQKAB1XiOxA3U5xO82WWuCnifrntbJOZR7CbrfxJI/0=; b=Yv9dajJy5wluPt6Z9jN06Qgf/7e0aiya57zksg5cTxjhM94tF5kRxeE6Im19HWu416 RE8HsODJ+F9inn3j/yrB38n1cWh2/O9rxObGnocA+x1i14MRTEUUZKV1zfnILWjjAJMt KTZ5YqAO0aP6p2yHplA3OM95ve1w7k2oEuUUDuS4bTTjzU+vQT27Nd+Y3TCQCJc4gvC+ gPJhln1etd9hT5TqRubiLFe4b0F2g/ipOTBifpBN+A7dFQb7BPK2tBo04jpYDwQ+ISl0 PhPMpJBPiLMBLHGiW13i+6+UfOQBNS+AhzAKC80+R+ekZn2AfTBI6CKonDe7bSx2B+/3 yxBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734799266; x=1735404066; 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=ZQKAB1XiOxA3U5xO82WWuCnifrntbJOZR7CbrfxJI/0=; b=XSZhInO+EXjrzEh90U8yd4AIA9jS85vuevfVP1QXtBE5QApXaAFZvbe1ALKfNSSKIW 3L7kYlQPj+heFKYiVrwUvZIdABdIPS3b8avf4rAvFJ5yGb8dHpA6/iFuNuiMuGO03YFU h1slCrWiPxJFI8gGzTT5I9RhBK9migjqIsVk+iWihElitPk0y2LsmY5YYPDNTzhlQlW1 5d/DcgXVZE7d4DJYpaJ8KRRzE12BB6D28tNtWCEKoL01EoL6PGpgoIglHJ3btQ85fJQC 4mPHS7adpEJzYIRKKraSzJ5mxzSEAF8W87szVhlIO1anC4hXdt0ySY5E6zzZq4e5IWLz zpGA== X-Gm-Message-State: AOJu0YzyFLaGVh+rRCSWy0knnc0oNVfo+3Z6PnMbS/Sb4e0//IkqXxOK cPLXdYFrwIPn4pIXjpRHqoiCz42ZA/lAfnykpkYoAIJNnq+EGeDrNmbW1HgnnFe8rI8dDkbZDv7 R8O6O/apU2j+9FBKF7CpUaBxLOYo= X-Gm-Gg: ASbGnctHilvXhsRbtQNeTqKgO6sXo7PcXut2T9snW7qMieXje2BOYkQJZomTfm3fOm+ RbWoK3l4s4rEkgEA88KGWLgybUv6ZJGE2gJ6Vkg== X-Google-Smtp-Source: AGHT+IEdI2BrtlAHrhOyLH6DTjkGjaJTZO5YV6VSTszcn6x/5OkPMI9zg+dWe5Vwhtu6GWLoiP0FOj2Pwth1nDbAOaA= X-Received: by 2002:a05:6808:1206:b0:3e7:b9be:5267 with SMTP id 5614622812f47-3ed88eb680cmr5291471b6e.6.1734799265775; Sat, 21 Dec 2024 08:41:05 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: David Mullineux Date: Sat, 21 Dec 2024 16:40:54 +0000 Message-ID: Subject: Re: huge shared_blocks_hit one select but manually run very fast To: James Pang Cc: pgsql-performance@lists.postgresql.org Content-Type: multipart/alternative; boundary="000000000000fe45b30629ca6d00" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000fe45b30629ca6d00 Content-Type: text/plain; charset="UTF-8" Depends on a lot of thongs...Visibility map sounds like it's impacted here. Are your inserts towards the index (like a monotonically increasing serial id) or scattered around the index values ? How big is the table index and shared buffers ? An example would really help On Sat, 21 Dec 2024, 11:51 James Pang, wrote: > Hi, > we have a simple select .... from table where ... (that mache the > index) , table has 80million rows. when many application sessions run the > query and at the same time some other sessions doing insert into ... this > table. from pg_stat_statements, shared_blks_hit show 31652 / per call. we > see very high cpu almost 100% cpu during application workload test, and > high LWLock BufferMapping waiting for these querys. But manually run the > sql show only 2148 shared_blks_hit/ per call. this is a simple sql, from > pg_profile we did see it use same index scan as manually running. What > could be possible reason leading so big difference with shared_blks_hit ? > PGv14.8 > > Thanks, > > James > --000000000000fe45b30629ca6d00 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Depends on a lot of thongs...Visibility map sounds like it&#= 39;s impacted here. Are your inserts towards the index (like a monotonicall= y increasing serial id)=C2=A0 or scattered around the index values ?=C2=A0= =C2=A0 How big is the table=C2=A0 index and shared buffers ?=C2=A0=C2=A0 An= example would really help


On Sat, 21 Dec 2024, 11:51 James Pang, <jamespang886@gmail.com> wrote:
Hi,=C2=A0
=C2=A0 =C2=A0we= have a simple select .... from table where ... (that mache the index) , ta= ble has 80million rows.=C2=A0 when many application sessions run the query = and at the same time some other sessions doing insert into ... this table. = from pg_stat_statements, shared_blks_hit show 31652 / per call.=C2=A0 =C2= =A0we see very high cpu almost 100% cpu during application workload test, a= nd high LWLock=C2=A0BufferMapping waiting for these querys.=C2=A0 But manua= lly=C2=A0run the sql show only 2148 shared_blks_hit/ per call.=C2=A0 this i= s a simple sql, from pg_profile we did see it use same index scan as manual= ly=C2=A0running.=C2=A0 What could be possible reason leading so big differe= nce with shared_blks_hit ?=C2=A0=C2=A0
=C2=A0PGv14.8=C2=A0
<= div>
Thanks,

James
--000000000000fe45b30629ca6d00--