Re: setting query timeout as part of the query

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Steve Crawford <scrawford(at)pinpointresearch(dot)com>
Cc: William Morgan <william(at)introhq(dot)com>, pgsql-novice(at)postgresql(dot)org
Subject: Re: setting query timeout as part of the query
Date: 2014-09-30 20:53:35
Message-ID: 20756.1412110415@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Steve Crawford <scrawford(at)pinpointresearch(dot)com> writes:
> On 09/30/2014 12:52 PM, William Morgan wrote:
>> My question is: is there a way to set this timeout as part of the
>> query itself?

> You could probably write a function that includes your timeout setting
> and call that but I'm not sure that would be better than simply using a
> transaction.

IIRC, statement_timeout applies to the total time required to execute
a *command submitted by the client*, and the active value is determined
just before starting each command. So you're pretty much stuck: you
must issue the SET as a separate client-submitted command.

As Steve says, it should be possible to ensure that the pooler doesn't
take the session away from you in between, by wrapping the whole thing
in BEGIN/COMMIT if nothing else. If the pooler will take away a session
intra-transaction, it is 100% broken and dangerous, and you need to get
another one.

regards, tom lane

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message William Morgan 2014-09-30 21:36:17 Re: setting query timeout as part of the query
Previous Message Steve Crawford 2014-09-30 20:32:01 Re: setting query timeout as part of the query