Database Research & Development

  • Home
  • NoSQL
    • NoSQL
    • Cassandra
  • Databases
    • Database Theory
    • Database Designing
    • SQL Server Coding Standards
    • SQL Server
    • PostgreSQL
    • MySQL
    • Greenplum
    • Linux
  • Interviews
    • SQL Server Interviews
    • MySQL Interviews
    • SQL Puzzles
  • DBA Scripts
    • SQL Server DBA Scripts
    • PostgreSQL DBA Scripts
    • MySQL DBA Scripts
    • Greenplum DBA Scripts
  • Home
  • Blog Archives !
  • (: Laugh@dbrnd :)
  • Contact Me !
sqlserverinterviews
Home 2017 December PostgreSQL: Understand the Proof of MVCC (Use XMIN Column)

PostgreSQL: Understand the Proof of MVCC (Use XMIN Column)

This article is half-done without your Comment! *** Please share your thoughts via Comment ***

If you don’t know about the MVCC, please visit the below article.
Because without knowing the MVCC, you should not start the learning of PostgreSQL.

What is Multi Version Concurrency Control (MVCC)

Many times, I shared information on MVCC like ONLY INSERT concept where every update is a new version of data.

In today’s post, I am sharing a proof of MVCC.
Not in detail, but with the small and easy demonstration.

The XMIN is a pseudo column of PostgreSQL which used to track concurrent row access.
Using XMIN, you can get an exact number which internally uses by MVCC operations.

Please check the below demonstration:

Create a table with a sample record:

1
2
3
CREATE TABLE tbl_MVCCDemo (ID INT, CODE CHARACTER VARYING);
 
INSERT INTO tbl_MVCCDemo VALUES (1,'XVK98');

Check the value of XMIN pseudo column:

1
2
3
4
5
6
SELECT XMIN,ID,CODE
FROM tbl_MVCCDemo;
 
xmin | id | code
----------------------
622 | 1 | XVK98

Now, update a record using XMIN:

1
2
UPDATE tbl_MVCCDemo SET code = 'T2738'
WHERE XMIN = 622;

Check the value of XMIN pseudo column:
We updated the value base on XMIN, then also the value of XMIN changed from 622 TO 623.
So this is proof that MVCC architecture inserts the new row for each update.

1
2
3
4
5
6
SELECT XMIN,ID,CODE
FROM tbl_MVCCDemo;
 
xmin | id | code
----------------------
623 | 1 | XVK98

