数据库
首页 > 数据库> > oracle迁移(duplicate)

oracle迁移(duplicate)

作者:互联网

目标库:
[oracle@oracle11g ~]$ mkdir -p /u01/app/oracle/oradata/orcl
[oracle@oracle11g ~]$ mkdir -p /u01/app/oracle/admin/orcl/{a,dp}dump
[oracle@oracle11g ~]$ mkdir -p /u01/app/oracle/fast_recovery_area/ORCL
[oracle@oracle11g ~]$ mkdir -p /u01/app/oracle/fast_recovery_area/orcl
[oracle@oracle11g dbs]$ mkdir -p /home/oracle/archivelog

[oracle@oracle11g ~]$ vi .bash_profile
export PATH
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1
export ORACLE_SID=orcl
export PATH=$PATH:$ORACLE_HOME/bin

[oracle@oracle11g ~]$ source .bash_profile

原库:
[oracle@node01 dbs]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on Fri May 20 22:13:52 2022

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

Connected to an idle instance.

SQL> create pfile from spfile;

File created

[oracle@node01 dbs]$ scp orapworcl oracle11g:/u01/app/oracle/product/11.2.0/db_1/dbs/
oracle@oracle11g's password:
orapworcl                                                                                                                       100% 1536    18.6KB/s   00:00

[oracle@node01 dbs]$ scp initorcl.ora oracle11g:/u01/app/oracle/product/11.2.0/db_1/dbs/
oracle@oracle11g's password:
initorcl.ora                                                                                                                    100%  891   215.7KB/s   00:00


目标库:
由于实例名,文件路径等没有改变,所以不需要修改文本参数文件内容。
orcl.__db_cache_size=314572800
orcl.__java_pool_size=4194304
orcl.__large_pool_size=8388608
orcl.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment
orcl.__pga_aggregate_target=306184192
orcl.__sga_target=457179136
orcl.__shared_io_pool_size=0
orcl.__shared_pool_size=121634816
orcl.__streams_pool_size=0
*.audit_file_dest='/u01/app/oracle/admin/orcl/adump'
*.audit_trail='db'
*.compatible='11.2.0.4.0'
*.control_files='/u01/app/oracle/oradata/orcl/control01.ctl','/u01/app/oracle/fast_recovery_area/orcl/control02.ctl'
*.db_block_size=8192
*.db_domain=''
*.db_name='orcl'
*.db_recovery_file_dest_size=4385144832
*.db_recovery_file_dest='/home/oracle/archivelog'
*.diagnostic_dest='/u01/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=orclXDB)'
*.memory_target=763363328
*.open_cursors=300
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.undo_tablespace='UNDOTBS1'


修改listener.ora和tnsnames.ora文件
原库:
listener.ora:
SID_LIST_LISTENER=
  (SID_LIST=
    (SID_DESC=
      (GLOBAL_DBNAME=orcl)
      (ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1)
      (SID_NAME=orcl))
    )

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = node01)(PORT = 1521))
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
    )
  )

ADR_BASE_LISTENER = /u01/app/oracle

tnsnames.ora:
ORCL =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.162.199)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = ORCL)
    )
  )

ORCL2 =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.162.200)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = ORCL)
    )
  )
  
目标库:
listener.ora:
SID_LIST_LISTENER=
  (SID_LIST=
    (SID_DESC=
      (GLOBAL_DBNAME=orcl)
      (ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1)
      (SID_NAME=orcl))
    )


LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = oracle11g)(PORT = 1521))
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
    )
  )

ADR_BASE_LISTENER = /u01/app/oracle

tnsnames.ora:
ORCL =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.162.199)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = ORCL)
    )
  )

ORCL2 =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.162.200)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = ORCL)
    )
  )

开启原库和目标库监听:
[oracle@node01 admin]$ lsnrctl start  
[oracle@oracle11g dbs]$ lsnrctl start

查看原库和目标库监听状态:
原库监听状态:
[oracle@node01 admin]$ lsnrctl status

LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 21-MAY-2022 10:42:20

