自动管理分区
2017-05-23 17:41
162 查看
表分区的一个好处:能够避免Deadlock,分区之间是相互独立的,对一个分区加X锁,不会对其他分区产生contention。在项目中,有如下 Partition Function 和 Partition Scheme
查看ETL的execution log,有时会发现 Deadlock Issue,对相关package Troubleshooting发现,发生deadlock的root cause是:同时更新表的两条语句产生contention,导致deadlock。仔细check代码,更新的两条查询语句都使用Partition Column(DataSourceID) 作为过滤条件。我推测,可能是这两个DataSourceID位于同一个Partition。1,验证boundary value
2,创建Job,自动分区最佳实践,如果一个partition是non-empty,那么split range会导致data movement,这可能是一个非常耗费IO的一个process,为了避免extensive data movement,最好是预留一个empty partition,每次都从empty partition 中split range。
本例将分区全部存放在Primary FileGroup, 如果需要将不同的Partition存储在不同的FileGroup,那么可以增加Create filegroup的代码。3,在Job执行时,Issue an errorExecuted as user: NT SERVICE\SQLSERVERAGENT. UNKNOWN TOKEN failed because the following SET options have incorrect settings: 'QUOTED_IDENTIFIER'. Verify that SET options are correct for use with indexed views and/or indexes on computed columns and/or filtered indexes and/or query notifications and/or XML data type methods and/or spatial index operations. [SQLSTATE 42000] (Error 1934). The step failed.QUOTED_IDENTIFIER设置错误,添加下面的script,即可
SET QUOTED_IDENTIFIER must be ON when you are creating a filtered index.
SET QUOTED_IDENTIFIER must be ON when you invoke XML data type methods.
CREATE PARTITION FUNCTION [funcPartition_int_DataSourceID](int) AS RANGE LEFT FOR VALUES (1, 2, 3)CREATE PARTITION SCHEME [schePartition_int_DataSourceID] AS PARTITION [funcPartition_DataSourceID] TO ([PRIMARY], [PRIMARY], [PRIMARY], [PRIMARY])create table dbo.dt_test ( ...More column definition DataSourceID int)on [schePartition_int_DataSourceID](DataSourceID)
查看ETL的execution log,有时会发现 Deadlock Issue,对相关package Troubleshooting发现,发生deadlock的root cause是:同时更新表的两条语句产生contention,导致deadlock。仔细check代码,更新的两条查询语句都使用Partition Column(DataSourceID) 作为过滤条件。我推测,可能是这两个DataSourceID位于同一个Partition。1,验证boundary value
select prv.function_id,pf.name,pf.boundary_value_on_right,prv.value as BoundaryValuefrom sys.partition_range_values prvinner join sys.partition_functions pf on prv.function_id=pf.function_idwhere pf.name='funcPartition_int_DataSourceID'BoundaryValue的值小于当前 DataSourceID的最大值,产生 contention的两个DataSourceID 在最右边的partition中。随着项目数据的增加和人员的更替,缺少合理的管理计划,导致额外增加的DataSourceID都被分配到同一个partition中。
2,创建Job,自动分区最佳实践,如果一个partition是non-empty,那么split range会导致data movement,这可能是一个非常耗费IO的一个process,为了避免extensive data movement,最好是预留一个empty partition,每次都从empty partition 中split range。
use db_studygodeclare @CurrentMaxBoundaryValue intdeclare @ExistingMaxDataSourceID intdeclare @BoudaryValue intselect @ExistingMaxDataSourceID = max(dds.DataSourceID)from dbo.dt_DataSource dds with(nolock)select @CurrentMaxBoundaryValue= max(cast(prv.value as int))from sys.partition_functions pf inner join sys.partition_range_values prv on pf.function_id=prv.function_idwhere pf.name='funcPartition_int_DataSourceID'-- add new boundary valueif @CurrentMaxBoundaryValue<@ExistingMaxDataSourceID+1begin set @BoudaryValue=@CurrentMaxBoundaryValue+1 DECLARE @SQL NVARCHAR(MAX)=N'ALTER PARTITION SCHEME [schePartition_int_DataSourceID] NEXT USED [PRIMARY] ALTER PARTITION FUNCTION [funcPartition_int_DataSourceID]() SPLIT RANGE (' declare @ExecSql nvarchar(max) set @ExecSql='' while @BoudaryValue<=@ExistingMaxDataSourceID+1 BEGIN SELECT @ExecSql = @SQL+ cast(@BoudaryValue as varchar(10))+ N')' EXEC(@ExecSql) set @BoudaryValue=@BoudaryValue+1 endend
本例将分区全部存放在Primary FileGroup, 如果需要将不同的Partition存储在不同的FileGroup,那么可以增加Create filegroup的代码。3,在Job执行时,Issue an errorExecuted as user: NT SERVICE\SQLSERVERAGENT. UNKNOWN TOKEN failed because the following SET options have incorrect settings: 'QUOTED_IDENTIFIER'. Verify that SET options are correct for use with indexed views and/or indexes on computed columns and/or filtered indexes and/or query notifications and/or XML data type methods and/or spatial index operations. [SQLSTATE 42000] (Error 1934). The step failed.QUOTED_IDENTIFIER设置错误,添加下面的script,即可
SET QUOTED_IDENTIFIER ON参考:SET QUOTED_IDENTIFIER (Transact-SQL)SET QUOTED_IDENTIFIER must be ON when you are creating or changing indexes on computed columns or indexed views. If SET QUOTED_IDENTIFIER is OFF, CREATE, UPDATE, INSERT, and DELETE statements on tables with indexes on computed columns or indexed views will fail.
SET QUOTED_IDENTIFIER must be ON when you are creating a filtered index.
SET QUOTED_IDENTIFIER must be ON when you invoke XML data type methods.
相关文章推荐
- 自动管理分区
- oracle11G新特性区间分区(对时间或数字分区自动管理)
- GPT分区表 管理 自动挂载于2T的分区
- linux之脚本管理自动挂载所有windows分区的脚本
- 关于 Ubuntu 自动挂载 Windows 分区
- .NET Framework 自动内存管理机制深入剖析 (转载)
- 自动检测并加载分区脚本
- 如何让程序自动管理线程
- ERP基础档案管理模块中实现多级分类档案ID号自动编码技术(V1.0)
- 如何让程序自动管理线程
- Oracle的分区管理
- (转).NET Framework 自动内存管理机制深入剖析 (C#分析篇)
- 多线程学习(二)-线程池和定时器——多线程的自动管理
- 分区计量管理系统
- 名片OCR自动识别管理软件
- 四、线程池和定时器——多线程的自动管理
- ROS 做PCQ脚本集体(每IP)自动限速 +带宽按端口管理流量
- linux下各种分区的自动挂载和卸载.
- 可变分区存储管理
- 多线程学习(二)-线程池和定时器——多线程的自动管理