Hi Airbyte team, We are running airbyte OSS usin...
# replication-troubleshooting
m
Hi Airbyte team, We are running airbyte OSS using helm chart 1.9.1 in K8s environment . I am syncing Cloudsql postgres data into GCS using airbyte. I am getting below 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. See https://docs.airbyte.com/integrations/sources/postgres/postgres-troubleshooting#under-cdc-incremental-mode-there-are-still-full-refresh-syncs for more details. Solutions show to have wal_keep_size , but cloudsql doesn't provide this database flag. Any help on this would be appreciated. Please. Thanks in advance.
k
I'm sorry, but the provided knowledge sources do not explicitly mention a direct alternative to the
wal_keep_size
flag specifically for Cloud SQL for PostgreSQL. However, the documentation and community discussions suggest several strategies to resolve this "Saved offset is before replication slot's confirmed LSN" error when you cannot modify that specific flag. ### Understanding the Error This error occurs when the Write-Ahead Logs (WAL) required for an incremental sync have been removed by Postgres before Airbyte could process them [[Troubleshooting Postgres Sources](https://docs.airbyte.com/integrations/sources/postgres/postgres-troubleshooting#troubleshooting)]. This is common in environments with low transaction volumes where the
confirmed_flush_lsn
does not advance, or in high-volume environments where logs are purged too quickly [[Resolving sync failures](https://docs.airbyte.com/integrations/sources/postgres/postgres-troubleshooting#advanced-wal-disk-consumption-and-heartbeat-action-query)]. ### Recommended Solutions #### 1. Implement a Heartbeat Table (Recommended for Cloud SQL) If your database has low traffic, the replication slot might not advance, leading to WAL retention issues. You can manually force the LSN to advance by creating a heartbeat table that Airbyte writes to periodically: 1. Create a heartbeat table in your Postgres database:
Copy code
sql     CREATE TABLE airbyte_heartbeat (         id SERIAL PRIMARY KEY,         timestamp TIMESTAMP NOT NULL DEFAULT current_timestamp,         text TEXT     );
2. Add the table to your publication:
Copy code
sql     ALTER PUBLICATION <your_publication_name> ADD TABLE airbyte_heartbeat;
3. Configure the Heartbeat Query in the Airbyte Source settings under the "Debezium heartbeat query" property:
Copy code
sql     INSERT INTO airbyte_heartbeat (text) VALUES ('heartbeat')
Airbyte will execute this query periodically to ensure the WAL advances [[Resolving sync failures](https://docs.airbyte.com/integrations/sources/postgres/postgres-troubleshooting#advanced-wal-disk-consumption-and-heartbeat-action-query)]. #### 2. Use
pg_cron
for Automated Heartbeats For a more automated approach in Cloud SQL, you can use the
pg_cron
extension to insert values into a heartbeat table every minute. This ensures the replication slot is cleared even when there are no changes in your primary data tables [[Troubleshooting Postgres Sources](https://docs.airbyte.com/integrations/sources/postgres/postgres-troubleshooting#wal-heartbeat-table)]. * Enable the
cloudsql.enable_pg_cron
flag in your Cloud SQL instance settings. * Add
pg_cron
to
shared_preload_libraries
[[Troubleshooting Postgres Sources](https://docs.airbyte.com/integrations/sources/postgres/postgres-troubleshooting#add-the-pg_cron-extension)]. #### 3. Increase Sync Frequency If the WAL is being purged because too much time passes between syncs, increasing the frequency of your Airbyte connection (e.g., from every 24 hours to every 1 hour) can prevent the logs from being recycled before the next sync starts [[Troubleshooting Postgres Sources](https://docs.airbyte.com/integrations/sources/postgres/postgres-troubleshooting#troubleshooting)]. #### 4. Adjust Invalid CDC Position Behavior In your Airbyte connection settings, you can change the Invalid CDC position behavior from
Fail sync
to
Re-sync data
. While this will trigger a full refresh when the LSN is lost (which may be expensive for large tables), it prevents the connection from staying in a failed state [[Github Issue (open)](https://github.com/airbytehq/airbyte/issues/55846); [CDC Not Working](https://github.com/airbytehq/airbyte/issues/49802)].