Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

Following this answer regarding limiting resources per query in PostgreSQL, I've been advised to set a timeout value for query execution:

SET statement_timeout TO '1min';

This is great, but sometimes I want to relax the restriction for a specific script.

  • Is there a way to set the timeout as a psql argument? I've tried psql --set statement_timeout=50, unsuccessfully.
  • Is there a way to set it from a Python script which uses psycopg2?
share|improve this question

2 Answers 2

up vote 4 down vote accepted

You can use the environment variable PGOPTIONS. Either set it permanently or just when you call psql, e.g.,

PGOPTIONS='--statement-timeout=1min' psql ...

This works for any libpq client, including psycopg.

Of course you could also just put the SET statement in the psqlscript.

share|improve this answer

As statement_timeout is described in postgres's documentation on client configuration, I would assume it's a setting for the session, so you should be able to just send the set command before your query.

As for how to do it with psycopg2, I have no idea. Looking through the docs shows a set_isolation_level and set_client_encoding ... you might want to look at the code to see how it handles those, and if it's something that's generic and could be extended.

update : I should also mention I didn't see anything in the docs for something like Perl DBI's do, which is how I handle these sorts of things.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.