473,564 Members | 2,730 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Same conditions, different planning?



Hi
I'm having serious problems with a mission critical app that runs on
postgres (and has been running for the past 3 years). It's rather large,
and lately things are not going well. The planner is getting 'nuts',
choosing ways that never end and completly stops the database.
The strange thing is that running the same query with the same database
with the same conditions in other machine the planner works as expecter and
all goes well.
All is vaccumed analyzed.
What can cause this?
Tkx


--
Pedro Miguel G. Alves pm*****@think.p t
THINK - Tecnologias de Informação www.think.pt
Tel: +351 21 413 46 00 Av. José Gomes Ferreira
Fax: +351 21 413 46 09 nº 13 1495-139 ALGÉS

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Nov 12 '05 #1
6 1696
Pedro Alves wrote:
I'm having serious problems with a mission critical app that runs on
postgres (and has been running for the past 3 years). It's rather large,
and lately things are not going well. The planner is getting 'nuts',
choosing ways that never end and completly stops the database.
The strange thing is that running the same query with the same database
with the same conditions in other machine the planner works as expecter and
all goes well.


Can we see explain analyze for the queries, relevant schema and other details?

And what version of postgresql is this? On what platform?

Shridhar

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddres sHere" to ma*******@postg resql.org)

Nov 12 '05 #2
On Wed, Oct 22, 2003 at 04:13:45PM +0530, Shridhar Daithankar wrote:
Pedro Alves wrote:
I'm having serious problems with a mission critical app that runs on
postgres (and has been running for the past 3 years). It's rather large,
and lately things are not going well. The planner is getting 'nuts',
choosing ways that never end and completly stops the database.
The strange thing is that running the same query with the same database
with the same conditions in other machine the planner works as expecter and
all goes well.


Can we see explain analyze for the queries, relevant schema and other
details?

And what version of postgresql is this? On what platform?


Both machines Linux, 7.3.4 (different dists, but it doesn't matter, I
think)

Query:
SELECT ra.ra_id, ra.ra_reqnum, ra.ra_datacolh, to_char(timesta mp_num,'YYYY-MM-DD'),to_char(ti mestamp_num,'HH 24:MI'), ra.ra_servico, ra.ra_urgente, ra.ra_produto, ra.ra_cama, ra.ra_parcial, ra.ra_vglobal, servico.s_id, servico.s_desc ,ut.ut_id, ut.ut_nome, ut.ut_sexo,ut.u t_data_nasc,ra. ra_modulo, ra.ra_relcolh, ra.ra_notamedic a,ra.ra_utiliza dor FROM Servico servico,Requisi caoAnalise ra, Utente ut WHERE ut.ut_id=ra.ra_ utente AND ra.ra_servreq=s ervico.s_id and ra.ra_servico = 1 AND ra_datacolh <='2003-10-22' AND ra.isactive=1 order by ra_reqnum desc LIMIT 80 OFFSET 0;))
Machine 1 (production):

Limit (cost=2193.79.. 2193.99 rows=80 width=156)
-> Sort (cost=2193.79.. 2194.32 rows=212 width=156)
Sort Key: ra.ra_reqnum
-> Hash Join (cost=970.41..2 185.62 rows=212 width=156)
Hash Cond: ("outer".ra_ser vreq = "inner".s_i d)
-> Merge Join (cost=968.75..2 180.25 rows=212 width=134)
Merge Cond: ("outer".ut_ id = "inner".ra_uten te)
-> Index Scan using utente_pkey on utente ut (cost=0.00..110 9.18 rows=38937 width=43)
-> Sort (cost=968.75..9 69.97 rows=486 width=91)
Sort Key: ra.ra_utente
-> Index Scan using ra_isactive on
requisicaoanali se ra (cost=0.00..947 .07 rows=486 width=91)
Index Cond: (isactive = 1)
Filter: ((ra_servico = 1) AND (ra_datacolh <= '2003-10-22'::date))
-> Hash (cost=1.53..1.5 3 rows=53 width=22)
-> Seq Scan on servico (cost=0.00..1.5 3 rows=53
width=22)
(15 rows)
Machine 2 (my develop machine):

