Created
June 5, 2017 10:29
-
-
Save xiazhibin/791ed9af3bcaec10699dbee6e2594cf5 to your computer and use it in GitHub Desktop.
postgresql study
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1·共享锁,排它锁。 | |
共享锁【S锁】 | |
又称读锁,若事务T对数据对象A加上S锁,则事务T可以读A但不能修改A,其他事务只能再对A加S锁,而不能加X锁,直到T释放A上的S锁。这保证了其他事务可以读A,但在T释放A上的S锁之前不能对A做任何修改。 | |
排他锁【X锁】 | |
又称写锁。若事务T对数据对象A加上X锁,事务T可以读A也可以修改A,其他事务不能再对A加任何锁,直到T释放A上的锁。这保证了其他事务在T释放A上的锁之前不能再读取和修改A。 | |
-查询是否锁表了 | |
select oid from pg_class where relname='可能锁表了的表' | |
select pid from pg_locks where relation='上面查出的oid' | |
--如果查询到了结果,表示该表被锁 则需要释放锁定 | |
select pg_cancel_backend(上面查到的pid) | |
http://www.postgres.cn/docs/9.3/sql-select.html#SQL-FOR-UPDATE-SHARE | |
http://www.postgres.cn/docs/9.3/view-pg-locks.html #锁 | |
http://www.postgres.cn/docs/9.3/index.html |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment