Hi all
Something that may be worth noting is that Postgresql has server-side support for session-based statement timeouts. Search for "
statement_timeout" here:
http://www.postgresql.org/docs/9.3/static/runtime-config-client.htmlIf one needs to cap the amount of time that may be spent running a statement and also want to leave the database in a known/consistent state, this is an option.
I am not advocating that this be used at a driver level -- just bringing it to everyone's attention. It may be useful.
psql example:
<snip>
=> set statement_timeout=1500; -- Timeout in ms
=> select pg_sleep(1); -- Sleep 1 second
pg_sleep
----------
(1 row)
=> select pg_sleep(2); -- Sleep 2 seconds
ERROR: canceling statement due to statement timeout
</snip>
Erlang example:
<snip>
> pgsql:squery(H, "SET statement_timeout=1500").
{ok,[],[]}
> pgsql:squery(H, "SELECT pg_sleep(1)").
{ok,[{column,<<"pg_sleep">>,void,4,-1,0}],[{<<>>}]}
> pgsql:squery(H, "SELECT pg_sleep(2)").
{error,{error,error,<<"57014">>, <<"canceling statement due to statement timeout">>,[]}}
</snip>
Regards,
Cobus