如何查看SQL Server表的读/写统计信息?
有没有办法找到 SQL Server 2005/2008 上表读写计数的统计信息?
我专门寻找 DMV/DMF
而不使用触发器或审核。
这里的目标是找出索引的适当填充因子 - 从这篇文章中得到了一个想法(填充因子定义)。
[更新] 关于 ServerFault 有一个后续问题
如何确定 读/写密集表 DMV/DMF统计
Is there a way to find a statistics on table read and write count on SQL Server 2005/2008?
I am specifically looking for DMVs/DMFs
without using triggers or audits.
The goal here is to find out appropriate fill factor for indexes - got an idea from this article (Fill Factor Defined).
[UPDATE] There is a follow up question on ServerFault
How to determine
Read/Write intensive table from
DMV/DMF statistics
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
以下查询可用于查找数据库中所有表的读写次数。该查询结果可以导出为 CSV 文件,然后使用 Excel 公式可以轻松计算读/写比率。在规划表上的索引时非常有用
Following query can be used to find number of read and writes on all tables in a database. This query result can be exported to CSV file and then using excel formulas you can easily calculate read/write ratio. Very useful while planning indexes on a table
记住“表”表示聚集索引或“堆” 。
Remember 'table' means the clustered index or the 'heap'.
要确定表索引的适当填充因子,您需要查看发生的页面拆分数量。这显示在
sys.dm_db_index_operational_stats
中:叶分配计数:索引叶级别的页拆分总数。
非叶分配计数:索引叶级以上的页拆分总数。
叶页合并计数:索引叶级的页合并总数。
经过一番挖掘后,我看到一些帖子说 DMV 的页面分割数没有那么有用(我个人还没有证实这一点),但还有一个性能计数器“页面分割/秒” (但它仅在 SQL Server 实例级别)。
我使用的经验法则是,普通表使用默认的 90% 填充因子,高插入表使用 70 - 85% 之间的填充因子(取决于行大小)。只读表可以使用 100% 的填充因子
To determine an appropriate fill factor for a table's indexes, you need to look at the number of page splits occuring. This is shown in
sys.dm_db_index_operational_stats
:Leaf allocation count: Total number of page splits at the leaf level of the index.
Nonleaf allocation count: Total number of page splits above the leaf level of the index.
Leaf page merge count: Total number of page merges at the leaf level of the index.
After doing a bit of digging, I've seen a few posts that say the page split numbers from the DMV's are not that useful (I haven't personally confirmed this), but there is also a performance counter "page splits/sec" (but it's is only at SQL Server instance level).
I use the rule of thumb that ordinary tables use the default 90% fill factor, high insert tables somewhere between 70 - 85% (depending on row size). Read only tables can utilise a fill factor of 100%
如果您有一个良好的聚集索引(即不断增加、唯一、狭窄),那么填充因子的真正决定性问题是表的更新方式和列的数据类型。
如果列都是固定大小(例如,整数、小数、浮点、字符)且不可为空,则更新无法增加行所需的存储空间。考虑到良好的聚集索引,您应该选择 90+ 甚至 100 的填充因子,因为不会发生页面拆分。
如果您有一些可变长度列(例如用于保存用户名的 Varchar)并且这些列在插入后很少更新,那么您仍然可以保持相对较高的填充因子。
如果您的数据长度变化很大(例如,UNC 路径、注释字段、XML),则应减小填充因子。特别是如果列经常更新并增长(如评论列)。
非聚集索引通常是相同的,只是索引键可能有更多问题(非唯一,可能不会增加)。
我认为 sys.dm_db_index_physical_stats 给出了最佳指标,但这是事后的结果。查看平均/最小/最大记录大小、平均碎片大小、平均页面空间,以了解索引空间的使用情况。
HTH。
If you have a good clustered index (i.e., ever increasing, unique, narrow) then the real determining issues for Fill Factor are how the table is updated and the data types of the columns.
If the columns are all fixed size (e.g., integer, Decimal, Float, Char) and non-nullable then an update cannot increase the storage required for a row. Given the good clustered index you should pick a Fill Factor of 90+ even 100 since page splits won't happen.
If you have a few variable length columns (e.g. a Varchar to hold User Name) and the columns are seldom updated after insert then you can still keep a relatively high Fill Factor.
If you have data that is highly variable in length (e.g., UNC paths, Comment fields, XML) then the Fill Factor should be reduced. Particularly if the columns are updated frequently and grow (like comment columns).
Non-Clustered indexes are generally the same except the index key may be more problematic (non unique, perhaps not ever increasing).
I think sys.dm_db_index_physical_stats gives the best metrics for this but it is after the fact. Look at the avg/min/max record size, avg frag size, avg page space used to get a picture of how the index space is being used.
HTH.