When setting lock_timeout 10 seconds locally on psql as shown below:
SET LOCAL lock_timeout = 10000;
I got the warning below on psql:
WARNING: SET LOCAL can only be used in transaction blocks
Then, SET LOCAL lock_timeout = 10000;
doesn't apply to the following transaction at all so lock table person;
waits to lock the table forever without timeout after 10 seconds as shown below:
postgres=# SET LOCAL lock_timeout = 10000;
WARNING: SET LOCAL can only be used in transaction blocks
SET
postgres=# BEGIN;
BEGIN
postgres=*# LOCK TABLE person; # Waits to lock the table forever
So, how can I solve the warning then apply SET LOCAL lock_timeout = 10000;
to the following transaction?
As the warning below says:
You need to use
SET LOCAL
in transaction after runningBEGIN
then it works properly as shown below: