Manually Release Postgres LOCK

青春壹個敷衍的年華 提交于 2019-12-11 02:56:46

问题


I would like to know if there´s any command to unlock or release a lock made by the same transaction.

Pseudo-code

FUNCTION
    TRANSACTION
        LOOP
            TABLE LOCK
            table operations...
            "TABLE UNLOCK WANTED"
        END
    END OF TRANSACTION
END OF FUNCTION

The function query can take a while as the LOOP might be large, so I would like to be able to unlock before the transaction is fully finished.


回答1:


No, it isn't possible. Locks are held until end of transaction, no exceptions.

Thus, you need to either:

  • Use a nonstandard lock like an advisory lock, which requires everyone to check for it and respect it; or

  • Do your work in transactions that commit autonomously, before the outer transaction is done. In PostgreSQL, lack of autonomous subtransaction support means that you must use dblink for this.



来源:https://stackoverflow.com/questions/21304465/manually-release-postgres-lock

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!