Re: implementing query timeout

Started by Bruce Momjianabout 24 years ago12 messagespatches
Jump to latest
#1Bruce Momjian
bruce@momjian.us

Here is my first draft of a query timeout SET variable. It works for a
simple test:

test=> set query_timeout to '2000';
SET
test=> select * from pg_class, pg_type;
ERROR: Query was cancelled.
test=>

I still need to polish it up and do more testing. Can people comment on
the proper placement of the disable_sig_alarm(true) calls? Also, the
handling of the alarm is tricky because the deadlock timer uses the
alarm as well and the query_timeout. (I have not gotten all the cases
correct yet.)

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026

Attachments:

/bjm/difftext/plainDownload+195-83
#2Peter Eisentraut
peter_e@gmx.net
In reply to: Bruce Momjian (#1)

Bruce Momjian writes:

Here is my first draft of a query timeout SET variable.

Unless it only cancels SELECT statements (which may or may not be a good
idea), please call it statement_timeout.

--
Peter Eisentraut peter_e@gmx.net

#3Bruce Momjian
bruce@momjian.us
In reply to: Peter Eisentraut (#2)

Peter Eisentraut wrote:

Bruce Momjian writes:

Here is my first draft of a query timeout SET variable.

Unless it only cancels SELECT statements (which may or may not be a good
idea), please call it statement_timeout.

Woh, you mean only SELECT is a query? Why is it SQL? Do we not use
'query' to mean any SQL command?

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026
#4Bruce Momjian
bruce@momjian.us
In reply to: Peter Eisentraut (#2)

Peter Eisentraut wrote:

Bruce Momjian writes:

Here is my first draft of a query timeout SET variable.

Unless it only cancels SELECT statements (which may or may not be a good
idea), please call it statement_timeout.

Do people prefer query_timeout or statement_timeout? Doesn't matter to
me.

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026
#5Rod Taylor
rbt@rbt.ca
In reply to: Bruce Momjian (#4)

On Wed, 2002-07-10 at 18:52, Bruce Momjian wrote:

Peter Eisentraut wrote:

Bruce Momjian writes:

Here is my first draft of a query timeout SET variable.

Unless it only cancels SELECT statements (which may or may not be a good
idea), please call it statement_timeout.

Do people prefer query_timeout or statement_timeout? Doesn't matter to
me.

There is no 'statement' in SQL, that said, 75% of SQL has nothing to do
with queries.

So... I think I vote 'statement'.

#6Jan Wieck
JanWieck@Yahoo.com
In reply to: Bruce Momjian (#4)

Bruce Momjian wrote:

Peter Eisentraut wrote:

Bruce Momjian writes:

Here is my first draft of a query timeout SET variable.

Unless it only cancels SELECT statements (which may or may not be a good
idea), please call it statement_timeout.

Do people prefer query_timeout or statement_timeout? Doesn't matter to
me.

Statements is everything. DDL- and DML-statements. Query is IMHO synonym
for DML-statement. So query_timeout is the right term.

Jan

--

#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me. #
#================================================== JanWieck@Yahoo.com #

#7Bruce Momjian
bruce@momjian.us
In reply to: Jan Wieck (#6)

Jan Wieck wrote:

Bruce Momjian wrote:

Peter Eisentraut wrote:

Bruce Momjian writes:

Here is my first draft of a query timeout SET variable.

Unless it only cancels SELECT statements (which may or may not be a good
idea), please call it statement_timeout.

Do people prefer query_timeout or statement_timeout? Doesn't matter to
me.

Statements is everything. DDL- and DML-statements. Query is IMHO synonym
for DML-statement. So query_timeout is the right term.

But the timeout is for any statement, not just SELECT/UPDATE, etc, so it
sounds like you are voting for 'statement'.

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026
#8Nicolas Bazin
nbazin@ingenico.com.au
In reply to: Bruce Momjian (#7)

The INFORMIX equivalent is SET LOCK MODE TO WAIT [timeout value in seconds];
If you don't specify any timeout value, you wait until all statements are
completed, If timeout value is set to 0 then you return immediatly if the
tables you query are already locked, ...

This statement is valid for a connection or until another identical
statement is sent.
----- Original Message -----
From: "Bruce Momjian" <pgman@candle.pha.pa.us>
To: "Jan Wieck" <JanWieck@Yahoo.com>
Cc: "Peter Eisentraut" <peter_e@gmx.net>; "Ed Loehr" <ed@LoehrTech.com>;
<dave@fastcrypt.com>; "Matthew Kennedy" <mkennedy@opushealthcare.com>;
"PostgreSQL-patches" <pgsql-patches@postgresql.org>
Sent: Thursday, July 11, 2002 11:34 AM
Subject: Re: [PATCHES] implementing query timeout

Jan Wieck wrote:

Bruce Momjian wrote:

Peter Eisentraut wrote:

Bruce Momjian writes:

Here is my first draft of a query timeout SET variable.

Unless it only cancels SELECT statements (which may or may not be a

good

idea), please call it statement_timeout.

Do people prefer query_timeout or statement_timeout? Doesn't matter

to

Show quoted text

me.

Statements is everything. DDL- and DML-statements. Query is IMHO synonym
for DML-statement. So query_timeout is the right term.

But the timeout is for any statement, not just SELECT/UPDATE, etc, so it
sounds like you are voting for 'statement'.

--
Bruce Momjian                        |  http://candle.pha.pa.us
pgman@candle.pha.pa.us               |  (610) 853-3000
+  If your life is a hard drive,     |  830 Blythe Avenue
+  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026

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

#9Bruce Momjian
bruce@momjian.us
In reply to: Nicolas Bazin (#8)

Nicolas Bazin wrote:

The INFORMIX equivalent is SET LOCK MODE TO WAIT [timeout value in seconds];
If you don't specify any timeout value, you wait until all statements are
completed, If timeout value is set to 0 then you return immediatly if the
tables you query are already locked, ...

This statement is valid for a connection or until another identical
statement is sent.

Users want a more general timeout facitily, for example, queries taking

10 minutes.

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026
#10Jan Wieck
JanWieck@Yahoo.com
In reply to: Bruce Momjian (#7)

Bruce Momjian wrote:

Jan Wieck wrote:

Statements is everything. DDL- and DML-statements. Query is IMHO synonym
for DML-statement. So query_timeout is the right term.

But the timeout is for any statement, not just SELECT/UPDATE, etc, so it
sounds like you are voting for 'statement'.

No, I am voting for 'query'. I don't see the point in allowing a
timeout for utility statements. Why would someone want a timeout
on CREATE INDEX, COPY or VACUUM? Allowing that would IMHO be
calling for more trouble than necessary.

Jan

--

#======================================================================#
# It's easier to get forgiveness for being wrong than for being
right. #
# Let's break this rule - forgive
me. #
#==================================================
JanWieck@Yahoo.com #

#11Bruce Momjian
bruce@momjian.us
In reply to: Jan Wieck (#10)

Jan Wieck wrote:

Bruce Momjian wrote:

Jan Wieck wrote:

Statements is everything. DDL- and DML-statements. Query is IMHO synonym
for DML-statement. So query_timeout is the right term.

But the timeout is for any statement, not just SELECT/UPDATE, etc, so it
sounds like you are voting for 'statement'.

No, I am voting for 'query'. I don't see the point in allowing a
timeout for utility statements. Why would someone want a timeout
on CREATE INDEX, COPY or VACUUM? Allowing that would IMHO be
calling for more trouble than necessary.

Seems pretty arbitrary to time just DML and not DLL. I can even imagine
this for VACUUM FULL where you don't want it running for a long time.
It is under their control and they can turn it off if they don't want it
for those statements.

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026
#12Bruce Momjian
bruce@momjian.us
In reply to: Rod Taylor (#5)

Rod Taylor wrote:

On Wed, 2002-07-10 at 18:52, Bruce Momjian wrote:

Peter Eisentraut wrote:

Bruce Momjian writes:

Here is my first draft of a query timeout SET variable.

Unless it only cancels SELECT statements (which may or may not be a good
idea), please call it statement_timeout.

Do people prefer query_timeout or statement_timeout? Doesn't matter to
me.

There is no 'statement' in SQL, that said, 75% of SQL has nothing to do
with queries.

So... I think I vote 'statement'.

OK, changed to 'statement'. Patch completed, ready for testing. It
properly handles all the cases I tested, like UPDATE waiting on a lock
and SELECT queries.

I also tested setting statement_timeout to '1' and it allows you to
change it to a different value. It doesn't cancel the SET before it is
changed.

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026

Attachments:

/bjm/difftext/plainDownload+199-85