4.2、提交事务

进程#1访问

  1. postgres=# begin;
  2. BEGIN
  3. postgres=# delete from tbase where id=5;
  4. DELETE 1
  5. postgres=#
  6. postgres=# select * from tbase order by id;
  7. id | nickname
  8. ----+---------------
  9. 1 | hello TBase
  10. 2 | TBase
  11. 3 | TBase
  12. 4 | TBase default

TBase也是完全支持ACID特性,没提交前开启另一个连接查询,你会看到是5条记录,这是TBase隔离性和多版本视图的实现,如下所示

进程#2访问

  1. postgres=# select * from tbase order by id;
  2. id | nickname
  3. ----+---------------
  4. 1 | hello TBase
  5. 2 | TBase
  6. 3 | TBase
  7. 4 | TBase default
  8. 5 | TBase swap
  9. (5 rows)

进程#1提交数据

  1. postgres=# commit;
  2. COMMIT
  3. postgres=#

进程#2再查询数据,这时能看到已经提交的数据了,这个级别叫“读已提交”

  1. postgres=# select * from tbase order by id;
  2. id | nickname
  3. ----+---------------
  4. 1 | hello TBase
  5. 2 | TBase
  6. 3 | TBase
  7. 4 | TBase default
  8. (4 rows)