2

In the Azure Portal under PostgreSQL the server configuration statement_timeout controls the following.

"Sets the maximum allowed duration (in milliseconds) of any statement. 0 turns this off."

There doesn't seem to be a way to override that setting once it is set. We use Npgsql's .NET Provider and have tried setting the timeout=0 and the command timeout=0 on the connection string to see that would override but it doesn't seem to have an effect on the timeout. We don't want to disable it or set it to a large interval, but we have some stored procedures that run a long time and would like to set on a per statement basis.

thank you.

Ed Mendez
  • 1,510
  • 10
  • 14

1 Answers1

4

You can set statement_timeout at a transaction level. In the example below, I start a transaction, set the timeout, call postgres' sleep function, then mark the end of the transaction.

BEGIN; SET LOCAL statement_timeout = 2000; SELECT pg_sleep(3); COMMIT;

Note that because the sleep function times out (which is marked as an ERROR), the transaction is rolled back.

Alternatively, you can set statement_timeout at a session level using just SET.

Info about SET and SET LOCAL: https://www.postgresql.org/docs/10/sql-set.html