What is alternative to "lock_timeout" in PostgreSQL?

772 views Asked by At

I need to kill my session, if I'm blocking other sessions.But as of now we have only option to kill own session blocked by other sessions using lock_timeout. Do we have option in postgres to timeout own session, if our session blocked other sessions not own session blocked by others?

2

There are 2 answers

0
Super Kai - Kazuya Ito On

statement_timeout is alternative = lock_timeout in PostgreSQL:

Abort any statement that takes more than the specified amount of time.

For example, SELECT pg_sleep(30); is timed out after 10 seconds as shown below:

postgres=# SET statement_timeout to 10000;
SET
postgres=# SELECT pg_sleep(30);
ERROR:  canceling statement due to statement timeout
0
Laurenz Albe On

You should set idle_in_transaction_session_timeout and statement_timeout. Then your blocking session gets killed if it runs too long statements and if it hangs idle in a database transaction.