{"record":{"id":"ce0a710b60b250c6","repo":"apache/seatunnel","slug":"cannot-drop-replication-slot-because-it-s-sti","errorCode":null,"errorMessage":"Cannot drop replication slot '{}' because it's still in use","messagePattern":"Cannot drop replication slot '(.+?)' because it's still in use","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"seatunnel-connectors-v2/connector-cdc/connector-cdc-opengauss/src/main/java/io/debezium/connector/postgresql/connection/PostgresConnection.java","lineNumber":458,"sourceCode":"     *\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\n                if (PSQLState.OBJECT_IN_USE.getState().equals(e.getSQLState())) {\n                    if (i < ATTEMPTS - 1) {\n                        LOGGER.debug(\n                                \"Cannot drop replication slot '{}' because it's still in use\",\n                                slotName);\n                    } else {\n                        LOGGER.warn(\n                                \"Cannot drop replication slot '{}' because it's still in use\",\n                                slotName);\n                        return false;\n                    }\n                } else if (PSQLState.UNDEFINED_OBJECT.getState().equals(e.getSQLState())) {\n                    LOGGER.debug(\"Replication slot {} has already been dropped\", slotName);\n                    return false;\n                } else {\n                    LOGGER.error(\"Unexpected error while attempting to drop replication slot\", e);\n                    return false;\n                }\n            }\n            try {\n                Metronome.parker(Duration.ofSeconds(1), Clock.system()).pause();\n            } catch (InterruptedException e) {\n            }\n        }\n        return false;","sourceCodeStart":440,"sourceCodeEnd":476,"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#L440-L476","documentation":"dropReplicationSlot tried to drop a replication slot via pg_drop_replication_slot but the PostgreSQL backend reports SQLSTATE 55006 (OBJECT_IN_USE) because a session is still streaming from the slot. It retries ATTEMPTS times, then warns and returns false (slot not dropped).","triggerScenarios":"Calling connection.dropReplicationSlot(slotName) while another connection/thread holds an active replication stream on that slot; the last retry hits OBJECT_IN_USE again and returns false.","commonSituations":"Connector restart while the old task still streams; a orphaned walreceiver backend keeping the slot active; tests shutting down a connection while the replicator thread is alive; killing a job whose streaming connection hasn't been released server-side yet.","solutions":["Find and terminate the backend holding the slot: SELECT pg_terminate_backend(active_pid) FROM pg_replication_slots WHERE slot_name='<slot>'; then retry the drop.","Close all other replication connections using the slot before dropping it.","Wait for the streaming session to end (slot active=false in pg_replication_slots) and retry.","If the slot must go regardless, run SELECT pg_drop_replication_slot('<slot>'); manually after terminating the holder."],"exampleFix":"// before\ndropReplicationSlot(\"dbz\"); // returns false, slot in use\n// after\n// stmt.execute(\"SELECT pg_terminate_backend(active_pid) FROM pg_replication_slots WHERE slot_name='dbz' AND active\");\n// then dropReplicationSlot(\"dbz\");","handlingStrategy":"try-catch","validationCode":"SELECT active, active_pid FROM pg_replication_slots WHERE slot_name='<slot>'; -- only drop when active=false","typeGuard":null,"tryCatchPattern":"try { boolean dropped = conn.dropReplicationSlot(slot); if (!dropped) { terminateHolderPid(slot); retryDrop(slot); } } catch (SQLException e) { /* handle */ }","preventionTips":["Check slot active=false before dropping.","Terminate streaming backends via pg_terminate_backend first.","Close connector tasks gracefully before cleanup."],"tags":["cdc","postgresql","replication-slot","connection-in-use"],"backgroundTag":"resource-not-found","analyzedSha":"cf67b549a7a6c35fa0beb12d83c62892427ea919","analyzedAt":"2026-09-10T21:44:55.265Z","contentChangedAt":"2026-09-10T21:44:55.265Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}