What is ROW EXCLUSIVE in PostgreSQL exactly?

霸气de小男生 提交于 2020-01-22 19:48:07

问题


I understand that PostgreSQL inserts use ROW EXCLUSIVE locks, does that mean that inserts can be in parallel, and that one insert won't lock up the entire table?

Table in question has a primary key generated outside of DB and no additional indexes (but I'm curious what would happen if that wasn't the case).

Edit 1:

Per documentation, ROW EXCLUSIVE conflicts with SHARE which is acquired by CREATE INDEX.

Does this mean that if the table has index, insert will lock up the entire table?

Or will the table be locked only when creating the index first time?

Also, as I understand now, primary key is also an index, right?


回答1:


Concurrent inserts should not block each other, unless they are inserting conflicting keys into a unique index, in which case the second insert will wait for the transaction containing the first to be committed or rolled back, and then either abort or proceed. A primary key is implemented as a unique index.

Non-unique indexes should not cause additional lock conflicts. Creating an index will block inserts and updates to the table, although you can just add concurrently to the command to avoid this, for some speed penalty.



来源:https://stackoverflow.com/questions/14530360/what-is-row-exclusive-in-postgresql-exactly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!