LOCK TABLES

2023-07-28 02:55:42  Updated

Purpose

You can use this statement to lock one or more tables, partitions, or subpartitions in specified mode.

Note

In the current version of OceanBase Database, the LOCK TABLES statement is ignored in MySQL mode.

Syntax

LOCK TABLES
    table_name [ [AS] alias ] lock_type
    [, table_name [ [AS] alias ] lock_type ]...

lock_type:
    READ [LOCAL]  
  | [LOW_PRIORTY] WRITE

Parameters

Parameter Description
table_name The name of the table to be locked.
lock_type The lock type. The current version of OceanBase Database supports the following lock types:
  • READ: allows all sessions, including the session that applies the lock, to read the locked table but not to modify it.
  • READ LOCAL: functions in the same way as READ, but allows execution of the INSERT statement.
  • WRITE: allows the current session to read and modify the locked table, but blocks all access from other sessions.
  • LOW_PRIORITY WRITE: applies low-priority write locks.

Examples

Set a read lock for the test1 table and a write lock for the test2 table.

obclient> LOCK TABLES test1 as t1 READ LOCAL, test2 as t2 LOW_PRIORITY WRITE;
Query OK, 0 row affected

Contact Us