Copyright (c) 1991, 2013, Oracle.  All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=node01)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 11.2.0.4.0 - Production
Start Date                21-MAY-2022 10:34:35
Uptime                    0 days 0 hr. 7 min. 45 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora
Listener Log File         /u01/app/oracle/diag/tnslsnr/node01/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=node01)(PORT=1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
Services Summary...
Service "orcl" has 2 instance(s).
  Instance "orcl", status UNKNOWN, has 1 handler(s) for this service...
  Instance "orcl", status READY, has 1 handler(s) for this service...
Service "orclXDB" has 1 instance(s).
  Instance "orcl", status READY, has 1 handler(s) for this service...
The command completed successfully

目标库监听状态:
[oracle@oracle11g dbs]$ lsnrctl status

LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 21-MAY-2022 02:45:34

Copyright (c) 1991, 2013, Oracle.  All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=oracle11g)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 11.2.0.4.0 - Production
Start Date                21-MAY-2022 02:34:29
Uptime                    0 days 0 hr. 11 min. 4 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora
Listener Log File         /u01/app/oracle/diag/tnslsnr/oracle11g/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=oracle11g)(PORT=1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
Services Summary...
Service "orcl" has 2 instance(s).
  Instance "orcl", status UNKNOWN, has 1 handler(s) for this service...
  Instance "orcl", status BLOCKED, has 1 handler(s) for this service...
The command completed successfully


测试原库和目标库网络:
原库:
[oracle@node01 admin]$ tnsping orcl

TNS Ping Utility for Linux: Version 11.2.0.4.0 - Production on 21-MAY-2022 10:34:41

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

Used parameter files:
/u01/app/oracle/product/11.2.0/db_1/network/admin/sqlnet.ora


Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.162.199)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = ORCL)))
OK (0 msec)
[oracle@node01 admin]$ tnsping orcl2

TNS Ping Utility for Linux: Version 11.2.0.4.0 - Production on 21-MAY-2022 10:34:47

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

Used parameter files:
/u01/app/oracle/product/11.2.0/db_1/network/admin/sqlnet.ora


Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.162.200)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = ORCL)))
OK (0 msec)

目标库:
[oracle@oracle11g admin]$ tnsping orcl

TNS Ping Utility for Linux: Version 11.2.0.4.0 - Production on 21-MAY-2022 02:35:02

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

Used parameter files:


Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.162.199)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = ORCL)))
OK (0 msec)
[oracle@oracle11g admin]$ tnsping orcl2

TNS Ping Utility for Linux: Version 11.2.0.4.0 - Production on 21-MAY-2022 02:35:09

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

Used parameter files:


Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.162.200)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = ORCL)))
OK (0 msec)


在原库连接目标库,开始复制数据库:
[oracle@node01 admin]$ rman target sys/oracle@orcl auxiliary sys/oracle@orcl2

Recovery Manager: Release 11.2.0.4.0 - Production on Sat May 21 10:57:05 2022

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

connected to target database: ORCL (DBID=1594731755)
connected to auxiliary database: ORCL (not mounted)

RMAN> duplicate target database to orcl from active database nofilenamecheck;

Starting Duplicate Db at 21-MAY-22
using target database control file instead of recovery catalog
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=19 device type=DISK

contents of Memory Script:
{
   sql clone "alter system set  db_name =
 ''ORCL'' comment=
 ''Modified by RMAN duplicate'' scope=spfile";
   sql clone "alter system set  db_unique_name =
 ''ORCL'' comment=
 ''Modified by RMAN duplicate'' scope=spfile";
   shutdown clone immediate;
   startup clone force nomount
   backup as copy current controlfile auxiliary format  '/u01/app/oracle/oradata/orcl/control01.ctl';
   restore clone controlfile to  '/u01/app/oracle/fast_recovery_area/orcl/control02.ctl' from
 '/u01/app/oracle/oradata/orcl/control01.ctl';
   alter clone database mount;
}
executing Memory Script

sql statement: alter system set  db_name =  ''ORCL'' comment= ''Modified by RMAN duplicate'' scope=spfile

sql statement: alter system set  db_unique_name =  ''ORCL'' comment= ''Modified by RMAN duplicate'' scope=spfile

Oracle instance shut down

Oracle instance started

Total System Global Area     759943168 bytes

Fixed Size                     2257112 bytes
Variable Size                499126056 bytes
Database Buffers             255852544 bytes
Redo Buffers                   2707456 bytes

Starting backup at 21-MAY-22
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=29 device type=DISK
channel ORA_DISK_1: starting datafile copy
copying current control file
output file name=/u01/app/oracle/product/11.2.0/db_1/dbs/snapcf_orcl.f tag=TAG20220521T105732 RECID=1 STAMP=1105268253
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
Finished backup at 21-MAY-22

Starting restore at 21-MAY-22
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=18 device type=DISK

channel ORA_AUX_DISK_1: copied control file copy
Finished restore at 21-MAY-22

database mounted

