postgresql 事务隔离级别 set transaction isolation level
生活随笔
收集整理的這篇文章主要介紹了
postgresql 事务隔离级别 set transaction isolation level
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
os: centos 7.4
db: postgresql 10.11
postgresql 默認的 isolation level 為 read committed,可以調整隔離級別。
版本
# cat /etc/centos-release CentOS Linux release 7.4.1708 (Core) # # # su - postgres Last login: Wed Jan 15 18:34:12 CST 2020 on pts/0 $ $ $ psql -c "select version();"version ----------------------------------------------------------------------------------------------------------PostgreSQL 10.11 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-39), 64-bit (1 row)set transaction isolation level
postgres=# select name,setting from pg_settings where name like 'transaction%';name | setting ------------------------+----------------transaction_deferrable | offtransaction_isolation | read committedtransaction_read_only | off (3 rows)postgres=# \h set transaction Command: SET TRANSACTION Description: set the characteristics of the current transaction Syntax: SET TRANSACTION transaction_mode [, ...] SET TRANSACTION SNAPSHOT snapshot_id SET SESSION CHARACTERISTICS AS TRANSACTION transaction_mode [, ...]where transaction_mode is one of:ISOLATION LEVEL { SERIALIZABLE | REPEATABLE READ | READ COMMITTED | READ UNCOMMITTED }READ WRITE | READ ONLY[ NOT ] DEFERRABLE postgres=# set transaction isolation level serializable; WARNING: SET TRANSACTION can only be used in transaction blocks SETserializable
postgres=# begin; postgres=# set transaction isolation level serializable; postgres=# show transaction_isolation;transaction_isolation -----------------------serializable (1 row)postgres=# rollback;repeatable read
postgres=# begin; postgres=# set transaction isolation level repeatable read; postgres=# show transaction_isolation;transaction_isolation -----------------------repeatable read (1 row)postgres=# rollback;read committed
postgres=# begin; postgres=# set transaction isolation level read committed; postgres=# show transaction_isolation;transaction_isolation -----------------------read committed (1 row)postgres=# rollback;read uncommitted
postgres=# begin; postgres=# set transaction isolation level read uncommitted; postgres=# show transaction_isolation;transaction_isolation -----------------------read uncommitted (1 row)postgres=# rollback;begin
postgres=# \h begin Command: BEGIN Description: start a transaction block Syntax: BEGIN [ WORK | TRANSACTION ] [ transaction_mode [, ...] ]where transaction_mode is one of:ISOLATION LEVEL { SERIALIZABLE | REPEATABLE READ | READ COMMITTED | READ UNCOMMITTED }READ WRITE | READ ONLY[ NOT ] DEFERRABLEserializable
postgres=# begin transaction isolation level serializable; postgres=# show transaction_isolation;transaction_isolation -----------------------serializable (1 row)postgres=# rollback;repeatable read
postgres=# begin transaction isolation level repeatable read; postgres=# show transaction_isolation;transaction_isolation -----------------------repeatable read (1 row)postgres=# rollback;read committed
postgres=# begin transaction isolation level read committed; postgres=# show transaction_isolation;transaction_isolation -----------------------read committed (1 row)postgres=# rollback;read uncommitted
postgres=# begin transaction isolation level read uncommitted; postgres=# show transaction_isolation;transaction_isolation -----------------------read uncommitted (1 row)postgres=# rollback;參考:
http://postgres.cn/docs/10/sql-set-transaction.html
總結
以上是生活随笔為你收集整理的postgresql 事务隔离级别 set transaction isolation level的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: STM32H750VBT6 DMA驱动T
- 下一篇: level1和level2行情的区别