patternsqlModerate
PostgreSQL: SET-ing from psql arguments
Viewed 0 times
postgresqlargumentsingpsqlfromset
Problem
Following this answer regarding limiting resources per query in PostgreSQL, I've been advised to set a timeout value for query execution:
This is great, but sometimes I want to relax the restriction for a specific script.
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
psqlargument? I've triedpsql --set statement_timeout=50, unsuccessfully.
- Is there a way to set it from a Python script which uses psycopg2?
Solution
You can use the environment variable
This works for any libpq client, including psycopg.
Of course you could also just put the
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.Code Snippets
PGOPTIONS='--statement-timeout=1min' psql ...Context
StackExchange Database Administrators Q#1372, answer score: 10
Revisions (0)
No revisions yet.