How the cdc retention value can be changed for the cleanup job?

末鹿安然 提交于 2019-12-04 00:07:49

I just discovered that the default retention value is 4320 minutes = 72 hours = 3 days.

It should be configurable by using

sp_cdc_change_job @job_type='cleanup', @retention=minutes

The maximum value is 52494800 (100 years). If specified, the value must be a positive integer. Retention is valid only for cleanup jobs.

Here's the link to the more detail explanation of sp_cdc_change_job procedure

Hope this will help someone else, too :D.

If you want to retain the CDC data indefinitly, you can simply disable the CDC cleanup job:

  1. Open SQL Server Management Studio and connect to your database server
  2. In the object explorer, expand “<instance> | SQL Server Agent | Jobs”
  3. Find the job for cleanup named “cdc.<database name>_cleanup”.
  4. Right-click the job and select "disable"

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.

By default it deletes anything older than 3 days, to change the default value to 14 days use the following script

use <Your database>
go

SELECT ([retention])/((60*24)) AS Default_Retention_days ,*
FROM msdb.dbo.cdc_jobs
go

EXEC <Your database>.sys.sp_cdc_change_job 
@job_type=N'Cleanup'
,@retention=20160 -- <60 min *24 hrs * 14 days >
go

SELECT ([retention])/((60*24)) AS Default_Retention_days ,*
FROM msdb.dbo.cdc_jobs
Go
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!