postgreSQL默认的隔离级别及修改

编程入门 行业动态 更新时间:2024-10-09 20:28:50

postgreSQL默认的隔离<a href=https://www.elefans.com/category/jswz/34/1766376.html style=级别及修改"/>

postgreSQL默认的隔离级别及修改

作者:瀚高PG实验室 (Highgo PG Lab)- 徐云鹤

SQL标准的4种隔离机制。

Isolation levelDirty readsNon-repeatable readsPhantoms
Read Uncommittedmay occurmay occurmay occur
Read Committeddon't occurmay occurmay occur
Repeatable Readdon't occurdon't occurmay occur
Serializabledon't occurdon't occurdon't occur

常见的关系型数据库的默认事务隔离级别采用的是READ_COMMITED,例如PostgreSQL、ORACLE、SQL Server和DB2。但是使用InnoDB引擎的MySQL数据库默认事务隔离级别是REPEATABLE_READ。

查询postgreSQL默认的隔离级别:

highgo=> show default_transaction_isolation;

 default_transaction_isolation 

-------------------------------

 read committed

(1 row)

检查当前隔离级别:

highgo=# show transaction_isolation;

 transaction_isolation 

-----------------------

 read committed

(1 row)

修改隔离级别:

1.修改当前事务的隔离级别,须在事物中执行:

highgo=# begin;

highgo=# set transaction isolation level serializable;

SET

highgo=# show transaction_isolation; 

transaction_isolation 

----------------------- 

serializable

(1 row)

2.修改当前会话默认的隔离级别:

highgo=# begin;

highgo=# set default_transaction_isolation='repeatable read';

SET

highgo=# show transaction_isolation;

 transaction_isolation 

-----------------------

 serializable

(1 row)

highgo=#  show default_transaction_isolation;

 default_transaction_isolation 

-------------------------------

 repeatable read

(1 row)

highgo=# commit;

COMMIT

highgo=# show transaction_isolation;

 transaction_isolation 

-----------------------

 repeatable read

(1 row)

--

highgo=#  show default_transaction_isolation;

 default_transaction_isolation 

-------------------------------

 read committed

(1 row)

highgo=#  set default_transaction_isolation='repeatable read';

SET

highgo=#  show default_transaction_isolation;

 default_transaction_isolation 

-------------------------------

 repeatable read

(1 row)

highgo=#  show transaction_isolation;

 transaction_isolation 

-----------------------

 repeatable read

(1 row)

如果在事物中修改默认的隔离级别是不影响当前事物的。否则即时生效。

也可以在数据库级别设置默认的隔离级别:

[highgo@db1 data]$ cat postgresql.conf |grep default_transaction_isolation

#default_transaction_isolation = 'read committed'

更多推荐

postgreSQL默认的隔离级别及修改

本文发布于:2024-02-06 15:31:56,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1749744.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:级别   postgreSQL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!