Database Diff incremental sync blocking application during migration
0 reputation · 25 Jun 2022, 08:17 UTC
0 reputation · 25 Jun 2022, 08:17 UTC
When migrating a small Oracle application, the goal is to apply schema changes without taking the application offline. Oracle SQL Developer’s Database Diff tool can compare two schemas and produce DDL scripts, but it currently lacks an incremental diff mode that would identify only new or modified objects since the last sync.
Because the generated scripts are executed manually, any DDL that requires exclusive locks will block concurrent application sessions, potentially causing downtime or transaction failures. Additionally, SQL Developer does not offer a transactional or lock‑free mechanism for applying DDL in a live environment.
Is it possible to perform incremental schema synchronization with Database Diff while keeping the application online, and if so, how can the generated DDL be applied without locking critical objects?
34775 reputation · 25 Jun 2022, 14:34 UTC
Oracle SQL Developer’s Database Diff cannot be toggled to produce a truly lock‑free incremental DDL script. It always emits standard DDL that, when executed, will acquire an Access Exclusive lock on the target objects. However, you can mitigate the impact on a live application by applying the generated DDL in a staged, online‑friendly manner.
ALTER TABLE, DROP COLUMN, or CREATE INDEX requires an exclusive lock on the table or index object.DBMS_REDEFINITION session:
DECLARE
l_redef_handle NUMBER;
BEGIN
DBMS_REDEFINITION.START_REDEF('SCHEMA', 'TABLE_NAME', l_redef_handle);
DBMS_REDEFINITION.ALTER_TABLE(l_redef_handle, 'ALTER TABLE TABLE_NAME ADD (new_col NUMBER)');
DBMS_REDEFINITION.FINISH_REDEF(l_redef_handle);
END;
This technique keeps the original table available for DML while the new structure is built in the background.
ONLINE keyword (Enterprise Edition only):
CREATE INDEX idx_name ON table_name(col1) ONLINE;
V$SESSION and V$LOCKED_OBJECT.
ALTER SESSION SET DDL_LOCK_TIMEOUT = 60;SELECT * FROM v$session WHERE blocking_session IS NOT NULL; to spot blocking sessions and decide whether to wait or kill them.To refine the recommendation, please confirm whether the target database is Oracle Enterprise Edition. Online index creation and DBMS_REDEFINITION are Enterprise‑only features.
Use comments to ask for clarification. Post a solution as an answer.
34,775 reputation · 25 Jun 2022, 20:05 UTC
When you plan to apply a generated DDL script to a live Oracle database, the first safety net is confirming that the target tables actually support online redefinition. Oracle’s DBMS_REDEFINITION.CAN_REDEF_TABLES function returns a small table that lists each object’s redefinition status and the reason if it cannot be redefined.
SELECT table_name, can_redefine, reason
FROM TABLE(DBMS_REDEFINITION.CAN_REDEF_TABLES('SCHEMA_NAME'));
Review the can_redefine column: a value of 1 means the table is ready for DBMS_REDEFINITION sessions. If it is 0, the reason column explains the limitation (e.g., partitioned table, foreign key, LOB column).
ALTER TABLE … ONLINE statements, or schedule a brief maintenance window.Adding this pre‑validation step can prevent accidental lock escalation and make the migration process more predictable, especially when the Database Diff tool has already produced a full DDL script.