Dec 19, 2017Anvesh Patel
PostgreSQL: Must know about DATE ADD operationPostgreSQL: Cannot Create a table with Reserved Keyword
Comments: 6
  1. Pisey
    December 21, 2017 at 3:20 am

    Hi, thank you for this, but i still don’t understand when i tried to select xmin from my table(107 rows)
    i saw the XMIN is duplicated many rows. Does it mean those rows which have the same XMIN is a concurrent row access?
    —————————————
    select xmin,* from employees;

    2595 199 Douglas Grant DGRANT 650.507.9844
    2595 200 Jennifer Whalen JWHALEN 515.123.4444
    2595 201 Michael Hartstein MHARTSTE 515.123.5555
    2595 202 Pat Fay PFAY 603.123.6666
    2595 203 Susan Mavris SMAVRIS 515.123.7777
    2595 204 Hermann Baer HBAER 515.123.8888
    2595 205 Shelley Higgins SHIGGINS 515.123.8080
    2595 206 William Gietz WGIETZ 515.123.8181
    2595 100 Steven King SKING 515.123.4567
    2595 101 Neena Kochhar NKOCHHAR 515.123.4568
    2595 102 Lex De Haan LDEHAAN 515.123.4569
    2595 103 Alexander Hunold AHUNOLD 590.423.4567
    2595 104 Bruce Ernst BERNST 590.423.4568
    2595 105 David Austin DAUSTIN 590.423.4569
    2595 106 Valli Pataballa VPATABAL 590.423.4560
    2595 107 Diana Lorentz DLORENTZ 590.423.5567
    2595 108 Nancy Greenberg NGREENBE 515.124.4569
    2595 109 Daniel Faviet DFAVIET 515.124.4169
    2595 110 John Chen JCHEN 515.124.4269
    2595 111 Ismael Sciarra ISCIARRA 515.124.4369
    2595 112 Jose Manuel Urman JMURMAN 515.124.4469
    2595 113 Luis Popp LPOPP 515.124.4567
    2595 114 Den Raphaely DRAPHEAL 515.127.4561
    2595 115 Alexander Khoo AKHOO 515.127.4562
    2595 116 Shelli Baida SBAIDA 515.127.4563
    2595 117 Sigal Tobias STOBIAS 515.127.4564
    2595 118 Guy Himuro GHIMURO 515.127.4565

    ReplyCancel
    • Anvesh Patel
      Anvesh Patel
      December 21, 2017 at 6:56 am

      Thanks for checking…
      actually, old xmin becoming frozen so not sure about this.
      I need more RND on this.

      ReplyCancel
      • Pisey
        December 21, 2017 at 7:03 am

        thank you then

        ReplyCancel
  2. Pisey
    December 21, 2017 at 7:45 am

    xmin:
    The identity (transaction ID) of the inserting transaction for this row version. (A row version is an individual state of a row; each update of a row creates a new row version for the same logical row.)

    https://www.postgresql.org/docs/9.1/static/ddl-system-columns.html

    ReplyCancel
    • Anvesh Patel
      Anvesh Patel
      December 21, 2017 at 9:01 am

      thanks for info, I will look into this.
      just tested got unique xmin in my database.

      ReplyCancel
  3. Hongjie zhang
    August 20, 2019 at 10:37 am

    I think if you want to verify that ‘a new row created when updating’, you should use ‘ctid’.

    ReplyCancel

Leave a Reply Cancel reply

CAPTCHA
Refresh

*

Anvesh Patel
Anvesh Patel

Database Engineer

December 19, 2017 6 Comments PostgreSQLAnvesh Patel, database, database research and development, dbrnd, Multiversion Concurrency Control, MVCC, plpgsql, Postgres Query, postgresql, PostgreSQL Administrator, PostgreSQL Error, PostgreSQL Monitoring, PostgreSQL Performance Tuning, PostgreSQL Programming, PostgreSQL Tips and Tricks, pseudo column, xmin
About Me!

I'm Anvesh Patel, a Database Engineer certified by Oracle and IBM. I'm working as a Database Architect, Database Optimizer, Database Administrator, Database Developer. Providing the best articles and solutions for different problems in the best manner through my blogs is my passion. I have more than six years of experience with various RDBMS products like MSSQL Server, PostgreSQL, MySQL, Greenplum and currently learning and doing research on BIGData and NoSQL technology. -- Hyderabad, India.

About DBRND !

dbrnd

This is a personal blog (www.dbrnd.com).

Any views or opinions represented in this blog are personal and belong solely to the blog owner and do not represent those of people, institutions or organizations that the owner may or may not be associated with in professional or personal capacity, unless explicitly stated.

Feel free to challenge me, disagree with me, or tell me I’m completely nuts in the comments section of each blog entry, but I reserve the right to delete any comment for any reason whatsoever (abusive, profane, rude, or anonymous comments) - so keep it polite.

The content of this website is protected by copyright. No portion of this website may be copied or replicated in any form without the written consent of the website owner.

Recent Comments !
  • Anvesh Patel { Sure will do... } – May 27, 12:43 PM
  • Anvesh Patel { Great... } – May 27, 12:41 PM
  • Anvesh Patel { Great... } – May 27, 12:39 PM
  • Anvesh Patel { Great... } – May 27, 12:36 PM
  • Anvesh Patel { Great... } – May 27, 12:28 PM
  • Anvesh Patel { Great... } – May 27, 12:27 PM
  • Anvesh Patel { Great... } – May 27, 12:16 PM
  • Older »
Follow Me !
  • facebook
  • linkedin
  • twitter
  • youtube
  • google
  • flickr
© 2015 – 2019 All rights reserved. Database Research & Development (dbrnd.com)
Posting....