<@U04S8PLJWMT> Hey Kapa! When is airbyte flushing ...
# ask-ai
p
@kapa.ai Hey Kapa! When is airbyte flushing the LSN to postgres when using a CDC sync to BigQuery? Even with an heartbeat configured, it seems that the committed LSN does not remove a lot of segments from the WAL files on RDS.
k
When using Airbyte's CDC sync from Postgres to BigQuery, the LSN (Log Sequence Number) is not flushed (i.e., acknowledged to Postgres) immediately at the end of a sync. Instead, Airbyte saves the updated offset (LSN) in its state at the end of a sync, but only acknowledges (flushes) it to Postgres at the start of the next sync. This design ensures that data is only acknowledged as processed in Postgres after it has been successfully written to the destination (BigQuery), providing data consistency and reliability. This means that WAL segments corresponding to the most recently synced data will only be released after the next sync cycle starts and the previous state is acknowledged. As a result, you may observe that WAL files are not immediately removed after a sync, even if a heartbeat is configured and working. This is expected behavior and is due to the way Airbyte coordinates state between the source and destination to guarantee data delivery: > "One point I want to stress is that when a sync ends we save an updated offset in an airbyte state, but only on the next sync will we acknowledge that to the DB. This has to do with the way sources and destinations communicate over the airbyte protocol, and is meant to ensure that we only acknowledge to postgres after destination has confirmed the data reached its final destination successfully. That means in your case that log records that we read and uploaded to your warehouse will only be released on postgres on the following day." [Source](https://github.com/airbytehq/airbyte/issues/42917) If you are still seeing excessive WAL retention even after several sync cycles and with a heartbeat configured, it may be due to other issues such as the replication slot becoming inactive, or the connector not consuming WAL fast enough. In low-traffic databases, you may also need to ensure that the heartbeat table is included in the publication and that the heartbeat query is configured in Airbyte, as described in the documentation. However, the delayed WAL cleanup after each sync is expected due to the state management approach described above [Advanced WAL disk consumption and heartbeat action query](https://docs.airbyte.com/integrations/sources/postgres/postgres-troubleshooting#advanced-wal-disk-consumption-and-heartbeat-action-query).