Will Oracle lock the whole table while performing a DML statement or just the row

前端 未结 4 1826
南旧
南旧 2021-02-14 16:29

When i try to insert/update something in a db table, will Oracle lock the whole table or only the row being inserted/updated?

Is this something that can be controlled t

4条回答
  •  灰色年华
    2021-02-14 17:10

    We can issue locks explicitly with the LOCK TABLE command. Find out more

    Otherwise, an insert does not lock any other rows. Because of Oracle's read isolation model that row only exists in our session until we commit it, so nobody else can do anything with it. Find out more.

    An update statement only locks the affected rows. Unless we have implemented a pessimistic locking strategy with SELECT ... FOR UPDATE. Find out more.

    Finally, in Oracle writers do not block readers. So even locked rows can be read by other sessions, they just can't be changed. Find out more.

    This behaviour is baked into the Oracle kernel, and is not configurable.


    Justin makes a good point about the table-level DDL lock. That lock will cause a session executing DDL on the table to wait until the DML session commits, unless the DDL is something like CREATE INDEX in which case it will fail immediately with ORA-00054.

提交回复
热议问题