How to control PrincipalObjectAccess table growth in Microsoft Dynamics CRM 2011
https://support.microsoft.com/en-us/kb/2664150
How to control PrincipalObjectAccess table growth in Microsoft Dynamics CRM 2011
SYMPTOMS
After you use Microsoft Dynamics CRM 2011, you may notice that the size of the SQL table PrincipalObjectAccess grows and could be using a large percentage of the database size.
CAUSE
When records are deleted in Microsoft Dynamics CRM, the related PrincipalObjectAccess records are not removed.
RESOLUTION
Apply Update Rollup 6, and then execute the script that is documented here. This script must be executed only one time after you apply Update Rollup 6. Update Rollup 6 and future Update Rollups will fix this known issue.
SQL Script To Execute
--Replace the text "Replace With DatabaseName" with your database name --For Example --USE [AdventureWorksCycle_MSCRM]
USE [<Replace With DatabaseName>]
GO BEGIN TRY
BEGIN TRAN t1 IF NOT EXISTS (SELECT * FROM sys.sysobjects WHERE id = object_id(N'[dbo].[ToDeletePOAEntries]') AND ObjectProperty(id, N'IsUserTable') = 1) create table ToDeletePoaEntries
(
ObjectId uniqueidentifier,
Otc int
) IF NOT EXISTS (SELECT * FROM sys.sysindexes si INNER JOIN sys.sysobjects so ON si.id = so.id WHERE so.id = OBJECT_ID(N'[dbo].[ToDeletePoaEntries]') AND OBJECTPROPERTY(so.id, N'IsUserTable') = 1 AND si.name LIKE '%mainindex%') CREATE UNIQUE NONCLUSTERED INDEX [mainindex] ON [dbo].[ToDeletePoaEntries]
(
[ObjectId] ASC,
[Otc] ASC
)WITH (STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ----- Insert records to be deleted in ToDeletePoaEntries -- go through all user-owned entities which are not replicated and don't support duplicate detection
declare entity_cursor cursor local FORWARD_ONLY READ_ONLY
for select distinct e.ObjectTypeCode, e.BaseTableName, a.PhysicalName from EntityView e
inner join AttributeView a on e.EntityId = a.EntityId and a.IsPKAttribute = 1
where e.IsReplicated = 0 and e.IsDuplicateCheckSupported = 0 and e.OwnershipTypeMask & 1 = 1 open entity_cursor declare @baseTableName sysname
declare @otc nvarchar(20)
declare @primaryKey sysname
declare @totalCollected int = 0
declare @currentCollected int declare @tempRowCount int = 0
declare @collectstatement nvarchar(max) fetch next from entity_cursor
into @otc, @baseTableName, @primaryKey while @@FETCH_STATUS = 0
begin
print 'Cleaning up POA for ' + @baseTableName set @currentCollected = 0 set @collectstatement = 'insert into ToDeletePoaEntries(ObjectId, Otc)
select distinct poa.ObjectId, poa.ObjectTypeCode
from PrincipalObjectAccess poa
left join ' + @baseTableName + ' e on poa.ObjectId = e.' + @primaryKey +
' where e.' + @primaryKey + ' is null and poa.ObjectTypeCode = ' + @otc; print @collectstatement exec(@collectstatement)
set @tempRowCount = @@ROWCOUNT
set @currentCollected = @currentCollected + @tempRowCount
print CAST(@currentCollected as nvarchar(20)) + ' records collected for ' + @baseTableName
set @totalCollected = @totalCollected + @currentCollected fetch next from entity_cursor
into @otc, @baseTableName, @primaryKey
end close entity_cursor
deallocate entity_cursor print CAST(@totalCollected as nvarchar(20)) + ' total records collected' -- Delete query -- This scripts cleans up orphaned POA records for selected entities declare @deleteBatchSize int = 50000
declare @deleteBatchSizeNVarChar nvarchar(10) = CAST(@deleteBatchSize as nvarchar(10))
declare @totalDeleted int = 0
declare @currentDeleted int
declare @deletestatement nvarchar(max) set @currentDeleted = 0
set @tempRowCount = 0 -- delete all records of the current entity type which don't have corresponding object in the base table
set @deletestatement = 'delete top (' + @deleteBatchSizeNVarChar + ') from PrincipalObjectAccess
from PrincipalObjectAccess poa
join ToDeletePoaEntries e on poa.ObjectId = e.ObjectId and poa.ObjectTypeCode = e.Otc' print @deletestatement -- delete PrincipalObjectAccess records in batches
exec(@deletestatement)
set @tempRowCount = @@ROWCOUNT
set @currentDeleted = @currentDeleted + @tempRowCount while @tempRowCount = @deleteBatchSize
begin
exec(@deletestatement)
set @tempRowCount = @@ROWCOUNT
set @currentDeleted = @currentDeleted + @tempRowCount print CAST(@currentDeleted as nvarchar(20)) + ' records deleted ' + cast(getUtcdate() as nvarchar(50))
--cleanup end COMMIT TRAN t1 -- Cleanup DROP Table [dbo].[ToDeletePoaEntries]
PRINT 'EXECUTION SUCCEED'
END TRY
BEGIN CATCH
ROLLBACK TRAN t1 -- Cleanup DROP Table [dbo].[ToDeletePoaEntries] PRINT 'EXECUTION FAILED :' + ERROR_MESSAGE()
END CATCH
MORE INFORMATION
This script only needs to be run one time after Update Rollup 6 or a future Update Rollup is installed. After the script is run to clean up the PrincipalObjectAccess table, the script does not need to be run after any future Update Rollup installations.
Article ID: 2664150 - Last Review: 06/27/2012 12:54:00 - Revision: 6.0
- kbmbsmigrate kbsurveynew KB2664150
How to control PrincipalObjectAccess table growth in Microsoft Dynamics CRM 2011的更多相关文章
- Microsoft Dynamics CRM4.0 和 Microsoft Dynamics CRM 2011 JScript 方法对比
CRM 2011 如果需要再IE里面调试,可以按F12在前面加上contentIFrame,比如 contentIFrame.document.getElementById("字段" ...
- Microsoft Dynamics CRM 2011的组织服务中的RetrieveMultiple方法(转)
本篇文章,介绍Microsoft Dynamics CRM 2011的组织服务中的RetrieveMultiple方法. RetreiveMultiple方法,用于获取实体的多个实例,该方法的签名如下 ...
- Dynamices CRM JS 类库 神器 XrmServiceToolkit - A Microsoft Dynamics CRM 2011 & CRM 2013 JavaScript Library
XrmServiceToolkit - A Microsoft Dynamics CRM 2011 & CRM 2013 JavaScript Library http://xrmservic ...
- Error message “Assembly must be registered in isolation” when registering Plugins in Microsoft Dynamics CRM 2011 2013 解决办法
Error message “Assembly must be registered in isolation” when registering Plugins in Microsoft Dynam ...
- Microsoft Dynamics CRM 2011 相关-摘自网络
Microsoft Dynamics CRM Server 2011硬件需求: 组件 *最低要求 *推荐配置 处理器 x64 体系结构或兼容的双核 1.5 GHz 处理器 四核 x64 体系结构 2 ...
- Microsoft Dynamics CRM 2011 当您在 大型数据集上执行 RetrieveMultiple 查询很慢的解决方法
症状 当您在 Microsoft Dynamics CRM 2011 年大型数据集上执行 RetrieveMultiple 查询时,您会比较慢. 原因 发生此问题是因为大型数据集缓存 Retrieve ...
- 转:JavaScript Reference for Microsoft Dynamics CRM 2011 / 2013
JavaScript Reference for Microsoft Dynamics CRM 2011 / 2013 98 Replies Here’s a quick reference guid ...
- Microsoft Dynamics CRM 2011 安装完全教程
作者:卞功鑫,转载请保留.http://www.cnblogs.com/BinBinGo/p/4302612.html 环境介绍 WINDOWS 2008 R2 Datacenter Microsof ...
- Microsoft Dynamics CRM 2011 面向Internet部署 (IFD) ADFS虚拟机环境搭建的步骤(CRM与ADFS装在同一台服务器上) 摘自网络
1: 安装windows server 2008 R2 中文版 (过程略) 安装完成后设置机器名和IP地址, 本过程机器名 crm5dev,192.168.0.110 dns: 192.168.0.1 ...
随机推荐
- JS对日期时间的操作
代码: //判断是否超期(有效期开始超过一年后算已超期) function IsEffect(effectDate) { var val = ""; var currentDate ...
- CA接口测试类
package com.creditharmony.adapter.testCase.ca; import org.junit.Test; import com.alibaba.druid.util. ...
- 导入和导出表空间:复制文件比mysqldump&restore快
#生成测试数据server1:mysql> CREATE TABLE test (c1 INT PRIMARY KEY)engine = innodb;Query OK, 0 rows affe ...
- HTML5新事物
1 指定编码字符集,极力推荐 <meta charset="utf-8"> 2 指定lang,所有的标签上都有,推荐在<html>上指定. 3 css样式的 ...
- SQL Server 2008中SQL增强之三:Merge(在一条语句中使用Insert,Update,Delete) 一条语句实现两表同步(添加、删除、修改)
MERGE 目标表 USING 源表 ON 匹配条件 WHEN MATCHED THEN 语句 WHEN NOT MATCHED THEN 语句; http://www.chinaz.com/prog ...
- IOS开发-手势简单使用及手势不响应处理办法
1.点击 2.长按 3.拖拽 4.轻扫.捏合.旋转 5.使用手势需要注意的地方 1.注意处理轻扫和拖拽的冲突 //那个时间短的话 就让那个先执行 //处理 拖拽和轻扫 两个手势的冲突 //需要轻扫手势 ...
- Discuz!NT 3.9.913 Beta DIY过程
前提: 论坛的源码版本为dnt_3.9.913_sqlserver_beta.zip,以下例子都以这个版本为原型修改 dnt_3.9.913数据字典:下载 目前(2013年10月21日)官网的asp. ...
- SPOJ #5 The Next Palindrome
"not more than 1000000 digits" means an efficient in-place solution is needed. My first so ...
- 【解决方案】: hyper-v 导入虚拟机报这个错误 32784
从win server 2012创建的虚拟机 导出后, 想导入到本机win8系统上,结果报错 32784, google了一堆,都说不支持... 实际上 1.在win8系统上 新建一个不带硬盘的虚拟机 ...
- 剑指offer系列46---和为s的连续正数序列
[题目]输出所有和为S的连续正数序列.序列为:1,2,3,4,5,6,7,8................ * 序列内按照从小至大的顺序,序列间按照开始数字从小到大的顺序 package com.e ...