Limit (cost=74.47..74 .51 rows=19 width=156)
-> Sort (cost=74.47..74 .51 rows=19 width=156)
Sort Key: ra.ra_reqnum
-> Hash Join (cost=1.66..74. 05 rows=19 width=156)
Hash Cond: ("outer".ra_ser vreq = "inner".s_i d)
-> Nested Loop (cost=0.00..72. 05 rows=19 width=134)
-> Index Scan using ra_isactive on requisicaoanali se
ra (cost=0.00..5.0 9 rows=19 width=91)
Index Cond: (isactive = 1)
Filter: ((ra_servico = 1) AND (ra_datacolh <=
'2003-10-22'::date))
-> Index Scan using utente_pkey on utente ut (cost=0.00..3.4 3 rows=1 width=43)
Index Cond: (ut.ut_id = "outer".ra_uten te)
-> Hash (cost=1.53..1.5 3 rows=53 width=22)
-> Seq Scan on servico (cost=0.00..1.5 3 rows=53
width=22)
(13 rows)

Some other relevant info:

select count(*) from requisicaoanali se;
count
--------
176328

select count(*) from utente;
count
-------
38868
Digging a bit more I find this:

Machine 1:

explain select count(*) from requisicaoanali se where isactive = 1 AND
(ra_servico = 4) AND (ra_datacolh <= '2003-10-22'::date);
QUERY PLAN
-----------------------------------------------------------------------------------------------
Aggregate (cost=948.45..9 48.45 rows=1 width=0)
-> Index Scan using ra_isactive on requisicaoanali se
(cost=0.00..947 .07 rows=550 width=0)
Index Cond: (isactive = 1)
Filter: ((ra_servico = 4) AND (ra_datacolh <= '2003-10-22'::date))
(4 rows)
Machine 2:

explain select count(*) from requisicaoanali se where isactive = 1 AND
(ra_servico = 4) AND (ra_datacolh <= '2003-10-22'::date);
QUERY PLAN
--------------------------------------------------------------------------------------------
Aggregate (cost=5.12..5.1 2 rows=1 width=0)
-> Index Scan using ra_isactive on requisicaoanali se (cost=0.00..5.0 9
rows=12 width=0)
Index Cond: (isactive = 1)
Filter: ((ra_servico = 4) AND (ra_datacolh <= '2003-10-22'::date))
How can I have such different costs?!?!?!


--
Pedro Miguel G. Alves pm*****@think.p t
THINK - Tecnologias de Informação www.think.pt
Tel: +351 21 413 46 00 Av. José Gomes Ferreira
Fax: +351 21 413 46 09 nº 13 1495-139 ALGÉS

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postg resql.org so that your
message can get through to the mailing list cleanly

Nov 12 '05 #3
On Wednesday 22 October 2003 16:25, Pedro Alves wrote:
Machine 1:

explain select count(*) from requisicaoanali se where isactive = 1 AND
(ra_servico = 4) AND (ra_datacolh <= '2003-10-22'::date);
QUERY PLAN
---------------------------------------------------------------------------
-------------------- Aggregate (cost=948.45..9 48.45 rows=1 width=0)
-> Index Scan using ra_isactive on requisicaoanali se
(cost=0.00..947 .07 rows=550 width=0)
Index Cond: (isactive = 1)
Filter: ((ra_servico = 4) AND (ra_datacolh <= '2003-10-22'::date))
(4 rows)


Could you please run explain analyze rather than just explain for all the
things you posted earlier?

And are there any tuning parameters different on these two machines? RAM size
of HDD setup etc?

Are these two machine absolutely same from hardware and postgresql tuning
point of view?

Shridhar
---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Nov 12 '05 #4


As a final attempt I tryed a pg_dumpall; initdb; psql -f <file> . It
seems to work as expected.... (!)


On Wed, Oct 22, 2003 at 05:03:32PM +0530, Shridhar Daithankar wrote:
On Wednesday 22 October 2003 16:25, Pedro Alves wrote:
Machine 1:

explain select count(*) from requisicaoanali se where isactive = 1 AND
(ra_servico = 4) AND (ra_datacolh <= '2003-10-22'::date);
QUERY PLAN
---------------------------------------------------------------------------
-------------------- Aggregate (cost=948.45..9 48.45 rows=1 width=0)
-> Index Scan using ra_isactive on requisicaoanali se
(cost=0.00..947 .07 rows=550 width=0)
Index Cond: (isactive = 1)
Filter: ((ra_servico = 4) AND (ra_datacolh <= '2003-10-22'::date))
(4 rows)


Could you please run explain analyze rather than just explain for all the
things you posted earlier?

And are there any tuning parameters different on these two machines? RAM size
of HDD setup etc?

