zoukankan      html  css  js  c++  java
  • PG中的事务隔离级别

    SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL SERIALIZABLE;
    set default_transaction_isolation='repeatable read';
    set transaction isolation level repeatable read;
    show transaction_isolation;
     
     
    设置默认的隔离级别,缺省的为read committed.
    postgres=# set default_transaction_isolation='repeatable read';
    postgres=# show transaction_isolation;
    transaction_isolation
    -----------------------
    repeatable read
     
     
    read committed,提交读,oltp
    postgres=# show transaction_isolation;
    transaction_isolation
    -----------------------
    read committed
     
    repeatable read,可重复读,做报表
    即一个事务中,所有的select读取的结果是一样,即都读同一个时间点上的数据。
    相当于 select * from as tabName as scn=12345;
     
    要注意的有同一行,补两个事务更新,被阻塞者是repeatable read事务,那么阻塞者提交后,被阻塞者将收到如下错误:
    ERROR: could not serialize access due to concurrent update
    如果阻塞者回退执行了回退,则持有repeatable read事务的被阻塞者也不会报错。
     
    postgres=# begin;
    postgres=# set transaction isolation level repeatable read;
    postgres=# show transaction_isolation;
    transaction_isolation
    -----------------------
    repeatable read
    postgres=# commit;
    postgres=# show transaction_isolation;
    transaction_isolation
    -----------------------
    read committed
     
    串行读 SERIALIZABLE read
    严格来说,PostgreSQL在9.1之前的版本中只是实现了其中两种,即读已提交和串行读。
    在PostgreSQL v9.1的版本中提供了三种实现方式,即在原有的基础上增加了可重复读。但串行读与可重复读测试目前没有差别。
    不过使用MVCC机制实现的数据库隔离级别和传统锁机制实现的数据库的隔离级别有细微的差异。
     
     
     
     
     
     
     
     
     


  • 相关阅读:
    mysql "The user specified as a definer ('root'@'%') does not exist" 问题
    mysql添加Federated引擎问题
    D7经典脚本[multi/handler]
    redhat7.4安装vertica-9.1.0教程
    批量在当前目录下所有的文件中添加指定字段
    mysql 水平分表技术
    linux普通用户提权
    两步完成利用procdump64+mimikatz获取win用户密码
    hibernate中对象的三种状态分析
    Hibernate 入门案例
  • 原文地址:https://www.cnblogs.com/laverne/p/12625695.html
Copyright © 2011-2022 走看看