Locking and postgres_fdw extension

From: Steve Baldwin <steve(dot)baldwin(at)gmail(dot)com>
To: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Locking and postgres_fdw extension
Date: 2020-11-19 23:45:02
Message-ID: CAKE1AiaRGUUB11quexXcjRL45bmkCiNzsevF-TSmKDB+tQgHNw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi all,

I have two DB instances - 'online' and 'offline'. In 'offline' I have a
foreign table 'f' imported from 'online'. I want to execute a query from
'offline' to obtain a row lock, and this works fine:

select id from f where id = 1 for no key update;

However if I want it to fail immediately if unable to obtain the lock, it
seems nowait is ignored for foreign tables (or at least with my version of
postgres_fdw). The waiting session blocks until the holding session commits
or rolls back.

My 'workaround' was to create a view in 'online':

create or replace view f_lock as select * from f for no key update nowait;

Then use import foreign schema to bring that view into 'offline'. I can
then execute:

select id from f_lock where id = 1;

and it will fail immediately if the row is already locked.

Is there a better way to do this?

Thanks,

Steve

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Yi Sun 2020-11-20 01:20:00 Re: received immediate shutdown request caused cluster failover
Previous Message Asya Nevra Buyuksoy 2020-11-19 18:27:24 Re: Upgrade 9.4 to 12 on windows system