Hi <@U04S8PLJWMT> is there any way to avoid this e...
# ask-ai
a
Hi @kapa.ai is there any way to avoid this error from happening: "Failure in source: 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. See https://docs.airbyte.com/integrations/sources/postgres/postgres-troubleshooting#under-cdc-incremental-mode-there-are-still-full-refresh-syncs for more details."
k
To avoid the error “Failure in source: 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,” you should address the underlying cause: the required WAL (Write-Ahead Log) segments for CDC have been removed by Postgres before Airbyte could read them. Here are the recommended steps to prevent this error: 1. Increase WAL Retention Set a higher value for
wal_keep_size
(and/or
max_slot_wal_keep_size
) in your Postgres configuration. This ensures that WAL files are retained longer, reducing the chance that Airbyte will miss required logs. For example:
Copy code
sql    ALTER SYSTEM SET wal_keep_size = '10GB';    ALTER SYSTEM SET max_slot_wal_keep_size = '10GB';
Remember, increasing these values will require more disk space on your Postgres server. 2. Increase Sync Frequency Run Airbyte syncs more frequently. The less time between syncs, the less likely it is that WAL files will be purged before Airbyte can read them. 3. Monitor WAL Disk Consumption If your database has low transaction volume, WAL segments may not advance as expected, which can also cause issues. You can add a high-transaction table to the publication or use a heartbeat table and configure the Debezium heartbeat query in Airbyte to ensure the LSN advances regularly. See the [advanced troubleshooting guide](https://docs.airbyte.com/integrations/sources/postgres/postgres-troubleshooting#advanced-wal-disk-consumption-and-heartbeat-action-query) for details. 4. Reset the Connection if Needed If you encounter this error, you may need to reset the Airbyte connection and perform a full refresh to recover. This is sometimes unavoidable if the WAL data is already lost. Summary: - Increase
wal_keep_size
and/or
max_slot_wal_keep_size
- Sync more frequently - Use a heartbeat table if transaction volume is low - Reset the connection if the error occurs For more details, see the official Airbyte documentation: [Troubleshooting Postgres Sources](https://docs.airbyte.com/integrations/sources/postgres/postgres-troubleshooting#under-cdc-incremental-mode-there-are-still-full-refresh-syncs)
a
so @kapa.ai I have wal_keep_size=2048
k
A message from kapa.ai
If you have
wal_keep_size=2048
(which means 2GB), this setting controls how much WAL data Postgres will retain for replication slots. Whether this is sufficient depends on your database's write volume and how frequently Airbyte runs syncs. Key points from the knowledge sources: - If your sync frequency is low or your database has high write activity, 2GB may not be enough, and WAL segments needed for CDC could be purged before Airbyte reads them, causing the "Saved offset is before replication slot's confirmed lsn" error. - The Airbyte documentation recommends increasing
wal_keep_size
if you encounter this error, especially if you cannot increase sync frequency. There is no universal "safe" value; it depends on your data change rate and sync schedule. You may need to experiment with higher values if you still see the error with 2GB set. - For low-transaction databases, WAL segments may not advance as expected, which can also cause issues. In such cases, using a heartbeat table or adding a high-transaction table to the publication can help advance the LSN and avoid WAL retention issues. See the [advanced troubleshooting guide](https://docs.airbyte.com/integrations/sources/postgres/postgres-troubleshooting#advanced-wal-disk-consumption-and-heartbeat-action-query) for details. - If you continue to see the error, you may need to increase
wal_keep_size
further or sync more frequently to ensure WAL files are not purged before Airbyte can process them. The documentation also notes that more disk space will be needed as you increase this value, so monitor your disk usage accordingly. Summary: With
wal_keep_size=2048
, you may still encounter the error if your syncs are not frequent enough or your database write volume is high. If the error persists, try increasing
wal_keep_size
further and/or increase your sync frequency. For low-transaction environments, consider implementing a heartbeat table as described in the documentation to ensure the WAL advances and is retained as needed [source](https://docs.airbyte.com/integrations/sources/postgres/postgres-troubleshooting#under-cdc-incremental-mode-there-are-still-full-refresh-syncs).
a
@kapa.ai it's a high write database, with this 0 0/30 * * * ? schedule
k
A message from kapa.ai
Given your database has a high write volume and your Airbyte sync schedule is every 30 minutes (
0 0/30 * * * ?
), a
wal_keep_size=2048
(2GB) may not be sufficient to guarantee WAL retention between syncs. Why? With high write activity, WAL files can grow and be purged quickly. If the amount of WAL generated in 30 minutes exceeds 2GB, Postgres will remove older WAL segments, and Airbyte may miss the required logs for CDC, resulting in the "Saved offset is before replication slot's confirmed lsn" error. This scenario is explicitly described in the Airbyte documentation: > When there are lots of database updates resulting in more WAL files than allowed in the
pg_wal
directory, Postgres will purge or archive the WAL files. This scenario is preventable. Possible solutions include: > - Sync the data source more frequently. > - Set a higher
wal_keep_size
. ... The downside of this approach is that more disk space will be needed. > [Troubleshooting Postgres Sources](https://docs.airbyte.com/integrations/sources/postgres/postgres-troubleshooting#under-cdc-incremental-mode-there-are-still-full-refresh-syncs) What should you do? - Increase
wal_keep_size
: Set it higher than 2GB, especially if you notice the error persists. The exact value depends on your database's write rate—monitor your WAL growth over a typical 30-minute period and set
wal_keep_size
accordingly. - (Optional) Increase sync frequency: If possible, run syncs more often to reduce the window in which WAL can be purged. - Monitor disk usage: As you increase
wal_keep_size
, ensure your disk has enough space to accommodate the larger WAL retention. Summary: For a high-write database with 30-minute syncs, 2GB WAL retention is often not enough. Increase
wal_keep_size
to match your WAL generation rate between syncs to avoid this error. If you continue to see the error, keep increasing the value or sync more frequently as needed. [Source: Airbyte Postgres Troubleshooting](https://docs.airbyte.com/integrations/sources/postgres/postgres-troubleshooting#under-cdc-incremental-mode-there-are-still-full-refresh-syncs)
a
@kapa.ai setting wal_keep_size to 4096, would do something?
k
A message from kapa.ai
Yes, setting
wal_keep_size
to 4096 (4GB)
would increase the amount of WAL (Write-Ahead Log) data that PostgreSQL retains before purging. This means PostgreSQL will keep up to 4GB of WAL files, which can help prevent the "Saved offset is before replication slot's confirmed lsn" error if your database generates a lot of WAL data between Airbyte syncs. The Airbyte documentation specifically recommends increasing
wal_keep_size
if you encounter this error, especially in high-write environments or when syncs are not very frequent. The downside is that this will require more disk space, but it directly addresses the issue of WAL files being purged before Airbyte can read them for CDC ([source](https://docs.airbyte.com/integrations/sources/postgres/postgres-troubleshooting#under-cdc-incremental-mode-there-are-still-full-refresh-syncs)). If you still encounter the error after increasing to 4GB, you may need to monitor your WAL generation and consider increasing it further or syncing more frequently.
a
ok @kapa.ai main problem is with the first sync (initial sync)
k
A message from kapa.ai
The main problem with the first sync (initial sync) in Airbyte's Postgres CDC mode is a known issue: Airbyte may commit or save an incorrect LSN (Log Sequence Number) during the initial snapshot. This can result in the saved offset being behind the replication slot's confirmed_flush_lsn on subsequent syncs, causing the error: > "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." This issue is documented in several GitHub issues and is not always resolved by simply increasing
wal_keep_size
or sync frequency. The root cause is that, during the initial snapshot, Airbyte sometimes saves an LSN that is not aligned with the actual state of the replication slot, especially if there are no incremental changes detected after the snapshot. This leads to a broken state for the next sync, which then fails or triggers a full refresh, depending on your CDC error handling settings. This behavior is described in detail here: [Airbyte Commits the Wrong LSN When Taking the Initial Snapshot](https://github.com/airbytehq/airbyte/issues/49803) [CDC sync is making the confirmed flush LSN to a value > saved state LSN](https://github.com/airbytehq/airbyte/issues/55846) Workarounds suggested in the knowledge sources: - Add high-traffic tables to your publication or use a heartbeat table to ensure there are changes in the WAL after the initial snapshot. This can help Airbyte update the saved offset correctly after the snapshot, but it is not a guaranteed fix for all environments. - Set the "Invalid CDC position behavior" to "Re-sync Data" to allow Airbyte to recover by doing a full refresh, though this is not ideal for large datasets. - There is currently no definitive fix in Airbyte for this initial sync LSN issue; it is a known bug being tracked by the Airbyte team. Summary: The initial sync problem is a known bug in Airbyte's Postgres CDC implementation, especially when there are no changes in the publication tables after the snapshot. Workarounds exist, but a permanent fix is still pending from the Airbyte team. [Source: GitHub Issue 49803](https://github.com/airbytehq/airbyte/issues/49803) [Source: GitHub Issue 55846](https://github.com/airbytehq/airbyte/issues/55846)