Re: best way to kill long running query?

From: "Bill Eaton" <EE2(at)aeroantenna(dot)com>
To: "Magnus Hagander" <magnus(at)hagander(dot)net>
Cc: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, <pgsql-general(at)postgresql(dot)org>
Subject: Re: best way to kill long running query?
Date: 2007-03-21 20:04:50
Message-ID: BHEMIOKCPPFPFJCHEKDCGEIMCFAA.EE2@aeroantenna.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

>>> I want to allow some queries for my users to run for a
>>> prescribed period of time and kill them if they go over
>>> time. Is there a good way to do this?

>> set statement_timeout perhaps?
> I don't think you can set GUC parameters from the ODBC driver. Your
> options are:
>
> * postgresql.conf. Will apply to all sessions to the databse.
>
> * database. Use ALTER DATABLASE foo SET statement_timeout=<something>.
> Will then affect all connections to that database.
>
> * user. Use ALTER ROLE foo SET statement_timeout=<something>. Will then
> affect all connections from that user.
>
> * change your application to issue a "SET statement_timeout=<something>"
> query before anything else it sends.
>

The last option is almost exactly what I wanted. It works quite nicely The
only downside to this approach is that an error is raised if the timeout is
exceeded. Which, when I think about it, is probably good behavior --> it
allows me to distinguish between (1) a query that completed and returned no
records and (2) a query that aborted because it exceeded the timeout.

Thanks to all for the assist.

Bill Eaton

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Vivek Khera 2007-03-21 20:47:23 Re: best way to kill long running query?
Previous Message Martijn van Oosterhout 2007-03-21 19:57:22 Re: invalid byte sequence for encoding "UTF8"