在 SQLServer 中使用快照隔离级别检测 tempdb 磁盘速度对性能的影响
Detecting performance impact of tempdb disk speed with snapshot isolation level in SQLServer
我们使用 SQL 具有快照隔离级别的服务器。确切地说,它是一个读取提交的快照级别。据我所知,在这种情况下,SQLServer 使用 tempdb 中的版本存储。在我们的环境中,tempdb 存储在比主数据库慢的磁盘上。
所以问题是如何检测这种 tempdb 放置的性能影响。以及如何与我的同事争论这一点?有没有什么有用的管理观点或反击?
每次更新行时快照隔离级别是绝对正确的,SQL 服务器数据库引擎会在 tempdb
中存储原始行的副本。而且,反过来 disk latency
的效率具有挑战性。
https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/sql/snapshot-isolation-in-sql-server
- 快照隔离级别不创建临时表,它在
TempDB
中存储行的副本
- 数据库引擎从
Tempdb
检索行版本
- Read/Writes 最终会在
Tempdb
开启快照隔离级别
您可以使用此脚本按数据库查找 read/writes。无论任何隔离级别如何,您都可以确定每个数据库的总数 I/O
SELECT name AS 'Database Name'
,SUM(num_of_reads) AS 'Number of Read'
,SUM(num_of_writes) AS 'Number of Writes'
FROM sys.dm_io_virtual_file_stats(NULL, NULL) I
INNER JOIN sys.databases D
ON I.database_id = d.database_id
GROUP BY name ORDER BY 'Number of Read' DESC;
用于按物理驱动器号显示 I/O 统计信息:
SELECT left(f.physical_name, 1) AS DriveLetter,
DATEADD(MS,sample_ms * -1, GETDATE()) AS [Start Date],
SUM(v.num_of_writes) AS total_num_of_writes,
SUM(v.num_of_bytes_written) AS total_num_of_bytes_written,
SUM(v.num_of_reads) AS total_num_of_reads,
SUM(v.num_of_bytes_read) AS total_num_of_bytes_read,
SUM(v.size_on_disk_bytes) AS total_size_on_disk_bytes
FROM sys.master_files f
INNER JOIN sys.dm_io_virtual_file_stats(NULL, NULL) v
ON f.database_id=v.database_id and f.file_id=v.file_id
GROUP BY left(f.physical_name, 1),DATEADD(MS,sample_ms * -1, GETDATE());
计算不同数据库驱动器的磁盘延迟
SELECT LEFT(physical_name, 1) AS drive,
CAST(SUM(io_stall_read_ms) /
(1.0 + SUM(num_of_reads)) AS NUMERIC(10,1))
AS 'avg_read_disk_latency_ms',
CAST(SUM(io_stall_write_ms) /
(1.0 + SUM(num_of_writes) ) AS NUMERIC(10,1))
AS 'avg_write_disk_latency_ms',
CAST((SUM(io_stall)) /
(1.0 + SUM(num_of_reads + num_of_writes)) AS NUMERIC(10,1))
AS 'avg_disk_latency_ms'
FROM sys.dm_io_virtual_file_stats(NULL, NULL) AS divfs
JOIN sys.master_files AS mf ON mf.database_id = divfs.database_id
AND mf.file_id = divfs.file_id
GROUP BY LEFT(physical_name, 1)
ORDER BY avg_disk_latency_ms DESC;
希望对您有所帮助
我们使用 SQL 具有快照隔离级别的服务器。确切地说,它是一个读取提交的快照级别。据我所知,在这种情况下,SQLServer 使用 tempdb 中的版本存储。在我们的环境中,tempdb 存储在比主数据库慢的磁盘上。 所以问题是如何检测这种 tempdb 放置的性能影响。以及如何与我的同事争论这一点?有没有什么有用的管理观点或反击?
每次更新行时快照隔离级别是绝对正确的,SQL 服务器数据库引擎会在 tempdb
中存储原始行的副本。而且,反过来 disk latency
的效率具有挑战性。
https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/sql/snapshot-isolation-in-sql-server
- 快照隔离级别不创建临时表,它在
TempDB
中存储行的副本
- 数据库引擎从
Tempdb
检索行版本
- Read/Writes 最终会在
Tempdb
开启快照隔离级别
您可以使用此脚本按数据库查找 read/writes。无论任何隔离级别如何,您都可以确定每个数据库的总数 I/O
SELECT name AS 'Database Name'
,SUM(num_of_reads) AS 'Number of Read'
,SUM(num_of_writes) AS 'Number of Writes'
FROM sys.dm_io_virtual_file_stats(NULL, NULL) I
INNER JOIN sys.databases D
ON I.database_id = d.database_id
GROUP BY name ORDER BY 'Number of Read' DESC;
用于按物理驱动器号显示 I/O 统计信息:
SELECT left(f.physical_name, 1) AS DriveLetter,
DATEADD(MS,sample_ms * -1, GETDATE()) AS [Start Date],
SUM(v.num_of_writes) AS total_num_of_writes,
SUM(v.num_of_bytes_written) AS total_num_of_bytes_written,
SUM(v.num_of_reads) AS total_num_of_reads,
SUM(v.num_of_bytes_read) AS total_num_of_bytes_read,
SUM(v.size_on_disk_bytes) AS total_size_on_disk_bytes
FROM sys.master_files f
INNER JOIN sys.dm_io_virtual_file_stats(NULL, NULL) v
ON f.database_id=v.database_id and f.file_id=v.file_id
GROUP BY left(f.physical_name, 1),DATEADD(MS,sample_ms * -1, GETDATE());
计算不同数据库驱动器的磁盘延迟
SELECT LEFT(physical_name, 1) AS drive,
CAST(SUM(io_stall_read_ms) /
(1.0 + SUM(num_of_reads)) AS NUMERIC(10,1))
AS 'avg_read_disk_latency_ms',
CAST(SUM(io_stall_write_ms) /
(1.0 + SUM(num_of_writes) ) AS NUMERIC(10,1))
AS 'avg_write_disk_latency_ms',
CAST((SUM(io_stall)) /
(1.0 + SUM(num_of_reads + num_of_writes)) AS NUMERIC(10,1))
AS 'avg_disk_latency_ms'
FROM sys.dm_io_virtual_file_stats(NULL, NULL) AS divfs
JOIN sys.master_files AS mf ON mf.database_id = divfs.database_id
AND mf.file_id = divfs.file_id
GROUP BY LEFT(physical_name, 1)
ORDER BY avg_disk_latency_ms DESC;
希望对您有所帮助