<@U04S8PLJWMT> on Airbyte MSSQL connector using Ch...
# ask-ai
k
@kapa.ai on Airbyte MSSQL connector using Change Data Capture, I have the error below on the last collect:
Copy code
Failure in source: Saved offset no longer present on the server. Please reset the connection, and then increase binlog retention and/or increase sync frequency.
The log retention is currently defined at 3 days. What is the root cause of this error with concrete explanations and how can I fix it ?
k
The error message:
Copy code
Failure in source: Saved offset no longer present on the server. Please reset the connection, and then increase binlog retention and/or increase sync frequency.
Root Cause: This error occurs because the saved offset (the last position Airbyte read from the SQL Server Change Data Capture (CDC) log) is no longer available on the server. In SQL Server, CDC data is retained for a configurable period (by default, 3 days). If Airbyte tries to resume syncing from an offset that has already been purged by SQL Server's CDC cleanup job, the sync fails. This situation is especially likely if: - The sync frequency is too low (not frequent enough), so the offset is lost before the next sync. - There are periods of inactivity (no changes in the source tables), so the commit LSN (log sequence number) is not updated, and after the retention period, the offset is out of range. - The CDC retention period is too short for your sync schedule. This is confirmed by user reports and logs, where the sync fails after the retention period if no data changes have occurred, causing the commit_lsn to be out of range after the third day. The cleanup job removes old CDC entries, and Airbyte cannot find the offset it needs to continue incremental syncs, resulting in this error [source-mssql] sync fails with CDC and no changes. How to Fix: 1. Increase CDC Retention Period: Extend the retention period of CDC data in SQL Server to ensure that the required log entries are available when Airbyte runs its sync. For example, you can set the retention to 10 days (14,400 minutes):
Copy code
sql    EXEC sp_cdc_change_job @job_type='cleanup', @retention = 14400;    EXEC sys.sp_cdc_stop_job @job_type = 'cleanup';    EXEC sys.sp_cdc_start_job @job_type = 'cleanup';
[Setting up CDC for MSSQL](https://docs.airbyte.com/integrations/sources/mssql#4-extend-the-retention-period-of-cdc-data) 2. Increase Sync Frequency: Run Airbyte syncs more frequently so that the offset is always within the CDC retention window. 3. Reset the Connection: If the error has already occurred, you must reset the Airbyte connection to perform a full refresh and re-establish a valid offset. Summary: The error is caused by the CDC log entries being purged before Airbyte can read them, due to a short retention period or infrequent syncs. Increase the CDC retention period and/or sync more frequently to prevent this issue in the future [source-mssql] sync fails with CDC and no changes, [Setting up CDC for MSSQL](https://docs.airbyte.com/integrations/sources/mssql#4-extend-the-retention-period-of-cdc-data).
k
@kapa.ai I do confirm no change happened on the replicated tables for more than 3 days, meaning more than the currently defined retention log duration. I can not increase the CDC retention period. Also, I do not understand why increasing the sync frequency will help to prevent from this error to appear again. Could you explain concretely why ?
k
A message from kapa.ai
Certainly! Here’s a concrete explanation based on the knowledge sources: When using Airbyte’s MSSQL CDC connector, Airbyte keeps track of the last position (offset) it has read from the SQL Server CDC logs. SQL Server only retains CDC data for a limited period (in your case, 3 days). If no changes occur in the replicated tables for more than 3 days, the CDC cleanup job will remove the old log entries, including the offset Airbyte last read. Why does increasing sync frequency help? - Each sync reads up to the latest available offset and saves it. - If you sync more frequently (e.g., every day or every few hours), Airbyte will always update its saved offset to a value that still exists in the CDC logs. - If you wait longer than the retention period (e.g., 4 days with a 3-day retention), the offset Airbyte tries to resume from will have been deleted by SQL Server, causing the error. In summary: Increasing sync frequency ensures that Airbyte’s saved offset is always within the range of CDC data still present on the server. If you sync less frequently than the retention period, the offset will be purged, and Airbyte cannot continue incremental syncs, resulting in the error you saw. This is confirmed by user reports and explanations in the knowledge sources: > “When no rows are transported the 'commit_lsn' won’t be updated. This leads to the 'commit_lsn' being out of range after the third day.” > “The MS SQL Server executes the cleanup job every night at 2AM... Currently our retention period is 3 days and the transport consistently fails in the 4th night.” ([source-mssql] sync fails with CDC and no changes) So, increasing sync frequency helps by ensuring Airbyte always saves a valid offset before the old one is deleted. If you cannot increase the retention period, syncing more often is the only way to avoid this error under your constraints.
k
@kapa.ai We are already syncing every day for a retention duration of 3 days. As no row is updated for more than 3 days (ie more than the retention period), I suppose the commit_lsn will not change in the source database, even if we sync it more frequently than every day. Are you sure that increasing the sync frequency will help, in the precise case were no row is updated for a long period ?
k
A message from kapa.ai
You are correct in your understanding, and your reasoning is supported by the knowledge sources. If no row is updated in the replicated tables for longer than the CDC retention period (e.g., no changes for 4 days, but retention is 3 days), then even if you sync more frequently (e.g., every day or even every hour), the commit_lsn (the offset) will not advance. This is because Airbyte only updates its saved offset when there are new changes to replicate. If there are no changes, the offset remains the same, and after the retention period, SQL Server will purge the old CDC entries, including the offset Airbyte is tracking. This scenario is described in the following way: > When no rows are transported the "commit_lsn" won’t be updated. This leads to the "commit_lsn" being out of range after the third day. ([source-mssql] sync fails with CDC and no changes) So, in the specific case where there are no changes in the source tables for longer than the retention period, increasing the sync frequency will NOT prevent the error. The only ways to avoid this error are to either increase the CDC retention period (which you said is not possible) or ensure that at least one change occurs in the replicated tables within each retention window. If neither is possible, this limitation is inherent to how SQL Server CDC and Airbyte's CDC implementation work together, and there is no workaround documented in the knowledge sources for this scenario.
k
@kapa.ai If we create a dummy table with 1 forced change per day and sync it using CDC, do you confirm it will help to prevent from this error to appear again ?
k
A message from kapa.ai
Yes, based on the knowledge sources, creating a dummy table with at least one forced change per day and including it in your CDC sync can help prevent this error. This approach works because each change in the dummy table will generate a new CDC log entry and advance the commit_lsn. As a result, Airbyte will be able to update its saved offset to a value that is always within the CDC retention window, even if your main tables have no changes. This workaround is specifically mentioned by users who faced the same issue: > "We created some frequently changing token tables with CDC set up on them and added those tables to the CDC jobs which had tables that did not change frequently (ie, that didn’t change within the log retention period of the source system)." > ([source-mssql] sync fails with CDC and no changes) So, forcing a change in a dummy table and syncing it with CDC will keep the commit_lsn advancing and prevent the "Saved offset no longer present on the server" error, even if your main tables are inactive.