contents of Memory Script:
{
   set newname for datafile  1 to
 "/u01/app/oracle/oradata/orcl/system01.dbf";
   set newname for datafile  2 to
 "/u01/app/oracle/oradata/orcl/sysaux01.dbf";
   set newname for datafile  3 to
 "/u01/app/oracle/oradata/orcl/undotbs01.dbf";
   set newname for datafile  4 to
 "/u01/app/oracle/oradata/orcl/users01.dbf";
   set newname for datafile  5 to
 "/u01/app/oracle/oradata/orcl/test01.dbf";
   set newname for datafile  6 to
 "/u01/app/oracle/oradata/orcl/par01.dbf";
   backup as copy reuse
   datafile  1 auxiliary format
 "/u01/app/oracle/oradata/orcl/system01.dbf"   datafile
 2 auxiliary format
 "/u01/app/oracle/oradata/orcl/sysaux01.dbf"   datafile
 3 auxiliary format
 "/u01/app/oracle/oradata/orcl/undotbs01.dbf"   datafile
 4 auxiliary format
 "/u01/app/oracle/oradata/orcl/users01.dbf"   datafile
 5 auxiliary format
 "/u01/app/oracle/oradata/orcl/test01.dbf"   datafile
 6 auxiliary format
 "/u01/app/oracle/oradata/orcl/par01.dbf"   ;
   sql 'alter system archive log current';
}
executing Memory Script

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

Starting backup at 21-MAY-22
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile copy
input datafile file number=00001 name=/u01/app/oracle/oradata/orcl/system01.dbf
output file name=/u01/app/oracle/oradata/orcl/system01.dbf tag=TAG20220521T105739
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:01:16
channel ORA_DISK_1: starting datafile copy
input datafile file number=00002 name=/u01/app/oracle/oradata/orcl/sysaux01.dbf
output file name=/u01/app/oracle/oradata/orcl/sysaux01.dbf tag=TAG20220521T105739
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:55
channel ORA_DISK_1: starting datafile copy
input datafile file number=00006 name=/u01/app/oracle/oradata/orcl/par01.dbf
output file name=/u01/app/oracle/oradata/orcl/par01.dbf tag=TAG20220521T105739
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:25
channel ORA_DISK_1: starting datafile copy
input datafile file number=00003 name=/u01/app/oracle/oradata/orcl/undotbs01.dbf
output file name=/u01/app/oracle/oradata/orcl/undotbs01.dbf tag=TAG20220521T105739
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:15
channel ORA_DISK_1: starting datafile copy
input datafile file number=00005 name=/u01/app/oracle/oradata/orcl/test01.dbf
output file name=/u01/app/oracle/oradata/orcl/test01.dbf tag=TAG20220521T105739
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:03
channel ORA_DISK_1: starting datafile copy
input datafile file number=00004 name=/u01/app/oracle/oradata/orcl/users01.dbf
output file name=/u01/app/oracle/oradata/orcl/users01.dbf tag=TAG20220521T105739
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
Finished backup at 21-MAY-22

sql statement: alter system archive log current

contents of Memory Script:
{
   backup as copy reuse
   archivelog like  "/home/oracle/archivelog/ORCL/archivelog/2022_05_21/o1_mf_1_36_k8jogm12_.arc" auxiliary format
 "/home/oracle/archivelog/ORCL/archivelog/2022_05_21/o1_mf_1_36_%u_.arc"   ;
   catalog clone recovery area;
   switch clone datafile all;
}
executing Memory Script

Starting backup at 21-MAY-22
using channel ORA_DISK_1
channel ORA_DISK_1: starting archived log copy
input archived log thread=1 sequence=36 RECID=31 STAMP=1105268435
output file name=/home/oracle/archivelog/ORCL/archivelog/2022_05_21/o1_mf_1_36_1f0u23mj_.arc RECID=0 STAMP=0
channel ORA_DISK_1: archived log copy complete, elapsed time: 00:00:01
Finished backup at 21-MAY-22

searching for all files in the recovery area

List of Files Unknown to the Database
=====================================
File Name: /home/oracle/archivelog/ORCL/archivelog/2022_05_21/o1_mf_1_36_1f0u23mj_.arc
cataloging files...
cataloging done

List of Cataloged Files
=======================
File Name: /home/oracle/archivelog/ORCL/archivelog/2022_05_21/o1_mf_1_36_1f0u23mj_.arc

datafile 1 switched to datafile copy
input datafile copy RECID=1 STAMP=1105239639 file name=/u01/app/oracle/oradata/orcl/system01.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=2 STAMP=1105239639 file name=/u01/app/oracle/oradata/orcl/sysaux01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=3 STAMP=1105239639 file name=/u01/app/oracle/oradata/orcl/undotbs01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=4 STAMP=1105239639 file name=/u01/app/oracle/oradata/orcl/users01.dbf
datafile 5 switched to datafile copy
input datafile copy RECID=5 STAMP=1105239639 file name=/u01/app/oracle/oradata/orcl/test01.dbf
datafile 6 switched to datafile copy
input datafile copy RECID=6 STAMP=1105239639 file name=/u01/app/oracle/oradata/orcl/par01.dbf

