PostgreSQL中对应的锁定方法是什么

时间:2019-03-21 03:18:40

标签: postgresql

在Oracle中,有两个过程使用DBMS_LOCK.REQUEST和DBMS_LOCK.RELEASE

lock_status := DBMS_LOCK.REQUEST(
    lockhandle => get_handle(lock_name),
    lockmode => DBMS_LOCK.X_MODE, -- eXclusive
    timeout => DBMS_LOCK.MAXWAIT, -- wait forever
    release_on_commit => FALSE);

lock_status := DBMS_LOCK.RELEASE(
    lockhandle => get_handle(lock_name));

get_handle的作用如下:

create or replace FUNCTION                        get_handle (lock_name IN VARCHAR2) RETURN VARCHAR2 IS
  PRAGMA AUTONOMOUS_TRANSACTION;
  lock_handle VARCHAR2(128);
BEGIN
  DBMS_LOCK.ALLOCATE_UNIQUE (
    lockname => lock_name,
    lockhandle => lock_handle,
    expiration_secs => 864000); -- 10 days
  RETURN lock_handle;
END get_handle;

我需要将DBMS_LOCK.REQUEST和DBMS_LOCK.RELEASE迁移到PostgreSQL中。我已经研究过Google, https://www.postgresql.org/docs/9.1/explicit-locking.htmlhttps://www.postgresql.org/docs/9.1/view-pg-locks.html

并且仍然试图了解我应该为这些锁使用的方法是什么。如果您对此有所了解,请帮助提供建议。

谢谢

0 个答案:

没有答案