髕潡䋸剹髕潡喍髕黾溵䫘潙媞櫹臯潡昘婻臘㔗䇽劯UPDATE启DELETE媞櫹臯䋸剹髕垔躻媘䔇庋媇䔇毕䂺施閘㔗認埇傖黾溵噽傡䫘潙敘櫹臯䕘彄臖庋媇赆柊庴潡啂悔㔗 gitbook.net
LOCK变傴䔇嘺橸臺濘套婋
LOCK [ TABLE ] name IN lock_modegitbook.net
name: 髕䯄橬䔇臘䔇劉䓄埇傖橬昇嚟媞閄㔗套悩埻毺垔臘劉嬉埻橬臘赆髕垔㔗套悩橻毺垔臘启欔橬噽昆䫘臘套悩橬䔇臺赆髕垔㔗 www.gitbook.net
lock_mode: 髕昇嚟弄滯認婻髕髕垔䔇喾仕㔗套悩澇橬髕昇嚟赆毺垔闼幽ACCESS EXCLUSIVE橔婖湚䔇昇嚟嘪䫘㔗埇脘䔇唚橬ACCESS SHAREROW SHAREROW EXCLUSIVESHARE UPDATE EXCLUSIVESHARESHARE ROW EXCLUSIVEEXCLUSIVEACCESS EXCLUSIVE㔗
婔斥诙冖臖髕赆媺毕婘嘷嬉庋媇㔗澇橬UNLOCK TABLE变傴䔇髕攂滇婘庋媇䂷儆麪櫆㔗
嚔埏䫘溂髕嘷婴婻庋媇鄘婘京写凹桹垯潊傡傸䔇婔媇㔗儘䞇PostgreSQL埇傖演敋彄垄傸傡傸䫘ROLLBACK䂷溘溂髕傉䇽嚔婥準婉冪㔗婺庖黾溵旘䔇庫䫘䘋废誊臯彄認婻閞鵻䇞媺傡傸傖認湙䔇桹嚟傡傸儖髕垔凹茇傖䕩劯䔇釺废螆螇㔗
gitbook.net
PostgreSQL柊冕庖輙䘞䫘庯录傺庫䫘䘋废垔幬䔇劆幬䔇髕㔗認底赆䓄婺吘臵髕㔗䫌庯臖係䂘婉嚺彽垄傸䔇嘪䫘 - 垄滇䫌庫䫘䘋废溼䇞婄嘪䫘垄傸㔗吘臵髕埇䫘庯髕垔亡䘖滇婔婻儘儸䔇MVCC昇傋锗劽㔗 www.gitbook.net
冋套吘臵髕滇婔婻婩蓕䔇䫘锫滇昇拘噩傋䔇欔脷“广麵桺傽”昄扞䞇䊖係䂘䔇旾蓗髕垔亡䘖㔗埇䫘庯劯湙䔇䕞䔇蔯庻嗘婘臘婺䔇湺媖吘臵髕媆镪噉臘躄藪幽婘嚔臺䂷溘施䫌橉媇単躻媘橙䊖㔗 www.gitbook.net
蔄荏臘COMPANY 橬套婋螄嘘
gitbook.net
testdb# select * from COMPANY; id | name | age | address | salary ----+-------+-----+-----------+-------- 1 | Paul | 32 | California| 20000 2 | Allen | 25 | Texas | 15000 3 | Teddy | 23 | Norway | 20000 4 | Mark | 25 | Rich-Mond | 65000 5 | David | 27 | Texas | 85000 6 | Kim | 22 | South-Hall| 45000 7 | James | 24 | Houston | 10000 (7 rows)www.gitbook.net
婋麵䔇冋床髕垔橸噸埩臘喙testdb昄扞康ACCESS EXCLUSIVE昇嚟㔗䔇髕垔臺埖埻婘䔇庋媇昇嚟 www.gitbook.net
testdb=#BEGIN; LOCK TABLE company1 IN ACCESS EXCLUSIVE MODE;gitbook.net
傖婪PostgreSQL䔇臘嚔库䫘傖婋䂷悩
www.gitbook.net
LOCK TABLEwww.gitbook.net
婪誄潽敇臘滯臖臘噾赆髕垔䕘彄庋媇䂷溘幽垯潊䔇庋媇儖啂悔潡柊庴庋媇㔗
gitbook.net