Bitpath

Boss lesson · Unit 04

Inside Postgres

Row versions, the write-ahead log, VACUUM and replicas

13 exercisesabout 3 min

What you practise

  • Pages and the heap, the write-ahead log and crash recovery, MVCC row versions and why UPDATE writes a new row, dead tuples and VACUUM, the buffer cache, streaming replication and read replicas

Try a question from this lesson

Pick one

You UPDATE a balance from 100 to 70. A transaction that began earlier must keep reading 100 from its snapshot. So where is the 100 now?

The ideas

Concept cards are short on purpose. In the app they appear between questions, after you have met the idea.

Concept

Rows have versions

An UPDATE writes a new version of the row and marks the old one as ended.

Each version records the transaction that created it (xmin) and the one that ended it (xmax). A snapshot simply picks the version that was current when it was taken.

This is MVCC: multi-version concurrency control.

xmin  xmax  name  balance
 100   205  Ana       100  <- old
 205     -  Ana        70  <- new

Concept

The write-ahead log

Rewriting data pages on disk at every commit would be slow: the pages are scattered all over the file.

So each change is first appended to one sequential file, the write-ahead log (WAL). COMMIT returns once the log is safely on disk. The data pages are written later, in the background.

After a crash, Postgres replays the log.

10 more exercises in the app

  • 2× type the answer
  • 5× multiple choice
  • 1× true or false
  • 1× order the lines
  • 1× match the pairs

Bitpath is an iOS app in development. Join the waitlist and you get one email when it is ready to try.

One email when Bitpath is ready to try. Nothing else. Privacy