SET-ting ALLOW_SNAPSHOT_ISOLATION ON 有何含义?
我是否应该运行
ALTER DATABASE DbName SET ALLOW_SNAPSHOT_ISOLATION OFF
如果暂时不使用快照事务 (TX) 隔离 (iso), ?
换句话说,
- 首先为什么要启用它?
- 为什么默认情况下不启用?
在 SQL Server 中启用(但暂时不使用)它的成本是多少?
--更新:
在数据库上启用快照 TX iso 级别不会将 READ COMMITTED tx iso 更改为默认值。
您可以通过运行来检查:
use someDbName;
--( 1 )
alter database someDbName set allow_snapshot_isolation ON;
dbcc useroptions;
最后一行显示当前会话的 tx iso 级别为(已提交读取)。
因此,启用快照 tx iso 级别而不更改它不会使用它,等等 为了使用它,应该发出
--( 2 )
SET TRANSACTION ISOLATION LEVEL SNAPSHOT
Update2:
我重复 [1] 中的脚本,但启用了 SNAPSHOT(但未打开),但未启用 READ_COMMITTED_SNAPSHOT
--with enabling allow_snapshot_isolation
alter database snapshottest set allow_snapshot_isolation ON
-- but without enabling read_committed_snapshot
--alter database snapshottest set read_committed_snapshot ON
-- OR with OFF
alter database snapshottest set read_committed_snapshot OFF
go
没有执行结果/行
select * from sys.dm_tran_version_store
执行 INSERT、DELETE 或 UPDATE 后
您能为我提供说明已启用 SNAPSHOT tx iso 级别的脚本吗by ( 1 ) 但未通过 ( 2 ) 打开会在 tempdb 中产生任何版本和/或增加每行 14 字节的数据大小?
我真的不明白如果版本控制由( 1 )启用但未使用(未由( 2 )设置),那么版本控制的意义是什么?
[1]
在 SQL Server 中管理 TempDB:TempDB 基础知识(版本存储:简单示例)
链接
Should I run
ALTER DATABASE DbName SET ALLOW_SNAPSHOT_ISOLATION OFF
if snapshot transaction (TX) isolation (iso) is not temporarily used?
In other words,
- why should it be enabled, in first place?
- Why isn't it enabled by default?
What is the cost of having it enabled (but temporarily not used) in SQL Server?
--Update:
enabling of snapshot TX iso level on database does not change READ COMMITTED tx iso to be default.
You may check it by running:
use someDbName;
--( 1 )
alter database someDbName set allow_snapshot_isolation ON;
dbcc useroptions;
the last row shows that tx iso level of current session is (read committed).
So, enabling snapshot tx iso level without changing to it does not use it, etc
In order to use it one should issue
--( 2 )
SET TRANSACTION ISOLATION LEVEL SNAPSHOT
Update2:
I repeat the scripts from [1] but with SNAPSHOT enabled (but not switched on) but without enabling READ_COMMITTED_SNAPSHOT
--with enabling allow_snapshot_isolation
alter database snapshottest set allow_snapshot_isolation ON
-- but without enabling read_committed_snapshot
--alter database snapshottest set read_committed_snapshot ON
-- OR with OFF
alter database snapshottest set read_committed_snapshot OFF
go
There no results/rows from from executing
select * from sys.dm_tran_version_store
after executing INSERT, DELETE or UPDATE
Can you provide me with scripts illustrating that enabled SNAPSHOT tx iso level by ( 1 ) but not switched on by ( 2 ) produces any versions in tempdb and/or increase the size of data with 14 bytes per row?
Really I do not understand what is the point in versioning if it is enabled by ( 1 ) but not used (not set on by ( 2))?
[1]
Managing TempDB in SQL Server: TempDB Basics (Version Store: Simple Example)
Link
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一旦在数据库中启用行版本控制(又名快照),所有写入都必须进行版本控制。在什么隔离级别下进行写入并不重要,因为隔离级别始终仅影响读取。一旦启用数据库行版本控制,任何插入/更新/删除都将:
同样,这是完全不相关的使用什么隔离级别。请注意,如果满足以下任一条件,也会发生行版本控制:
所有这些均在 行版本控制资源使用情况:
更新
As soon as row versioning (aka. snapshot) is enabled in the database all writes have to be versioned. It doesn't matter under what isolation level the write occurred, since isolation levels always affect only reads. As soon the database row versioning is enabled, any insert/update/delete will:
Again, it is completely irrelevant what isolation level is used. Note that row versioning occurs also if any of the following is true:
All this is explained in Row Versioning Resource Usage:
Update
默认情况下,快照隔离处于关闭状态。如果将其打开,SQL 将维护正在运行的事务的数据快照。
示例:在连接 1 上,您正在运行 big select。在连接 2 上,您更新了第一次选择将返回的一些记录。
在快照隔离打开时,SQL 会临时复制数据,受更新影响,因此 SELECT 将返回原始数据。
任何额外的数据操作都会影响性能。这就是为什么此设置默认为关闭的原因。
By default, you have snapshot isolation OFF, If you turn it ON, SQL will maintain snapshots of data for running transactions.
Example: On connection 1, you are running big select. On connection 2, you update some of the records that are going to be returned by first select.
In snapshot isolation ON, SQL will make a temporary copy of the data, affected by update, so SELECT will return original data.
Any additional data manipulation will affect performance. That's why this setting is OFF by default.