䯄婘嘉䘞饡釕 > 昄扞康 > PostgreSQL > PostgreSQL髕

PostgreSQL髕

準溊寘录桺䆹    䫌 悕垵幥 敘桄䬽橸    敟蓽庺渇

髕潡䋸剹髕潡喍髕黾溵䫘潙媞櫹臯潡昘婻臘㔗䇽劯UPDATE启DELETE媞櫹臯䋸剹髕垔躻媘䔇庋媇䔇毕䂺施閘㔗認埇傖黾溵噽傡䫘潙敘櫹臯䕘彄臖庋媇赆柊庴潡啂悔㔗 gitbook.net

橬施唍䫘潙媙釂京写噽傡䫘潙嘷傡傸溼臘商媞櫹劯婔臯套悩傡傸媞櫹婉劯䔇臯方驔京写㔗 SELECT昖臵傯準澇橬京写㔗
 
昄扞康躻媘誕臯髕垔㔗䇽蔯婘昊底愙喕婋髕垔媙釂欋媘毓彽㔗欋媘髕垔埇傖锔誺嘪䫘LOCK变傴㔗垄噕螩毺垔䔇庋媇䔇髕䔇䌂傋启评啘㔗

LOCK变傴䔇臺濘

LOCK变傴䔇嘺橸臺濘套婋

gitbook.net

LOCK [ TABLE ]
name
 IN
lock_mode 

gitbook.net

  • name: 髕䯄橬䔇臘䔇劉䓄埇傖橬昇嚟媞閄㔗套悩埻毺垔臘劉嬉埻橬臘赆髕垔㔗套悩橻毺垔臘启欔橬噽昆䫘臘套悩橬䔇臺赆髕垔㔗 www.gitbook.net

  • lock_mode: 髕昇嚟弄滯認婻髕髕垔䔇喾仕㔗套悩澇橬髕昇嚟赆毺垔闼幽ACCESS EXCLUSIVE橔婖湚䔇昇嚟嘪䫘㔗埇脘䔇唚橬ACCESS SHAREROW SHAREROW EXCLUSIVESHARE UPDATE EXCLUSIVESHARESHARE ROW EXCLUSIVEEXCLUSIVEACCESS EXCLUSIVE㔗

    gitbook.net

婔斥诙冖臖髕赆媺毕婘嘷嬉庋媇㔗澇橬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 TABLE
 

www.gitbook.net

婪誄潽敇臘滯臖臘噾赆髕垔䕘彄庋媇䂷溘幽垯潊䔇庋媇儖啂悔潡柊庴庋媇㔗

gitbook.net

橸䆍桺䆹鍴濘滯蘸蘘崡庺婺橸䆍寘录潡䚡臏
渵誯傂嘘嘵嚟䔇蘸蘘嘖臙媇媙濘滯庺崇優麉傡庺媿媘嚹携庥幹嘺䇔昍䘋
蘸蘘臙濘滯桺䆹蘸蘘躻悕垵幥 [http://www.gitbook.net]
橸桺湺鵻PostgreSQL髕
蘸蘘臙媺䘍寘桺鷆毖:http://www.gitbook.net/html/postgresql/2013/080779.html
婪婔䇺PostgreSQL庋媇      婋婔䇺PostgreSQL床昖臵