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 1t1eCX-00HF59-LY for pgsql-general@arkaria.postgresql.org; Fri, 18 Oct 2024 04:02:58 +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 1t1eCV-00Eu1b-BJ for pgsql-general@arkaria.postgresql.org; Fri, 18 Oct 2024 04:02:55 +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 1t1eCU-00Eu1S-N0 for pgsql-general@lists.postgresql.org; Fri, 18 Oct 2024 04:02:55 +0000 Received: from mail-pf1-x434.google.com ([2607:f8b0:4864:20::434]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1t1eCR-001TLw-8J for pgsql-general@lists.postgresql.org; Fri, 18 Oct 2024 04:02:53 +0000 Received: by mail-pf1-x434.google.com with SMTP id d2e1a72fcca58-71e74900866so1064777b3a.1 for ; Thu, 17 Oct 2024 21:02:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bitnine-net.20230601.gappssmtp.com; s=20230601; t=1729224170; x=1729828970; 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=moCAzzlcqPLKU8WPyJp2pZhrwyoeivMndisHAvkq3gI=; b=aRUarw6rVptIMQKeLGYRn0xgiH8JzcLP7irNYSWzL58+ubIbRxtF8UIhPMv9Lm98o1 IuKSiwEqklMrwtMbrw3TkuHi7AJIw2E8Ls8z8IilA5rW5CmvQF8DZhKbUqPaHbLi9LwC 4QBZsnmf+kej9MgReZMtQpntsaEwRcC+rtACqquKVPZWWHTcUTEkmiPMnnfI3XhKiMxa riyhOIXEXApLLTnbHrnDfX3vEc0rGtkWH6dD1kxAODSX74YzDdQykHGe9802p3ESjomc l3aXWEO1GnfOumg86MZHLERTARK9FZkj90ZgDuQ+zqifTsdYVJatXOsucyS2Avd6wreJ 4qzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729224170; x=1729828970; 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=moCAzzlcqPLKU8WPyJp2pZhrwyoeivMndisHAvkq3gI=; b=VNvTn4af04BOeoFMp1Zl+qPP4D7QhH5H+v0ldzxxLNEIFmE29b8cqLuMDPEUnWWivv fO0Lk3m5jxI5/eTlHWoZzyWmlamd1w2H7AIJV3VDWltGTiQjLh4SGku8d2beRxeTZ3PV YR/xzhhNbQL6lwPpvCEvywIYeBJ3IHPFIVb6SoZ/JvgcDnHnScP+qXq7OKWYiu0T1Ymw Vdex/ZgrHQpz5s51uZChAHqaWepVerElDu0G1AqwEd8fjlgE/BfVf/oNJfNL9c79m8Ak 2onG1KxUaPOZmNVcsmw89xXD5vntNnfyxa4PCEVsi3qsO1f0+RMNAucjv5LRZ1+yBTkr cqog== X-Gm-Message-State: AOJu0YzRGT97UVS3aZYxw5IqDKgkAm95dJsbHqcl0WVFdgx8hGUKMJ55 M4wKbhkuojp0ehlLBLw5Y7vQmXCa8blHSOCEwvNfVJ5UoA7iwflAlf0q98BjZD28BRQEPxKUAre VsDitoixmhehspZK84EHQk/hNImbWmSntQ0b8CA== X-Google-Smtp-Source: AGHT+IEO0r3msSP3MHf6W/fmwqJiKSNWyk8l+Qr07F+c2h/9leQ/VT2A6gvbSQNF+MfK5qHmf8m6mdJ47DIR9uob+OI= X-Received: by 2002:a05:6a00:18a7:b0:71e:79a8:1d84 with SMTP id d2e1a72fcca58-71ea32640e1mr2101373b3a.3.1729224169759; Thu, 17 Oct 2024 21:02:49 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Muhammad Usman Khan Date: Fri, 18 Oct 2024 09:02:39 +0500 Message-ID: Subject: Re: Performance difference between Primary & Secondary in the query execution To: Siraj G Cc: pgsql-general@lists.postgresql.org Content-Type: multipart/alternative; boundary="0000000000006047310624b86081" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000006047310624b86081 Content-Type: text/plain; charset="UTF-8" Hi, You can check and verify the following points: *Check the cpu resources on both primary and secondary *Check the execution plans on both the primary and secondary by running EXPLAIN (ANALYZE, BUFFERS) for the problematic queries like the following explain (analyze,buffers) select * from test ; QUERY PLAN ------------------------------------------------------------------------------------------------------------- Seq Scan on test (cost=0.00..22.70 rows=1270 width=36) (actual time=0.013..0.014 rows=1 loops=1) Buffers: shared hit=1 Planning: Buffers: shared hit=1 Planning Time: 0.082 ms Execution Time: 0.033 ms (6 rows) *check vacuuming and bloating using the following query select * from pg_stat_user_tables; select * from pg_stat_all_tables; *Check the shared_buffers, work_mem, and maintenance_work_mem settings on both instances. *Compare the disk I/O performance using the following query select * from pg_stat_bgwriter; *Check for any replication lag (pg_stat_replication on the primary) to ensure the secondary isn't falling behind. On Thu, 17 Oct 2024 at 19:08, Siraj G wrote: > Hello Experts! > > We have a PgSQL instance running with HA (secondary is being in sync with > streaming replication). Both the ends, we have same version, but not sure a > few SQLs behave badly in the secondary: > > Primary: > PostgreSQL 12.20 (Ubuntu 12.20-0ubuntu0.20.04.1) on x86_64-pc-linux-gnu, > compiled by gcc (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0, 64-bit > > OS: Ubuntu 20.04.6 LTS \n \l > > Secondary: > ostgreSQL 12.20 (Ubuntu 12.20-0ubuntu0.20.04.1) on x86_64-pc-linux-gnu, > compiled by gcc (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0, 64-bit > > OS: Ubuntu 20.04.6 LTS \n \l > > The application consumes more data from secondary, hence the server has > extra vCPUs. > > Can you please advise what needs to be checked. > > FYI, I am attaching the query with the different execution plans. > > Regards > Siraj > --0000000000006047310624b86081 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi,
You can check and ver= ify the following points:

*Check the cpu resources on both primary a= nd secondary
*Check the execution plans on both the primary and s= econdary by running EXPLAIN (ANALYZE, BUFFERS) for the problematic queries = like the following
explain (analyze,buffers) select * from test ;=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0QUERY PLAN
------------------------------= ---------------------------------------------------------------------------= ----
=C2=A0Seq Scan on test =C2=A0(cost=3D0.00..22.70 rows=3D1270 width= =3D36) (actual time=3D0.013..0.014 rows=3D1 loops=3D1)
=C2=A0 =C2=A0Buff= ers: shared hit=3D1
=C2=A0Planning:
=C2=A0 =C2=A0Buffers: shared hit= =3D1
=C2=A0Planning Time: 0.082 ms
=C2=A0Execution Time: 0.033 ms
= (6 rows)
*check vacuuming and bloating using the following qu= ery
select * from pg_stat_user_tables;
select * fro= m pg_stat_all_tables;
*Check the shared_buffers,= work_mem, and maintenance_work_mem settings on both instances.
*Compar= e the disk I/O performance using the following query
select * from pg_st= at_bgwriter;
*Check for any replication lag (pg_stat_replicat= ion on the primary) to ensure the secondary isn't falling behind.
=

= On Thu, 17 Oct 2024 at 19:08, Siraj G <tosiraj.g@gmail.com> wrote:
Hello Experts!

We have a PgSQL instance running with HA (secondary is being in sync with = streaming replication). Both the ends, we have same version, but not sure a= few SQLs behave badly in the secondary:

Primary:<= /div>
PostgreSQL 12.20 (Ubuntu 12.20-0ubuntu0.20.04.1) on x86_64-pc-lin= ux-gnu, compiled by gcc (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0, 64-bit
=

OS:=C2=A0Ubuntu 20.04.6 LTS \n \l

Se= condary:
ostgreSQL 12.20 (Ubuntu 12.20-0ubuntu0.20.04.1) on x86_6= 4-pc-linux-gnu, compiled by gcc (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0, 64-b= it

OS:=C2=A0Ubuntu 20.04.6 LTS \n \l

The application consumes more data from secondary, he= nce the server has extra vCPUs.

Can you please adv= ise what needs to be checked.

FYI, I am attaching = the query with the different execution plans.

Rega= rds
Siraj
--0000000000006047310624b86081--