Search code examples
postgresqlmvcc

How TOAST behaves in MVCC Postgres


Good day, I was reading Postgres documentation about TOAST but I didn't find anything about how TOAST works in terms of MVCC. According to documentation of postgres.

The TOAST management code is triggered only when a row value to be stored in a table is wider than TOAST_TUPLE_THRESHOLD bytes (normally 2 kB).

As far as I understand if field is big enough and has variable length then postgres doesn't store this field directly in tuple block but it stores a reference to the different table(file) that contains this field with chunk_id and sequence_id. However, what about MVCC. Let's say I have a table user(data jsonb , id int PK,name varchar(255)). Usually when row is updated then new row will be created with xmin equals to the current transaction. Let's say that jsonb field is in the TOAST table and this field is not updated, will postgres create a new TOAST instance for updated row or new row will have a new reference to the existing TOAST value ?


Solution

  • See here:

    During an UPDATE operation, values of unchanged fields are normally preserved as-is; so an UPDATE of a row with out-of-line values incurs no TOAST costs if none of the out-of-line values change.