迼걒

Postgres Ìṩ¶àÖÖËøģʽÀ´¿ØÖƶԱíÖÐÊý¾ÝµÄ²¢ÐзÃÎÊ¡£ÓÐЩËøģʽÊÇÔÚÓï¾äÖ´ÐÐ֮ǰÓÉPostgres ×Ô¶¯Ê©¼ÓµÄ£¬¶øÆäËûµÄÌṩÓÃÀ´ÓÉÓ¦ÓÃʹÓõġ£Ò»¸öÊÂÎñÀïÒªÇóµÄËùÓÐËøģʽ£¨³ýÁË AccessShareLock£©¶¼ÊÇÔÚÕû¸öÊÂÎñÆڼ䱣Óеġ£

³ýÁËËøÒÔÍ⣬¶ÌÆڵĹ²Ïí/ÅÅËûÏúÒ²ÔÚ¹²ÏíµÄ»º³å³ØÖÐÓÃÓÚ¿ØÖƶԱíÒ³ÃæµÄ¶Á/д·ÃÎÊ¡£ÏúÔÚÒ»Ìõ¼Ç¼ץȡ»òÕ߸üкóÂíÉϱ»ÊÍ·Å¡£

±í¼¶Ëø

AccessShareLock
Ò»¸öÄÚ²¿Ëøģʽ£¬½øÐвéѯʱ×Ô¶¯Ê©¼ÓÔÚ±»²éѯµÄ±íÉÏ¡£Óï¾äÖ´ÐÐÍê³Éºó£¬Postgres ÊÍ·ÅÕâЩËø¡£

 

 
 
 

Ö»Óë AccessExclusiveLock ³åÍ»¡£
 

RowShareLock
±» SELECT FOR UPDATE ºÍÓÃÓÚ IN ROW SHARE MODE  µÄ LOCK TABLE Óï¾äÒªÇó¡£

 

 
 
 

Óë ExclusiveLock ºÍ AccessExclusiveLock ģʽ³åÍ»¡£
 

RowExclusiveLock
±» UPDATE, DELETE, INSERT ºÍÓÃÓÚIN ROW EXCLUSIVE MODE µÄ LOCK TABLE Óï¾äÒªÇó¡£

 

 
 
 

Óë ShareLock£¬ShareRowExclusiveLock£¬ExclusiveLock ºÍ AccessExclusiveLock ģʽ³åÍ»¡£
 

ShareLock
±» CREATE INDEX ºÍÓÃÓÚIN SHARE MODE µÄ LOCK TABLE Óï¾äËùÒªÇó¡£

 

 
 
 

Óë RowExclusiveLock£¬ShareRowExclusiveLock£¬ExclusiveLock ºÍ AccessExclusiveLock ģʽ³åÍ»¡£
 

ShareRowExclusiveLock
±»ÓÃÓÚ IN SHARE ROW EXCLUSIVE MODE µÄ LOCK TABLE Óï¾äÒªÇó¡£

 

 
 
 

Óë RowExclusiveLock£¬ShareLock£¬ShareRowExclusiveLock£¬ExclusiveLock ºÍ AccessExclusiveLock ģʽ³åÍ»¡£
 

ExclusiveLock
±»ÓÃÓÚ IN EXCLUSIVE MODE µÄ LOCK TABLE Óï¾äÒªÇó¡£

 

 
 
 

Óë RowShareLock£¬RowExclusiveLock£¬ShareLock£¬ShareRowExclusiveLock£¬ExclusiveLock ºÍ AccessExclusiveLock ģʽ³åÍ»¡£
 

AccessExclusiveLock
±» ALTER TABLE£¬DROP TABLE£¬VACUUM ºÍ LOCK TABLE Óï¾äÒªÇó¡£

 

 

Óë RowShareLock£¬RowExclusiveLock£¬ShareLock£¬ShareRowExclusiveLock£¬ExclusiveLock ºÍ AccessExclusiveLock ģʽ³åÍ»¡£
 

×¢Ò⣺ Ö»ÓÐ AccessExclusiveLock ×èÈû SELECT £¨Ã»ÓРFOR UPDATE£©Óï¾ä¡£

Ðм¶Ëø

µ±Ä³ÐеÄÒ»¸öÄÚ²¿×ֶα»¸üУ¨»òɾ³ý»ò±ê¼ÇΪ¸üУ©Ê±ÒªÇóʹÓÃÕâЩËø¡£Postgres ÔÚÄÚ´æÀï²»×ö¹ØÓÚÒѸüеÄÐеÄÈκμÇÒ䣬Òò¶ø¶ÔËø¶¨µÄÐÐÊýûÓÐÈκÎÏÞÖÆ£¬Ò²Ã»ÓÐËø¶¨µÝÔö¡£

µ«ÊÇ£¬Òª×¢Òâ SELECT FOR UPDATE »á¸ü¸ÄËùÑ¡¶¨µÄÐÐÒÔ±ê¼ÇËüÃÇ£¬Òò¶ø»áµ¼Ö´ÅÅÌд¶¯×÷¡£

Ð춱ðµÄËø²»Ó°ÏìÊý¾Ý²éѯ¡£ËüÃÇÖ»ÊÇÓÃÓÚ×èÈû¶ÔͬһÐеÄд¡£

Ò