Skip to content

Cross-database data recovery using database links

Cross-database data recovery using database links is a procedure utilized in Oracle Database environments to restore specific data segments from a remote database system to a local client.^[600-developer-database-oracle-oracle-db-link.md] This technique is particularly useful for reconstructing tables or entries based on specific criteria, such as time ranges or identifiers, by establishing a direct connection pathway known as a database link.^[600-developer-database-oracle-oracle-db-link.md]

Overview

The process involves two main steps: establishing a connection to the remote database and executing a data recovery operation via SQL commands.^[600-developer-database-oracle-oracle-db-link.md] This allows for the selective retrieval of data—for example, recovering orders created within a specific timeframe—without requiring a full database restoration.^[600-developer-database-oracle-oracle-db-link.md]

Implementation Steps

To facilitate communication between the local (client) database and the remote (server) database, a DATABASE LINK must be created on the client side^[600-developer-database-oracle-oracle-db-link.md]. This link definition includes the remote username, password, and connection details (protocol, host, port, and service name)^[600-developer-database-oracle-oracle-db-link.md].

Example syntax:

CREATE DATABASE LINK mypaycenter 
  CONNECT TO mypaycenter IDENTIFIED BY password 
  USING '(DESCRIPTION=
    (ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST = 10.140.0.1)(PORT = 1521)))
    (CONNECT_DATA = (SERVICE_NAME = myPay))
  )';

2. Executing Data Recovery

Once the link is established, data is recovered by selecting from the remote table via the link and inserting it into the local table^[600-developer-database-oracle-oracle-db-link.md]. A typical recovery script uses an INSERT INTO ... SELECT structure combined with UNION ALL logic to handle multiple specific date ranges or conditions while avoiding duplicate entries^[600-developer-database-oracle-oracle-db-link.md].

The recovery logic generally follows this pattern: 1. Select specific columns from the remote table (e.g., py_order@mypaycenter). 2. Apply filtering conditions, such as Customer ID (CUST_ID) and date ranges (order_no patterns or >= comparisons). 3. Exclude records that already exist in the local table to ensure idempotency. 4. Combine multiple recovery ranges (e.g., different days) using UNION ALL.

Sources

^[600-developer-database-oracle-oracle-db-link.md]

  • [[Oracle Database]]
  • [[SQL]]
  • [[Data recovery]]