Query sometimes takes down server - Mailing list pgsql-general

From Jason Long
Subject Query sometimes takes down server
Date
Msg-id 496FD875.6000805@supernovasoftware.com
Whole thread Raw
Responses Re: Query sometimes takes down server
Re: Query sometimes takes down server
List pgsql-general
I am having a serious problem with my application and I hope someone can
help me out.
This could not happen at a worse time as a consulting firm is at my
clients to recommend a new financial system and the inventory
system(which I developed) keeps locking up.

I have a dynamically built query that will periodically(2 times a day
and becoming more frequent) make my server totally unresponsive.

The query that hangs the system is requesting a count(*)
based on some parameters the users selects.

Since I set my timeout to 2 minutes(the only way I  have been able to
deal with this so far) I see the offending query in the log.

I took the query from the logs and pasted it into pgAdmin and ran it a
few times.

Sometime is takes 700-900 ms, but others it takes 60-100 seconds.
Other times it never stops(I waited 10 minutes).

If I run 10 times I get

8 less that 1 sec
2 5-10 sec

And maybe 1 in 20 will not complete.

Dev Server specs
1 CPU Xeon 5472 Quad core 3.0 GHz 1600MHz FSB
2x10k Raptor Raid 1
DB 50 mb with a lot of table joins

These queries are being run with nothing else running on the server.

My guess it that the planner is picking an inefficient plan sometimes.

I have not looked into the detail of the explain, and I do see visually
that very different plans are being chosen.

How can I see the plan that was chosen when the time it very high?
Is there a way to print the query plan chosen when the query times out
as well?





pgsql-general by date:

Previous
From: Justin Pasher
Date:
Subject: Re: Autovacuum daemon terminated by signal 11
Next
From: Jeff Davis
Date:
Subject: Re: Query sometimes takes down server