apple=# begin;
BEGIN
apple=# set transaction ISOLATION LEVEL read committed ;
SET
apple=# select * from test;
id | info
----+-------
2 | test
3 | test1
4 | test1
5 | test
6 | test
7 | test
8 | test1
9 | test1
10 | test
11 | test
1 | test
1 | test
1 | test
1 | test
1 | test
(15 rows)

中间别的连接插入一条数据,并提交,在本事务内查询,多了一条。
apple=# select * from test;
id | info
----+-------
2 | test
3 | test1
4 | test1
5 | test
6 | test
7 | test
8 | test1
9 | test1
10 | test
11 | test
1 | test
1 | test
1 | test
1 | test
1 | test
1 | test
(16 rows)
apple=# commit;
COMMIT 设置隔离级别为可重复读:
apple=# begin;
BEGIN
apple=# set transaction ISOLATION LEVEL repeatable READ;
SET
apple=# select * from test;
id | info
----+-------
2 | test
3 | test1
4 | test1
5 | test
6 | test
7 | test
8 | test1
9 | test1
10 | test
11 | test
1 | test
1 | test
1 | test
1 | test
1 | test
1 | test
(16 rows)

中间别的连接插入一条数据,并查询:
apple=# select * from test;
id | info
----+-------
2 | test
3 | test1
4 | test1
5 | test
6 | test
7 | test
8 | test1
9 | test1
10 | test
11 | test
1 | test
1 | test
1 | test
1 | test
1 | test
1 | test
(16 rows) apple=#

设置隔离级别只能在事物段中执行:

apple=# set transaction ISOLATION LEVEL repeatable READ;
WARNING: SET TRANSACTION can only be used in transaction blocks
SET

在PG配置文件有一项配置提交级别:

#default_transaction_isolation = 'read committed'

Read committed(读已提交)

读已提交是PostgreSQL中的默认隔离级别。 当一个事务运行使用这个隔离级别时, 一个查询(没有FOR UPDATE/SHARE子句)只能看到查询开始之前已经被提交的数据, 而无法看到未提交的数据或在查询执行期间其它事务提交的数据。实际上,SELECT查询看到的是一个在查询开始运行的瞬间该数据库的一个快照。不过SELECT可以看见在它自身事务中之前执行的更新的效果,即使它们还没有被提交。

所以脏读现象将不会再发生。

还要注意的是,即使在同一个事务里两个相邻的SELECT命令可能看到不同的数据,因为其它事务可能会在第一个SELECT开始和第二个SELECT开始之间提交。即会造成不可重复读。

Repeatable read(可重复读)

可重复读隔离级别只看到在事务开始之前被提交的数据;它从来看不到未提交的数据或者并行事务在本事务执行期间提交的修改(不过,查询能够看见在它的事务中之前执行的更新,即使它们还没有被提交)。

这个级别与读已提交不同之处在于,一个可重复读事务中的查询可以看见在事务中第一个非事务控制语句开始时的一个快照,而不是事务中当前语句开始时的快照。因此,在一个单一事务中的后续SELECT命令看到的是相同的数据,即它们看不到其他事务在本事务启动后提交的修改。

最新文章

  1. 云计算之路-阿里云上:从ASP.NET线程角度对“黑色30秒”问题的全新分析
  2. GitHub新手快速入门日常操作流程
  3. C#窗体自定义控件
  4. Win7重装后,如何删除cygwin目录?
  5. SpringBoot相关
  6. 1> Strut2 Mapping to MVC
  7. SQLite语句
  8. XStream的使用方法、简单使用方法、xml的解析方法
  9. nopcommerce数据库字典
  10. Mui Webview下来刷新上拉加载实现
  11. vueX、vue中transition的使用、axios
  12. line-height各类属性值
  13. git 入门教程之 git 私服搭建教程
  14. docker 搭建简易仓库registry
  15. JavaScript 从定义到执行,你应该知道的那些事
  16. curl_init 接口
  17. Spring加载静态资源的方式
  18. 【HLSDK系列】groupinfo的基本用法
  19. 20155334 实验二 Java面向对象程序设计
  20. HDU 2114 Calculate S(n)

热门文章

  1. Nginx 403 forbidden原因及故障模拟重现(转载)
  2. PAT 1114 Family Property[并查集][难]
  3. 5.5 Components -- Customizing A Compnent's Element
  4. c#通过webrequest请求远程http服务时出现的问题
  5. firefox_flash_install_on_kali
  6. 小奇的糖果(candy)
  7. linux下如何退出tmux和重新进入tmux
  8. SQL 中 not in 查询不到数据问题
  9. 【图片下载-代码】java下载网络图片资源例子
  10. JDBC中的事物处理