<@U04S8PLJWMT> Hello, I'm encountering an issue ...
# ask-ai
c
@kapa.ai Hello, I'm encountering an issue with our PostgreSQL WAL (Write-Ahead Log) configuration during a CDC (Change Data Capture) sync process between a PostgreSQL source and destination, using Airbyte for replication. Even though our database experiences low usage and infrequent changes, we use CDC to ensure we can efficiently replicate all changes, including edits and deletions. The exact error message is: "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 Airbyte Documentation for more details." Interestingly, the first five syncs with five-minute intervals worked without any issues. Here is a snippet of our PostgreSQL configuration focusing on WAL:
Copy code
wal_level = logical
wal_keep_size = 1GB
max_wal_senders = 1
max_replication_slots = 1
wal_sync_method = fsync
synchronous_commit = on
min_wal_size = 80MB
max_wal_size = 1GB
Let me know if you need more details or have any questions.
k
The error message you're encountering—**"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."**—is a known issue when using Airbyte's CDC mode with PostgreSQL, especially in databases with low transaction volumes. ### Why This Happens - WAL (Write-Ahead Log) Retention: PostgreSQL may remove WAL segments that Airbyte needs for incremental syncs if they are not retained long enough. This is more likely in low-traffic databases, where the WAL does not advance frequently, and the replication slot's
confirmed_flush_lsn
can move ahead of the last saved offset. - Low Transaction Volume: If there are few or no changes in the tables being tracked, the WAL may not advance as expected, and PostgreSQL may clean up WAL segments that Airbyte still needs for CDC, causing the offset mismatch and triggering a full resync or failure. ### Your Configuration Your current WAL-related settings are:
Copy code
plaintext wal_level = logical wal_keep_size = 1GB max_wal_senders = 1 max_replication_slots = 1 wal_sync_method = fsync synchronous_commit = on min_wal_size = 80MB max_wal_size = 1GB
-
wal_keep_size = 1GB
is reasonable, but in low-traffic environments, the issue is not just about size, but also about the frequency of WAL advancement. -
max_replication_slots = 1
and
max_wal_senders = 1
are minimal; if you have more than one replication client, you may need to increase these. ### Solutions #### 1. Increase WAL Retention - You can try increasing
wal_keep_size
further, but this only helps if the WAL is filling up. In low-traffic environments, this may not be sufficient. #### 2. Increase Sync Frequency - Run Airbyte syncs more frequently to ensure the WAL segments needed for CDC are not removed before Airbyte can read them. However, you mentioned that even with five-minute intervals, the issue eventually appeared. #### 3. Heartbeat Table (Recommended for Low-Traffic Databases) - Create a heartbeat table and add it to your publication. Airbyte (via Debezium) can be configured to periodically write to this table, ensuring the WAL advances even when there are no changes in your main tables. - Steps: 1. Create the table:
Copy code
sql      CREATE TABLE airbyte_heartbeat (        id SERIAL PRIMARY KEY,        timestamp TIMESTAMP NOT NULL DEFAULT current_timestamp,        text TEXT      );
2. Add it to your publication:
Copy code
sql      ALTER PUBLICATION <publicationName> ADD TABLE airbyte_heartbeat;
3. In Airbyte, set the Debezium heartbeat query to:
Copy code
sql      INSERT INTO airbyte_heartbeat (text) VALUES ('heartbeat');
This will keep the WAL advancing and prevent the offset mismatch error, as described in the [Airbyte documentation](https://docs.airbyte.com/integrations/sources/postgres/postgres-troubleshooting#advanced-wal-disk-consumption-and-heartbeat-action-query). #### 4. Check for Known Connector Issues - There are known issues with certain versions of the Airbyte Postgres source connector and the underlying PgJDBC driver, which can cause similar problems even if your WAL settings are correct. If you are using a connector version >= 3.6.19, you may be affected by a bug where the confirmed_flush_lsn advances unexpectedly. Downgrading to version 3.6.18 or earlier may help as a temporary workaround. See [this issue](https://github.com/airbytehq/airbyte/issues/49802) for more details. ### Summary - Add a heartbeat table and configure Airbyte to use it. - Consider increasing
wal_keep_size
further if disk space allows.
- Ensure your Airbyte and connector versions are not affected by known bugs. - Increase sync frequency if possible, but the heartbeat table is the most robust solution for low-traffic databases. For more details and step-by-step instructions, refer to the [Airbyte Postgres troubleshooting guide](https://docs.airbyte.com/integrations/sources/postgres/postgres-troubleshooting#advanced-wal-disk-consumption-and-heartbeat-action-query). If you need further help, please provide your Airbyte and connector versions, and confirm if you are using a heartbeat table or not.
c
@kapa.ai to make it easier and streamilned, can i put this script directly in the Debezium heartbeat query ? :
Copy code
-- Étape 1: Créer la table airbyte_heartbeat si elle n'existe pas déjà
DO $$
BEGIN
    IF NOT EXISTS (
        SELECT 1
        FROM information_schema.tables
        WHERE table_schema = current_schema()
        AND table_name = 'airbyte_heartbeat'
    ) THEN
        CREATE TABLE airbyte_heartbeat (
            id SERIAL PRIMARY KEY,
            timestamp TIMESTAMP NOT NULL DEFAULT current_timestamp,
            text TEXT
        );
    END IF;
END $$;


-- Étape : Insérer une entrée dans la table airbyte_heartbeat pour initialiser le heartbeat
INSERT INTO airbyte_heartbeat (text) VALUES ('heartbeat')
k
A message from kapa.ai
No, you cannot put the entire script—including the table creation logic—directly into the Debezium heartbeat query field in Airbyte. The Debezium heartbeat query is intended for simple DML statements, such as an
INSERT
or
UPDATE
, not for DDL or procedural code like
DO $$ ... $$
blocks or
CREATE TABLE
statements.
The documentation and user reports indicate that the heartbeat query should be a straightforward statement that writes to an existing table, for example:
Copy code
sql INSERT INTO airbyte_heartbeat (text) VALUES ('heartbeat');
or
Copy code
sql UPDATE yourSchema.yourTable SET value='heartbeat', updated=now();
You must create the
airbyte_heartbeat
table manually in your database before configuring the heartbeat query in Airbyte. The heartbeat query will then periodically write to this table to keep the WAL advancing and prevent CDC issues in low-traffic environments. This process is described in the [Airbyte documentation](https://docs.airbyte.com/integrations/sources/postgres/postgres-troubleshooting#advanced-wal-disk-consumption-and-heartbeat-action-query) and confirmed by user experiences in the community and GitHub issues. Summary: - The heartbeat query field does not support DDL or procedural code. - Create the table manually first, then use a simple DML statement as the heartbeat query. For more details, see the official [Airbyte Postgres troubleshooting guide](https://docs.airbyte.com/integrations/sources/postgres/postgres-troubleshooting#advanced-wal-disk-consumption-and-heartbeat-action-query) and related user discussions in the knowledge sources.
c
ok, @kapa.ai in the doc it says to put :
Copy code
INSERT INTO airbyte_heartbeat (text) VALUES ('heartbeat')
should I add ; at the end like so ? :
Copy code
INSERT INTO airbyte_heartbeat (text) VALUES ('heartbeat');
k
A message from kapa.ai
You do not need to add a semicolon (
;
) at the end of the query in the Debezium heartbeat query field. The documentation and examples provided by Airbyte show the query without a semicolon:
Copy code
INSERT INTO airbyte_heartbeat (text) VALUES ('heartbeat')
This is the recommended format to use in the Airbyte UI for the Debezium heartbeat query property. Adding a semicolon is not necessary and could potentially cause issues, as the field expects a single SQL statement without statement terminators. Reference: [Airbyte Postgres troubleshooting guide](https://docs.airbyte.com/integrations/sources/postgres/postgres-troubleshooting#advanced-wal-disk-consumption-and-heartbeat-action-query)