sql >> Base de Datos >  >> RDS >> Database

Migración de datos usando Network_link

Fuente :exa01dm05 (Oracle 11g)
Objetivo :exa02dm06  (Oracle 18c)

1. Cree el directorio de volcado en PDB y CDB

exa02dm06:. oraenv
ORACLE_SID = [oracle] ? CDBGPA
ORACLE_HOME = [/home/oracle] ? /u01/app/oracle/product/18.0.0.0/dbhome_1
The Oracle base remains unchanged with value /u01/app/oracle
exa02dm06: export ORACLE_SID=CDBGPA1
exa02dm06: sqlplus / as sysdba

SQL*Plus: Release 18.0.0.0.0 - Production on Thu Jan 28 15:29:13 2021
Version 18.2.0.0.0

Copyright (c) 1982, 2018, Oracle. All rights reserved.

Connected to:
Oracle Database 18c Enterprise Edition Release 18.0.0.0.0 - Production
Version 18.2.0.0.0

SQL> show pdbs

CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 PPDBTESTE READ WRITE NO
4 HPDBGDA READ WRITE NO

SQL> alter session set container = HPDBGDA;

Session altered.

SQL> CREATE OR REPLACE DIRECTORY MIG AS '/exp';

Directory created.

2. Agregue la entrada tnsnames de SOURCE en el servidor TARGET DB exa02dm06


gda_mig =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = exa01dm05)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = gda)
(UR=A)
)
)

$ tnsping gda_mig

TNS Ping Utility for Linux: Version 18.0.0.0.0 - Production on 28-JAN-2021 11:38:40

Copyright (c) 1997, 2017, Oracle. All rights reserved.

Used parameter files:

Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = exa01dm05)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = gda) (UR=A)))
OK (10 msec)

3. Cree el dblink en el PDB en Target.


SQL> create public database link gda_link connect to system identified by xxxxx using 'gda_mig';

Database link created.

SQL> select sysdate from dual@gda_link;

SYSDATE
---------------
02-FEB-21

4. Crea el archivo sql con el DDL para todos los espacios de tablas


exa01dm05: impdp directory=MIG dumpfile=gda.dmp sqlfile=tablespaces.sql include=TABLESPACE full=yes
Import: Release 11.2.0.4.0 - Production on Thu Jan 28 15:42:35 2021

Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.

Username: system
Password:

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
Master table "SYSTEM"."SYS_SQL_FILE_FULL_01" successfully loaded/unloaded
Starting "SYSTEM"."SYS_SQL_FILE_FULL_01": system/******** directory=DM_TESTE_MIG dumpfile=hsbd.dmp sqlfile=tablespaces.sql include=TABLESPACE full=yes
Processing object type DATABASE_EXPORT/TABLESPACE
Job "SYSTEM"."SYS_SQL_FILE_FULL_01" successfully completed at Thu Jan 28 15:42:48 2021 elapsed 0 00:00:01

5. Cambie el nombre de la ruta de los archivos de datos en el archivo sql (tablespaces.sql) según el destino.

6. Cree espacios de tablas en el destino:


exa01dm06: sqlplus "/ as sysdba" @tablespaces.sql

7. Realice la importación utilizando network_link. Yo uso parfile "imp_gda.par".


# cat imp_gda.par

directory=MIG
network_link=gda_link
logfile=import_gda.log
cluster=N
parallel=4
full=yes
exclude=schema:"IN ('SCOTT','SYS','SYSTEM','WMSYS','XDB','OJVMSYS','ORDDATA','ORDSYS','OUTLN','AUDSYS','CTXSYS')"

$ impdp \'sys@HPDBGDA as sysdba\' parfile=imp_gda.par

Import: Release 18.0.0.0.0 - Production on Tue Feb 2 12:13:35 2021
Version 18.2.0.0.0

Copyright (c) 1982, 2018, Oracle and/or its affiliates. All rights reserved.
Password:

Connected to: Oracle Database 18c Enterprise Edition Release 18.0.0.0.0 - Production
Starting "SYS"."SYS_IMPORT_FULL_01": "sys/********@HPDBGDA AS SYSDBA" parfile=imp_gda.par
Estimate in progress using BLOCKS method...
Processing object type DATABASE_EXPORT/SCHEMA/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 375.9 MB

8. Vuelva a compilar objetos no válidos:


SQL> alter session set container = HPDBGDA;

Session altered.

SQL> EXEC DBMS_UTILITY.compile_schema(schema => 'DBGDA', compile_all => FALSE);

PL/SQL procedure successfully completed.

9. Reúne estadísticas:


DECLARE
BEGIN
DBMS_STATS.GATHER_SCHEMA_STATS (ownname => 'DBGDA',
method_opt => 'for all columns size auto',
granularity => 'ALL',
cascade => TRUE);
END;
/

PL/SQL procedure successfully completed.