Sobes.tech
Middle+

Do you know what Xmin and Xmax are in PostgreSQL?

sobes.tech AI

Answer from AI

In PostgreSQL, xmin and xmax are system-internal fields used to implement the Multi-Version Concurrency Control (MVCC) mechanism.

  • xmin is the transaction ID that created (inserted) the current row. It indicates when the row became visible.
  • xmax is the transaction ID that deleted or marked the row as deleted. If xmax is zero, it means the row is not deleted.

These fields help PostgreSQL determine the visibility of rows for different transactions, ensuring data isolation and consistency without locks.

Example: When executing a query, PostgreSQL checks xmin and xmax of each row to understand whether it should be visible to the current transaction.