Are these two machine absolutely same from hardware and postgresql tuning
point of view?

Shridhar
---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html


--
Pedro Miguel G. Alves pm*****@think.p t
THINK - Tecnologias de Informação www.think.pt
Tel: +351 21 413 46 00 Av. José Gomes Ferreira
Fax: +351 21 413 46 09 nº 13 1495-139 ALGÉS

---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

Nov 12 '05 #5
Pedro Alves <pm*****@think. pt> writes:
As a final attempt I tryed a pg_dumpall; initdb; psql -f <file> . It
seems to work as expected.... (!)


It may have been a case of index bloat--did you ever REINDEX? That
might have fixed it without a dump/reload.

7.4 has fixes for the index bloat problem.

-Doug

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Nov 12 '05 #6

Hum... no, I didn't :/ I thought vacuum analyze would be enough. Next
time (neve, I hope) I will have that in mind

On Wed, Oct 22, 2003 at 08:36:10AM -0400, Doug McNaught wrote:
Pedro Alves <pm*****@think. pt> writes:
As a final attempt I tryed a pg_dumpall; initdb; psql -f <file> . It
seems to work as expected.... (!)


It may have been a case of index bloat--did you ever REINDEX? That
might have fixed it without a dump/reload.

7.4 has fixes for the index bloat problem.

-Doug

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend


--
Pedro Miguel G. Alves pm*****@think.p t
THINK - Tecnologias de Informação www.think.pt
Tel: +351 21 413 46 00 Av. José Gomes Ferreira
Fax: +351 21 413 46 09 nº 13 1495-139 ALGÉS

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Nov 12 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
5281
by: bart_nessux | last post by:
I need a script to call several functions at the same time. How does one call more than one function simultaneously?
1
4465
by: Jo | last post by:
I am having a real problem with the Launch conditions in VS .NET and can only come to the conclusion that it is a bug. It states quite emphatically in the MSDN that Launch Conditions WILL be executed in the order added. This statement holds true if every Condition has a InstallURL value set. but not if there is no InstallURL value. For...
1
1260
by: usl2222 | last post by:
Hi, I'm building this web application using asp.net and c# as code behind. Currently I save all my session data in session variables. One of the things that this application must do, is to invoke another instance of the same application, with different parameters, of course. Then the second invokation can potentially couse a third...
15
1563
by: iwdu15 | last post by:
hi, i have these 2 code snippets: Public Sub ImRec(ByVal IM As IAccIm, ByVal Sender As IAccUser) Dim str As String = IM.GetConvertedText(DECODE) Dim temp As String = str temp = temp.Remove(temp.IndexOf("<body>"), 6) temp = temp.Remove(temp.IndexOf("</body>"), 7)
11
1922
by: dgk | last post by:
If I have a class with a public variable, isn't this the same as a private variable with a property? ie, isn't this: Public Class MyTest Public MyVar as String End Class the same as this: Public Class MyTest
1
4191
by: ajayvaram | last post by:
<?xml version="1.0" encoding="utf-8"?> <CategoryList> <Category ID="01" Title="One"> </Category> <Category ID="03" Title="Three"> </Category> <Category ID="04" Title="Four"> <Style Color="Red" > <Car Name="R"/> </Style>
4
2613
by: dsdevonsomer | last post by:
Hello, I have one simple query joining two tables with left outer join on 3 fields and using MIN on two fields. These two tables have lot of data about 3 mil in total. I am trying to migrate db from MS Access to SQL 2005. I get about 689000 rows in SQL Server, vs 863000 rows in MS Access. SELECT T1., T1., T2., MIN ( T1.), MIN(T1. ),...
12
25077
by: =?ISO-8859-1?Q?Ren=E9?= | last post by:
Hi, is there a rule of thumb what is better/faster/more performant in SQL Server 2005? a) SELECT * FROM A INNER JOIN B ON B.ID = A.ID AND B.Cond1 = 1 AND B.Cond2 = 2 b) SELECT * FROM A INNER JOIN B ON B.ID = A.ID WHERE B.Cond1 = 1 AND B.Cond2 = 2
4
2275
by: Prashanth Kumar B R | last post by:
Hi, I have situation in C++ where in I'll have to add around 20-25 conditions <compare a variable against a number> to an if statement. Is there any limit on the number of expressions/conditions to be added to an if statement. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ sample code....
0
7666
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7888
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8108
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7951
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6260
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5484
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1201
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
925
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.