Is there a way to know when cleanup of change tracking tables occurs? How to check the last occurrence of a cleanup process?
BACKGROUND:
I have Change Tracking on database with retention set to 1 minute:
ALTER DATABASE [test] SET CHANGE_TRACKING = ON (CHANGE_RETENTION = 1 MINUTES)
I do some updates in my test table and then wait a bit longer than the retention period (lets say 3 minutes). As the cleanup process is asynchronous, I do understand that there NO guarantee that Change Tracking tables will be cleaned up after 1 minute. It can happen at any time that is > 1 min.
I found this procedure to call the cleanup process manually:
EXEC sp_flush_commit_table_on_demand 100000
But it does not work as expected.. (Change Tracking rows are still in place after retention period)
Best Answer
I reproduced this using the code below, and essentially, yes, if you wait long enough, and auto cleanup is on, it will clean itself out. It appears to be bound the a minimum - that is, the change_retention setting is more of a suggestion than a command.
Admittedly, I haven't tested with real-world table activity, etc., but the links below contain more information about what the job does - it's more of a black box, really, than anything.
Links:
MS Change Tracking
Kendra Little on Change Tracking
Song Lyrics - Courtesy of Disney
Here's what I came up with.