PostgreSQL - SPLessons

PostgreSQL Locks

Chapter 24

SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

PostgreSQL Locks

PostgreSQL Locks

shape Description

When different number of users access the same information at the same point of time, locking restrict them for making concurrent alterations to the data. Locks are handled within the Microsoft SQL Server Compact Database Engine. PostgreSQL Locks is automatically captured and discharged based on the operations performed by the client.

If PostgreSQL Locks is not performed, then different number of clients can update the same record at the same point of time, the record within the database can become logically incorrect. In that case, queries are executed against that record will produce unexpected results. PostgreSQL Locks must be controlled manually. And this Manual locking can be done by utilising the LOCK command. It permits determination of a transaction’s lock sort and extensions.

shape Syntax

The syntax for PostgreSQL Locks is as follows:

LOCK[TABLE]
name
IN
lock_mode

Name => The name of an existing table to lock.
Lock_mode => Specifies to which lock it will conflicts.

shape Examples

By viewing the below example the concept of PostgreSQL Locks can be easily understood.

testdb# select * from Employee;
 id | name  | age | address   | salary
----+-------+-----+-----------+--------
  1 | Paul  |  32 | California|  20000
  2 | Allen |  25 | Texas     |  15000
  3 | Teddy |  23 | Norway    |  20000
  4 | Mark  |  25 | Rich-Mond |  65000
  5 | David |  27 | Texas     |  85000
  6 | Kim   |  22 | South-Hall|  45000
  7 | James |  24 | Houston   |  10000
(7 rows)
testdb=#BEGIN;
LOCK TABLE Employee IN ACCESS EXCLUSIVE MODE;
LOCK TABLE

Here in the above example the Employee table has been locked by performing the above command.

Summary

shape Key Points

  • PostgreSQL Locks – Is the process of restricting users to access same data.