![]() #define SET_LOCKTAG_VIRTUALTRANSACTION(locktag,vxid) #define SET_LOCKTAG_TRANSACTION(locktag,xid) #define SET_LOCKTAG_TUPLE(locktag,dboid,reloid,blocknum,offnum) #define SET_LOCKTAG_PAGE(locktag,dboid,reloid,blocknum) #define SET_LOCKTAG_DATABASE_FROZEN_IDS(locktag,dboid) #define SET_LOCKTAG_RELATION_EXTEND(locktag,dboid,reloid) #define SET_LOCKTAG_RELATION(locktag,dboid,reloid) In PostgreSQL, there are about 10 Micros defined to address different locks in different use cases, and you can find the details by searching below key info. Uint8 locktag_lockmethodid /* lockmethod indicator */ ![]() Uint8 locktag_type /* see enum LockTagType */ Uint16 locktag_field4 /* a 16-bit ID field */ Uint32 locktag_field3 /* a 32-bit ID field */ Uint32 locktag_field2 /* a 32-bit ID field */ Uint32 locktag_field1 /* a 32-bit ID field */ Here is how the LOCKTAG data struct is defined in PostgreSQL. In the source code, PostgreSQL defines a generic LOCKTAG data struct to let user transaction fill in different lock information. The reason PostgreSQL can detect this local deadlock is because PostgreSQL knows all the locks information, and it can easily find a lock waiting cycle. In this blog, we call this kind of deadlock as local deadlock compared with the one (global deadlock) we are going to discuss more below. For more details information about the deadlock, you can refer to the official document at src/backend/storage/lmgr/README. ![]() To address this deadlock issue, PostgreSQL has two key things built-in: 1) try to avoid the deadlock by having a lock waiting queue and sort the locks requests to avoid potential deadlock 2) requires the transaction to abort if a deadlock detected By having these two key designs, a deadlock happens within a single PostgreSQL server can be easily resolved. When this kind of deadlock is happening, there is no win-win solution, the only way to solve this locking issue is that one of the transactions has to abort and release the lock. Since PostgreSQL allows user transactions to request locks in any order, therefore, this kind of deadlock can happen. In this situation, Either Process A or Process B can’t not continue and they will wait for each other forever. Deadlockįirst of all, the basic concept of a deadlock is that Process A is trying to acquire Lock2 while it is holding Lock1 and Process B is trying to acquire Lock1 while it is holding Lock2 at the same moment. There are many discussions about global deadlock, but this blog will provide you a step-by-step procedure about how to create such a global deadlock and share some thoughts based on personal experience. deadlock on the Turkish Wikipedia.Nowadays, supporting distributed transactions is a typical requirement for many use cases, however, the global deadlock detection is one of the key challenging issues if you plan to use PostgreSQL to setup a distributed database solution.Wikipedia ptĭeadlock ( definite accusative deadlocku, plural deadlocklar) ( computing ) deadlock ( inability to continue operating due to two processes requiring a response from one other ). ![]() Unadapted borrowing from English deadlock.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |