Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@ssilva
Last active September 25, 2017 01:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ssilva/1f7e5cc2dc5ed036897bf64947eb6618 to your computer and use it in GitHub Desktop.
Save ssilva/1f7e5cc2dc5ed036897bf64947eb6618 to your computer and use it in GitHub Desktop.

In Postgres, each row has a system column xmin which holds the ID of the first transaction to have visibility over that row. Conversely, the xmax system column holds the ID of last trasaction to have visibility over that row.

DROP TABLE IF EXISTS users;
CREATE TABLE users (name varchar(80)) WITH OIDS;
INSERT INTO users VALUES ('root');
SELECT oid, xmin, xmax, name FROM users;
  oid  | xmin | xmax | name 
-------+------+------+------
 16398 |  602 |    0 | root
(1 row)
UPDATE users SET name = 'ssilva' WHERE name = 'root';
SELECT oid, xmin, xmax, name FROM users;
  oid  | xmin | xmax |  name  
-------+------+------+--------
 16398 |  603 |    0 | ssilva
(1 row)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment