Loading topic
SELECT and an UPDATE run against the same row at the same time, and neither waits for the other. The mechanism is multiversion concurrency control (MVCC). This chapter explains how MVCC works, what a snapshot is, and which cases MVCC does not cover. Those cases are why the rest7 min readBEGIN, COMMIT and ROLLBACK. It also assumes you can run two psql sessions side by side. You should know what a primary key is. The previous chapter explained why MVCC (multiversion concurrency control) lets readers and writers work without7 min readpsql sessions. It also assumes you know that a lock taken inside a transaction is held until COMMIT or ROLLBACK, and that you have the accounts table from the earlier chapters. After reading, you should be able to predict whether two statements6 min readpsql sessions side by side, and have read the earlier chapters on MVCC and on locks lasting until the end of a transaction. Table-level locks come in the previous chapter. This one covers row-level locks: what takes them, which 7 min readFOR clauses from the earlier chapters. You should be able to run two or three psql sessions side by side. Here you will see what happens when a lock request cann7 min readBEGIN, COMMIT, ROLLBACK), and how to run two psql sessions side by side. It also assumes you have read the earlier chapters on lock lifetime and row-level locks. Here you will see how two transactions can end up waiting on each other, an7 min readBEGIN, COMMIT and ROLLBACK, and have read the previous chapter on how a deadlock forms. Here you will see what PostgreSQL does after a cycle of waits exists: when it looks for the cycle, how it chooses a victim, what the error7 min readFOR UPDATE, FOR NO KEY UPDATE, FOR SHARE and FOR KEY SHARE. Here you turn that knowledge into habits you c7 min readBEGIN, COMMIT and ROLLBACK work, and you have read the earlier chapters on row locks, table locks and the lock queue. Here you will learn how to put an upper bound on waiting, so that one stuck transaction cannot stall7 min readSELECT ... FOR UPDATE, and that you can run two psql sessions side by side. By the end you will be able to:6 min readlock_timeout behaves. It applies them to one job: changing a live table's structure while the application keeps running.6 min readpg_locks. You also need two psql sessions to try the examples.7 min read