如何更改清理作业的 cdc 保留值?
我正在 asp.net mvc2 应用程序上实现日志记录功能,该应用程序使用 SqlServer2008 作为数据库,使用实体框架作为数据模型。
我启用了 SqlServer 的 CDC 功能,它可以很好地记录更改,但我刚刚注意到一些旧的日志记录数据被删除了。
有谁知道 CDC 保存记录的默认期限是多少,有谁知道我如何将其设置为无限值。
I'm implementing a logging feature on a asp.net mvc2 application, that uses SqlServer2008 as a database and Entity Framework as a data model.
I enabled CDC feature of SqlServer and it's logging changes well, but I just noticed that some of the old logging data is erased.
Does anyone know what's default period CDC keeps records, and does anyone know how could I set it to indefinite value.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我刚刚发现默认保留值为 4320 分钟 = 72 小时 = 3 天。
它应该可以通过使用进行配置
这是 sp_cdc_change_job 过程的链接到更详细的说明
希望这会有所帮助其他人也一样:D。
I just discovered that the default retention value is 4320 minutes = 72 hours = 3 days.
It should be configurable by using
Here's the link to the more detail explanation of sp_cdc_change_job procedure
Hope this will help someone else, too :D.
如果您想无限期保留 CDC 数据,只需 禁用 CDC 清理作业:
以下是在何处查找该选项的示例图片:
禁用清理作业后,CDC 数据在一定时间间隔后将不再被删除。
If you want to retain the CDC data indefinitly, you can simply disable the CDC cleanup job:
Here is a sample picture of where to find the option:
After you disabled the cleanup job, the CDC data will no longer get removed after a certain time interval.
默认情况下,它会删除超过 3 天的任何内容,要将默认值更改为 14 天,请使用以下脚本
By default it deletes anything older than 3 days, to change the default value to 14 days use the following script
在 Azure SQL 中,您可以在此处查看作业
select * from cdc.cdc_jobs
返回
job_type maxtrans maxscans 连续轮询间隔保留阈值
捕获 10000 100 0 0 0 0
cleanup 0 0 0 0 4320 4999
清理作业应该是 job_type = 'cleanup'
您可以简单地删除它,这样清理就不会发生
从 cdc.cdc_jobs 中删除
其中 job_type = 'cleanup'
或将保留更新为 100 年限制内的任何值,该值以分钟为单位。
https://learn.microsoft.com/en-us/azure/azure-sql/database/change-data-capture-overview?view=azuresql#cdc-customization
In Azure SQL you can see the jobs here
select * from cdc.cdc_jobs
Returns
job_type maxtrans maxscans continuous pollinginterval retention threshold
capture 10000 100 0 0 0 0
cleanup 0 0 0 0 4320 4999
The cleanup job should be job_type = 'cleanup'
You can simply delete this so cleanup never occurs
delete from cdc.cdc_jobs
where job_type = 'cleanup'
or update to the retention to what ever value with in 100 years limit, this value is in minutes.
https://learn.microsoft.com/en-us/azure/azure-sql/database/change-data-capture-overview?view=azuresql#cdc-customization