HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlModerate

PostgreSQL: SET-ing from psql arguments

Submitted by: @import:stackexchange-dba··
0
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:

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?

Solution

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.

Code Snippets

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

Context

StackExchange Database Administrators Q#1372, answer score: 10

Revisions (0)

No revisions yet.