Understanding Teradata Locking: Types and Granularity

What is locking in Teradata?

Locking database objects is essential in RDBMS to prevent multiple users from concurrently modifying or accessing the same data in ways that could cause inconsistencies.

The affected objects are protected to maintain their integrity while users access or modify data.

Teradata determines the necessary level of lock granularity and the corresponding restrictions on other users’ activities during each data access.

Lock granularity can escalate during execution, for example by transitioning from a row lock to a table lock.

Which Objects can be locked?

  • Database Locks: All Objects in a database are locked
  • Table Locks: All table rows are locked
  • View Locks: All table accesses by a view are locked
  • Partition Locks: All rows of a partition or several partitions are locked
  • Partition Range Locks: A range of a table’s partitions is locked
  • Rowhash Locks: One or more rows of a table are locked

Rowhash Locking Details

Locking a RowHash affects multiple rows because rows with the same Primary Index value also share the same RowHash.

RowHash locks are used in these scenarios:

  • An unpartitioned table is queried via the primary index.
  • An UPDATE or DELETE statement uses a primary or unique secondary index (the rowhash is locked in the USI subtable and the base table).

Consider the following UPDATE statement:

UPDATE Customer SET Gender = 'm';

Without a WHERE clause, this statement requires a write lock on the entire table.

Using a WHERE condition on the primary index (CustomerId) results in a rowhash lock instead.

UPDATE Customer SET Gender = 'm' WHERE CustomerId = 1;

Rowhash Locking for Row-Partitioned Tables

Rowhash locking enables more precise locking of a partition or range of partitions in a row-partitioned table.

The RowHash is locked within one or multiple partitions, allowing other requests to access rows in separate partitions or with a different rowhash.

Teradata Locking Types

What is the Exclusive Lock?

Locks are only applied to databases or tables.
They are the strictest locks because all other users’ requests are queued if an object is exclusively locked. Exclusive locks are rarely used, usually when databases are restructured.

What is a Write Lock?

Write locks allow the lock’s owner to change data. All other users only read with a so-called “dirty read” because the data can be inconsistent. No new write or read locks are allowed if there is a write lock.

What is a Read Lock?

Whenever a user holds a read lock on an object, no write locks or exclusive locks can be obtained by any other users. However, other users can hold unlimited read locks (and access locks) simultaneously on the same object.

What is an Access Lock?

Access locks allow a user to read “inconsistent” data. Access locks work even if another user already holds a write lock on the object. Access Locks are not allowed if there is an exclusive lock on the object.

How are Teradata Locks selected?

Teradata selects the most appropriate lock automatically for every scenario.

SQL StatementThe granularity with Index AccessThe granularity with FTS or NUSILock Level Mode
SELECTRow HashTableRead
UPDATE Row Hash Table Write
DELETE Row Hash Table Write
INSERT Row Hash Write
CREATE/DROP/MODIFY DATABASEDatabaseExclusive
CREATE/DROP/ALTER TABLETable Exclusive

Users can influence the lock level. For example:

SELECT * FROM Customer;

This query typically results in a read lock.

Lower the lock to an access lock if data consistency is not critical.

LOCKING Customer FOR ACCESS
SELECT * FROM Customer;

The ACCESS modifier allows data retrieval while the table is being written to.

You can also upgrade the lock by changing it from a read lock to a write lock.

LOCKING Customer FOR WRITE
SELECT * FROM Customer;

Other users who need access to the customer table with read, write, or exclusive privileges must wait for your query to finish.

Locking Modifiers

LOCK DATABASE/TABLE/VIEW/ROW 
FOR ACCESS/EXCLUSIVE/READ/WRITE
[{NOWAIT}

The NOWAIT option is optional; when specified, the SQL statement will end immediately if the desired lock is unavailable.

Locking Summary

  • Exclusive Lock: No concurrent access allowed
  • Write Lock: No concurrent read, write, and exclusive locks allowed
  • Read Lock: No concurrent write and exclusive locks allowed
  • Access Lock: No concurrent exclusive locks allowed
teradata locking
Teradata locking queues

Also refer to:

A Warning Regarding Teradata Locking

Due to resource limitations, the Teradata lock manager can only apply locks at row hash granularity. If multiple rows map to the same row hash and locking fails as a result, the transaction may fail.

Please refer to the following resources for more information on this topic.

Locking – The official Teradata documentation

Related Services

🏗️ Planning a Data Platform Migration?

Architecture-first approach: we design before a single line of code is written. Zero data loss across every migration delivered.

Our Migration Services →

📊 Data Platform Migration Survey

Help us map where the industry is heading. Results are public — see what others chose.

1. What is your current data platform?

2. Where are you migrating to (or evaluating)?

Migrating FROM
Migrating TO

Thanks for voting! Share this with your network.

Follow me on LinkedIn for daily insights on data warehousing and platform migrations.

Stay Ahead in Data Warehousing

Get expert insights on Teradata, Snowflake, BigQuery, Databricks, Microsoft Fabric, and modern data architecture — delivered to your inbox.

1 thought on “Understanding Teradata Locking: Types and Granularity”

Leave a Comment

DWHPro

Expert network for enterprise data platforms. Senior consultants, project teams built for your challenge — across Teradata, Snowflake, Databricks, and more.

📍Vienna, Austria & Jacksonville, Florida

Quick Links
Services Team Teradata Book Blog Contact Us
Connect
LinkedIn → [email protected]
Newsletter

Join 4,000+ data professionals.
Weekly insights on Teradata, Snowflake & data architecture.