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 1sXHRn-002xNd-33 for pgsql-general@arkaria.postgresql.org; Fri, 26 Jul 2024 09:41:11 +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 1sXHRl-00957a-8B for pgsql-general@arkaria.postgresql.org; Fri, 26 Jul 2024 09:41:09 +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 1sXHRk-00957Q-Of for pgsql-general@lists.postgresql.org; Fri, 26 Jul 2024 09:41:08 +0000 Received: from mail-oa1-x2a.google.com ([2001:4860:4864:20::2a]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sXHRi-001Wq2-0y for pgsql-general@lists.postgresql.org; Fri, 26 Jul 2024 09:41:07 +0000 Received: by mail-oa1-x2a.google.com with SMTP id 586e51a60fabf-250ca14422aso663288fac.0 for ; Fri, 26 Jul 2024 02:41:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721986865; x=1722591665; 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=9Arhsu1XJ5LMHxQKv94zMH6CxWmpXd4Vf6/0tab/CvE=; b=jgsHtB/zORhaAjGkwVTRN0Unzfn/E0n3YpeeS63bJ/i7KinkrEddrjsnJEMWClwbH4 2EhrXwt3Zm2kExf8HXeCmZH+vCNfuEzyBzJMUZPD01ttgkvu8H/58SB1IVywRSh1K7av IoyQI1EqMjThnbZm4xlyompE2V6LuswNn/XeFP5aoSuGz/vgL0I9AAiIOvxge8iq6Jr+ 1xfkx1BsA7aSNwdFxwV/C1LxOQ1QoHZLR9zozYyFlk88xqsaLpKMdesF43mzZewrv1Gw 7q7OB/NH5qU5M5cAo+gVU6rJtZ0ghXfMAeNBkLhSDeWJBzH+5ottDlAkb1vTgTs3R8wn /zRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721986865; x=1722591665; 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=9Arhsu1XJ5LMHxQKv94zMH6CxWmpXd4Vf6/0tab/CvE=; b=tP3sP1Q5OpfVMVUdb+2aJ2QquPMHitu/kShLNFim/J+36+N+Aob8s6f3299gJicZQu rp5tydpBdBPhqTPewGe1duwJDrDipWrz8nzPmO6CgRnyBNBsYQkWRYGHZuy+a/pwYNut R+/JaTr2KelOQifbxQ+ZNwsDG6YZKKfsvKsmjpob+uKLBsCPVHa9ZlUZ0VsQ1ij3G2Ql SCkp5aRdxYAYMkS3NRwp67U3+BRHCXQWMsh0MRNQiDXk8bgBLJWEpYFt2PrtMV7dOWMS BeY5mui70WtuyRtkFYZAR6TGhl81hFt/fRcMvS1i0k7dcl/I1CddMeuV2ZwpCk6r2WLQ Cowg== X-Gm-Message-State: AOJu0YzCdU8wYENUuR/lmi60SDT2zDIUAG18bgr7IhKUYrQOIHEkdOJZ KwlcfhHunkjXkhdxWvEmmeIjmu5sVM2KMVaQcwwkQ6XD1v+MhKFkIBBnGsorg3olu8zeCozGA/V +zTr0YSXnLHVqeC8m3s22mXW9VwmHzohZ X-Google-Smtp-Source: AGHT+IG9uxDKc50K03bxgA8f9iO1V6VdcvrQSU8shAbAwQ/0L29udLUw4ZeYxJsZE/tL+V1WumCFoo506g+Q/1S9hhg= X-Received: by 2002:a05:6871:72a:b0:260:ff24:fb32 with SMTP id 586e51a60fabf-264a0c355dcmr6761848fac.1.1721986865265; Fri, 26 Jul 2024 02:41:05 -0700 (PDT) MIME-Version: 1.0 References: <431223779.107307.1721971823963.ref@mail.yahoo.com> <431223779.107307.1721971823963@mail.yahoo.com> In-Reply-To: From: Fatih Sazan Date: Fri, 26 Jul 2024 12:40:53 +0300 Message-ID: Subject: Re: Slow performance To: "sivapostgres@yahoo.com" Cc: Postgresql General Group Content-Type: multipart/alternative; boundary="000000000000698798061e234f63" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000698798061e234f63 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Siva, pg_dump taken from client_db seems not to have transferred full data to client_test. When I examine the query plans, the rows scanned seem to be extremely different. For example, there is 1 row in cl_level table on client_test, while clined_db shows that around 300,000 records were scanned. My suggestion would be to check the data counts in the tables you moved with count(*). Francisco Olarte , 26 Tem 2024 Cum, 10:55 tarihinde =C5=9Funu yazd=C4=B1: > Hello: > > On Fri, 26 Jul 2024 at 07:31, sivapostgres@yahoo.com > wrote: > ... > > Took backup (pg_dump) of first database (client_db) and restored the > database as second database (client_test). > ... > > The query when run against DB1 takes around 7 min 32 seconds. > > The same query when run against DB2 takes around 124 msec. > > Same computer, same PG cluster, same query. > > Why it takes so much time when run against DB1 (client_db)? > > Can be bad luck, but the usual suspect would be different databases. > > I assume db1 is quiescent on the tests ( as it seems the production > database, no heavy querying concurrent with your tests ). > > Bear in mind restoring leaves the database similar to what a vacuum > full will do, so it can differ a lot from the original. > > > Already executed vacuum against client_db database. > > I think you already have pointed out this, but IIRC you have not told > us if you have ANALYZED any of the databases. This is important. Bad > stats in any of them could make the planner choose a bad plan ( or, if > you are unlucky, make it choose a bad one ). > > Also, did you vacuum verbose? where your tables well packed? ( bad > vacuuming can lead to huge tables with a lot of free space, but I > doubt this is your case, but everything has to be checked, we only > know what you write us ). > > And now, not being an expert in tracing explain I see this in plan-db1: > " Join Filter: (((b.registrationnumber)::text =3D > (p.registrationnumber)::text) AND ((c.subjectcode)::text =3D > (p.subjectcode)::text) AND (a.semester =3D p.semester))" > " Rows Removed by Join Filter: 13614738" > " -> Index Scan using > ""cl_student_semester_subject_IX3"" on cl_student_semester_subject p > (cost=3D0.55..8.57 rows=3D1 width=3D60) (actual time=3D0.033..55.702 > rows=3D41764 loops=3D1)" > " Index Cond: (((companycode)::text =3D '100'::text) > AND ((examheaderfk)::text =3D > 'BA80952CFF8F4E1C3F9F44B62ED9BF37'::text))" > > Not an explain expert, but if i read correctly an index scan expecting > 1 row recovers 41674, which hints at bad statistics ( or skewed data > distribution and bad luck ) > > The plans are similar, but in the fast query > cl_student_semester_subject is accessed using other index: > > " -> Index Scan using > ""cl_student_semester_subject_IX1"" on cl_student_semester_subject p > (cost=3D0.42..3.09 rows=3D1 width=3D60) (actual time=3D0.010..0.010 rows= =3D1 > loops=3D326)" > " Index Cond: (((companycode)::text =3D '100'::text) > AND ((subjectcode)::text =3D (a.subjectcode)::text) AND > ((registrationnumber)::text =3D (a.registrationnumber)::text) AND > (semester =3D a.semester))" > > Which seems much more selective and recovers just what it wants. > > I would start by analyzing ( and, if not too costly, reindexing ) that > table. > > Francisco Olarte. > > > --000000000000698798061e234f63 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi Siva,

pg_dump taken from client_db s= eems not to have transferred full data to client_test.

When I examin= e the query plans, the rows scanned seem to be extremely different. For exa= mple, there is 1 row in cl_level table on client_test, while clined_db show= s that around 300,000 records were scanned.

My suggestion would be t= o check the data counts in the tables you moved with count(*).




Francisco Olarte <folarte@peoplecall.com>, 26 Tem 2024 C= um, 10:55 tarihinde =C5=9Funu yazd=C4=B1:
Hello:

On Fri, 26 Jul 2024 at 07:31, sivapostgres@yahoo.com
<sivapostgre= s@yahoo.com> wrote:
...
> Took backup (pg_dump) of first database (client_db) and restored the d= atabase as second database (client_test).
...
> The query when run against DB1 takes around 7 min 32 seconds.
> The same query when run against DB2 takes around 124 msec.
> Same computer, same PG cluster, same query.
> Why it takes so much time when run against DB1 (client_db)?

Can be bad luck, but the usual suspect would be different databases.

I assume db1 is quiescent on the tests ( as it seems the production
database, no heavy querying concurrent with your tests ).

Bear in mind restoring leaves the database similar to what a vacuum
full will do, so it can differ a lot from the original.

> Already executed vacuum against client_db database.

I think you already have pointed out this, but IIRC you have not told
us if you have ANALYZED any of the databases. This is important. Bad
stats in any of them could make the planner choose a bad plan ( or, if
you are unlucky, make it choose a bad one ).

Also, did you vacuum verbose? where your tables well packed? ( bad
vacuuming can lead to huge tables with a lot of free space, but I
doubt this is your case, but everything has to be checked, we only
know what you write us ).

And now, not being an expert in tracing explain I see this in plan-db1:
"=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 Join Filter: (((b.re= gistrationnumber)::text =3D
(p.registrationnumber)::text) AND ((c.subjectcode)::text =3D
(p.subjectcode)::text) AND (a.semester =3D p.semester))"
"=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 Rows Removed by Join= Filter: 13614738"
"=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ->=C2=A0 Index Sc= an using
""cl_student_semester_subject_IX3"" on cl_student_semes= ter_subject p
(cost=3D0.55..8.57 rows=3D1 width=3D60) (actual time=3D0.033..55.702
rows=3D41764 loops=3D1)"
"=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= Index Cond: (((companycode)::text =3D '100'::text)
AND ((examheaderfk)::text =3D
'BA80952CFF8F4E1C3F9F44B62ED9BF37'::text))"

Not an explain expert, but if i read correctly an index scan expecting
1 row recovers 41674, which hints at bad statistics ( or skewed data
distribution and bad luck )

The plans are similar, but in the fast query
cl_student_semester_subject is accessed using other index:

"=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ->=C2=A0 Index Sc= an using
""cl_student_semester_subject_IX1"" on cl_student_semes= ter_subject p
(cost=3D0.42..3.09 rows=3D1 width=3D60) (actual time=3D0.010..0.010 rows=3D= 1
loops=3D326)"
"=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= Index Cond: (((companycode)::text =3D '100'::text)
AND ((subjectcode)::text =3D (a.subjectcode)::text) AND
((registrationnumber)::text =3D (a.registrationnumber)::text) AND
(semester =3D a.semester))"

Which seems much more selective and recovers just what it wants.

I would start by analyzing ( and, if not too costly, reindexing ) that tabl= e.

Francisco Olarte.


--000000000000698798061e234f63--