Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

PostgreSQL SKIP LOCKED

If you need to SELECT from a table and protect those rows from being updated until your transaction has completed, you would specify FOR UPDATE, but if some rows are locked, you can specify SKIP LOCKED to tell it to simply ignore those rows and just perform the operation on whichever rows it can access.

For example:
In session 1:
 # BEGIN;
 BEGIN
 # SELECT * FROM colours;
  id | name  
 ----+-------
   1 | red
   2 | green
   3 | blue
 (3 rows)
 # UPDATE colours SET name = 'scarlet' WHERE name = 'red';
 CREATE TABLE
In session 2:
 # SELECT * FROM colours FOR UPDATE NOWAIT;
 ERROR:  could not obtain lock on row in relation "colours"
 # SELECT * FROM colours FOR UPDATE SKIP LOCKED;
  id | name  
 ----+-------
   2 | green
   3 | blue
 (2 rows)

Comments

Popular posts from this blog

PostgreSQL pgBadger

ORA-01261: Parameter db_recovery_file_dest destination string cannot be translated ORA-01262: Stat failed on a file destination directory Linux-x86_64 Error: 2: No such file or directory

Migrating From Oracle to PostgreSQL using ora2pg open source tools

How to Get Table Size, Database Size, Indexes Size, schema Size, Tablespace Size, column Size in PostgreSQL Database

How to configure Replication Manager (repmgr) ?