Hello, using an SQLServer source, I'm often gettin...
# ask-ai
j
Hello, using an SQLServer source, I'm often getting the "Saved offset no longer present on the server". While I understand that the issue comes from a badly set binlog retention on the SQLServer, the solution of clearing the data works and is enough until we have sorted that out. However I need to do it manually on all the streams I have setup, which is not convenient. Is there some way to setup the source to automatically clear the data and restart from scratch when such an issue occurs ?
k
Airbyte does not currently provide a built-in setting to automatically clear data and restart from scratch when the "Saved offset no longer present on the server" error occurs for SQL Server sources. The standard behavior, when this error is encountered and the "Invalid CDC position behavior" is set to "Fail Sync," is for the sync to fail and require manual intervention—either by clearing the data (reset/clear) or by adjusting the retention settings on your SQL Server to prevent the issue in the first place. This is by design, to make the problem visible and avoid unintended data loss or silent full refreshes without operator awareness. You can clear data for all streams or individual streams manually via the Airbyte UI or API, but there is no documented way to automate this process in response to the CDC offset error. The clear operation is intentionally a manual safeguard, as clearing data is destructive and can lead to data loss if the source does not retain all historical records. Airbyte recommends resolving the underlying retention issue to avoid frequent manual clears. For more details on the clear/reset process, see the official documentation: [Clearing your data](https://docs.airbyte.com/platform/operator-guides/clear). If you need to clear multiple streams, you can do so via the API, but this still requires an explicit action and is not triggered automatically by the connector in response to CDC errors. There is no configuration option to make Airbyte automatically clear and re-sync upon this specific error for SQL Server sources at this time. If this is a critical feature for your workflow, you may consider submitting a feature request to the Airbyte team or following related issues for updates on this capability. References: - [Clearing your data](https://docs.airbyte.com/platform/operator-guides/clear) - [source-mssql] Airbyte triggering full refresh after retention period is over when using SQLServer CDC for ingestion ([GitHub Issue](https://github.com/airbytehq/airbyte/issues/42435))
j
But what exactly could be the root cause here? My streams refresh correctly every 15 minutes or so, until they stop with this particular error. @kapa.ai
k
A message from kapa.ai
The root cause of the "Saved offset no longer present on the server" error in Airbyte's SQL Server CDC integration is that the commit LSN (Log Sequence Number) Airbyte is tracking for incremental syncs has been cleaned up (removed) from the SQL Server's CDC change tables due to the configured retention period. This typically happens when: - The retention period for CDC data on SQL Server is too short relative to your sync frequency or the volume of changes. Even if you sync every 15 minutes, if there are periods of low or no changes in the source tables, the commit_lsn may not be updated, and the tracked offset can "fall behind" the minimum LSN retained by SQL Server. Once the cleanup job runs and removes older LSNs, Airbyte's saved offset is no longer valid, causing the error. - If there are tables with very infrequent changes, the offset for those tables may not advance, even though the max LSN in the system keeps moving forward due to other activity or dummy entries. This can cause the offset for those tables to fall outside the retention window, triggering the error when Airbyte tries to resume from an LSN that no longer exists in the CDC tables. This behavior is confirmed in several user reports and discussions: - "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, [GitHub Issue](https://github.com/airbytehq/airbyte/issues/37772)) - "Looking at the events building up to this error, the lsn which the log reports missing from server ... is the lsn from the initial snapshot taken 10 days ago." ([source-mssql] Airbyte triggering full refresh after retention period is over, [GitHub Issue](https://github.com/airbytehq/airbyte/issues/42435)) In summary: Even with frequent syncs, if some tables rarely change, their offsets may not advance, and the corresponding LSNs can be purged by SQL Server's CDC cleanup job. When Airbyte tries to resume from these old LSNs, it fails with the "Saved offset no longer present on the server" error. Recommended solution: Increase the CDC retention period on your SQL Server to ensure that LSNs are retained long enough for all streams, including those with infrequent changes, to be picked up by Airbyte. You can do this using the
sp_cdc_change_job
stored procedure as described in the [Airbyte documentation](https://docs.airbyte.com/integrations/sources/mssql#4-extend-the-retention-period-of-cdc-data):
Copy code
sql -- Example: Set retention to 10 days (14400 minutes) 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';
This should help prevent the error by ensuring the required LSNs are available when Airbyte attempts to sync, even for tables with infrequent changes. For more details, see the [Airbyte MSSQL CDC setup guide](https://docs.airbyte.com/integrations/sources/mssql#4-extend-the-retention-period-of-cdc-data).
j
The solution was apparently to mark the source as "invalid CDC position behaviour" -> "re-sync data" instead of "fail sync" which is the default @kapa.ai
k
Sorry @Jean-Denis COSTA, it looks like your question contains files, which I cannot process. Please reformulate your question without including any files.
j
The solution was apparently to mark the source as "invalid CDC position behaviour" -> "re-sync data" instead of "fail sync" which is the default @kapa.ai
k
A message from kapa.ai
Yes, setting the "Invalid CDC position behavior" to "Re-sync data" instead of the default "Fail sync" is a documented workaround for this issue. When "Re-sync data" is selected, Airbyte will automatically trigger a full refresh (i.e., clear and re-sync the data) if it encounters a situation where the saved CDC offset is no longer present on the server, rather than failing the sync and requiring manual intervention. This behavior is confirmed in user reports and issue discussions. For example, one user noted: > Changing the Invalid CDC position behavior from Fail Sync to Re-sync Data. This should make the pipeline in a constant retrial state for taking a snapshot instead of constant failure. Maybe in one of those retries some changes are committed to the tables in the publication. (Tradeoff: Each retry of the snapshot would incur additional costs and infrastructure load.) [GitHub Issue #49803](https://github.com/airbytehq/airbyte/issues/49803) Similarly, the error messages and logs show that with "Re-sync data," Airbyte will clear and re-sync the data automatically when the offset is invalid, whereas with "Fail sync," it will stop and require manual action: > In case Invalid CDC position behavior (Advanced) Property is
Fail sync
, Output Log is: >
Copy code
> Saved offset is before replication slot's confirmed lsn. Please reset the connection, and then increase WAL retention and/or increase sync frequency to prevent this from happening in the future. >
> In case Invalid CDC position behavior (Advanced) Property is
Re-sync data
, Output Log is: >
Copy code
> Saved offset is before Replication slot's confirmed_flush_lsn, Airbyte will trigger sync from scratch >
[GitHub Issue #49802](https://github.com/airbytehq/airbyte/issues/49802) So, if you want Airbyte to automatically clear and re-sync data when this CDC offset issue occurs, setting "Invalid CDC position behavior" to "Re-sync data" is the correct approach. Just be aware that this will result in a full refresh of your data, which may have performance and cost implications, especially for large datasets.