{"record":{"id":"c9df329810b3026a","repo":"apache/seatunnel","slug":"invalid-lsn-returned-from-database","errorCode":null,"errorMessage":"Invalid LSN returned from database","messagePattern":"Invalid LSN returned from database","errorType":"exception","errorClass":"ConnectException","httpStatus":null,"severity":"error","filePath":"seatunnel-connectors-v2/connector-cdc/connector-cdc-opengauss/src/main/java/io/debezium/connector/postgresql/connection/PostgresConnection.java","lineNumber":433,"sourceCode":"        if (lsnStr == null) {\n            return null;\n        }\n        try {\n            lsn = Lsn.valueOf(lsnStr);\n        } catch (Exception e) {\n            throw new ConnectException(\n                    \"Value \"\n                            + column\n                            + \" in the pg_replication_slots table for slot = '\"\n                            + slotName\n                            + \"', plugin = '\"\n                            + pluginName\n                            + \"', database = '\"\n                            + database\n                            + \"' is not valid. This is an abnormal situation and the database status should be checked.\");\n        }\n        if (!lsn.isValid()) {\n            throw new ConnectException(\"Invalid LSN returned from database\");\n        }\n        return lsn;\n    }\n\n    /**\n     * Drops a replication slot that was created on the DB\n     *\n     * @param slotName the name of the replication slot, may not be null\n     * @return {@code true} if the slot was dropped, {@code false} otherwise\n     */\n    public boolean dropReplicationSlot(String slotName) {\n        final int ATTEMPTS = 3;\n        for (int i = 0; i < ATTEMPTS; i++) {\n            try {\n                execute(\"select pg_drop_replication_slot('\" + slotName + \"')\");\n                return true;\n            } catch (SQLException e) {\n                // slot is active","sourceCodeStart":415,"sourceCodeEnd":451,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-connectors-v2/connector-cdc/connector-cdc-opengauss/src/main/java/io/debezium/connector/postgresql/connection/PostgresConnection.java#L415-L451","documentation":"After successfully parsing the LSN in tryParseLsn, the code calls lsn.isValid(); if the parsed LSN is not valid it throws this ConnectException. This guards against LSN objects that parse syntactically but represent impossible positions (e.g. Lsn.INVALID), preventing the connector from starting from a bogus WAL offset.","triggerScenarios":"The value in the given pg_replication_slots column parses via Lsn.valueOf but returns false from isValid() — typically the sentinel invalid LSN value or a numerically impossible position returned by the server.","commonSituations":"A freshly created slot whose LSN fields report an uninitialized/invalid sentinel on some server builds; a database fork (OpenGauss) returning non-standard sentinel values; catalog corruption after an unclean shutdown.","solutions":["Query the slot LSNs directly and compare against pg_current_wal_lsn() to see if the value is a plausible position.","Drop and recreate the replication slot so the server initializes confirmed_flush_lsn/restart_lsn to real WAL positions.","Let the server advance the slot: run a short transaction with the connector's plugin so WAL positions are established, then restart the connector.","Check database health/logs for corruption after unclean shutdowns and restart the instance if needed."],"exampleFix":"-- before: slot reports an invalid sentinel LSN\nSELECT pg_drop_replication_slot('seatunnel_slot');\n-- after: recreate and prime the slot\nSELECT pg_create_logical_replication_slot('seatunnel_slot', 'pgoutput');\nBEGIN; INSERT INTO t VALUES (1); COMMIT; -- advance WAL, then start connector","handlingStrategy":"validation","validationCode":"SELECT restart_lsn, confirmed_flush_lsn, pg_current_wal_lsn() FROM pg_replication_slots WHERE slot_name = 'slot'; -- slot LSNs must be plausible relative to pg_current_wal_lsn()","typeGuard":null,"tryCatchPattern":"try {\n    connection.getReplicationSlotState(slotName, pluginName);\n} catch (ConnectException e) {\n    pgDropSlot(slotName); pgCreateSlot(slotName, pluginName);\n}","preventionTips":["Prime a fresh slot with a small transaction so LSNs become valid.","Verify database integrity after unclean shutdowns.","Keep server and connector versions aligned."],"tags":["cdc","postgres","lsn","replication-slot"],"backgroundTag":"invalid-argument-value","analyzedSha":"cf67b549a7a6c35fa0beb12d83c62892427ea919","analyzedAt":"2026-09-10T21:44:55.265Z","contentChangedAt":"2026-09-10T21:44:55.265Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}