contents of Memory Script:
{
   set until scn  1381735;
   recover
   clone database
    delete archivelog
   ;
}
executing Memory Script

executing command: SET until clause

Starting recover at 21-MAY-22
using channel ORA_AUX_DISK_1

starting media recovery

archived log for thread 1 with sequence 36 is already on disk as file /home/oracle/archivelog/ORCL/archivelog/2022_05_21/o1_mf_1_36_1f0u23mj_.arc
archived log file name=/home/oracle/archivelog/ORCL/archivelog/2022_05_21/o1_mf_1_36_1f0u23mj_.arc thread=1 sequence=36
media recovery complete, elapsed time: 00:00:01
Finished recover at 21-MAY-22
Oracle instance started

Total System Global Area     759943168 bytes

Fixed Size                     2257112 bytes
Variable Size                499126056 bytes
Database Buffers             255852544 bytes
Redo Buffers                   2707456 bytes

contents of Memory Script:
{
   sql clone "alter system set  db_name =
 ''ORCL'' comment=
 ''Reset to original value by RMAN'' scope=spfile";
   sql clone "alter system reset  db_unique_name scope=spfile";
   shutdown clone immediate;
   startup clone nomount;
}
executing Memory Script

sql statement: alter system set  db_name =  ''ORCL'' comment= ''Reset to original value by RMAN'' scope=spfile

sql statement: alter system reset  db_unique_name scope=spfile

Oracle instance shut down

connected to auxiliary database (not started)
Oracle instance started

Total System Global Area     759943168 bytes

Fixed Size                     2257112 bytes
Variable Size                499126056 bytes
Database Buffers             255852544 bytes
Redo Buffers                   2707456 bytes
sql statement: CREATE CONTROLFILE REUSE SET DATABASE "ORCL" RESETLOGS ARCHIVELOG
  MAXLOGFILES     16
  MAXLOGMEMBERS      3
  MAXDATAFILES      100
  MAXINSTANCES     8
  MAXLOGHISTORY      292
 LOGFILE
  GROUP   1  SIZE 50 M ,
  GROUP   2  SIZE 50 M ,
  GROUP   3  SIZE 50 M
 DATAFILE
  '/u01/app/oracle/oradata/orcl/system01.dbf'
 CHARACTER SET AL32UTF8


contents of Memory Script:
{
   set newname for tempfile  1 to
 "/u01/app/oracle/oradata/orcl/temp01.dbf";
   switch clone tempfile all;
   catalog clone datafilecopy  "/u01/app/oracle/oradata/orcl/sysaux01.dbf",
 "/u01/app/oracle/oradata/orcl/undotbs01.dbf",
 "/u01/app/oracle/oradata/orcl/users01.dbf",
 "/u01/app/oracle/oradata/orcl/test01.dbf",
 "/u01/app/oracle/oradata/orcl/par01.dbf";
   switch clone datafile all;
}
executing Memory Script

executing command: SET NEWNAME

renamed tempfile 1 to /u01/app/oracle/oradata/orcl/temp01.dbf in control file

cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/orcl/sysaux01.dbf RECID=1 STAMP=1105239652
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/orcl/undotbs01.dbf RECID=2 STAMP=1105239652
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/orcl/users01.dbf RECID=3 STAMP=1105239652
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/orcl/test01.dbf RECID=4 STAMP=1105239652
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/orcl/par01.dbf RECID=5 STAMP=1105239652

datafile 2 switched to datafile copy
input datafile copy RECID=1 STAMP=1105239652 file name=/u01/app/oracle/oradata/orcl/sysaux01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=2 STAMP=1105239652 file name=/u01/app/oracle/oradata/orcl/undotbs01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=3 STAMP=1105239652 file name=/u01/app/oracle/oradata/orcl/users01.dbf
datafile 5 switched to datafile copy
input datafile copy RECID=4 STAMP=1105239652 file name=/u01/app/oracle/oradata/orcl/test01.dbf
datafile 6 switched to datafile copy
input datafile copy RECID=5 STAMP=1105239652 file name=/u01/app/oracle/oradata/orcl/par01.dbf

contents of Memory Script:
{
   Alter clone database open resetlogs;
}
executing Memory Script

database opened
Finished Duplicate Db at 21-MAY-22

RMAN>

自此,数据库迁移完成!

  

标签:datafile,app,orcl,duplicate,oradata,oracle,迁移,u01
来源: https://www.cnblogs.com/orcl-2018/p/16294301.html