Oracle 如何快速的 duplicate 一個資料庫

jhon_lee發表於2022-05-01

首先

  1.duplicate daabase幹什麼的

   快速複製一個資料庫。通常用在系統遷移、測試系統搭建。

   使用active方式複製,可以不需要有備份檔案的情況下,直接複製資料庫到新的地方。

   如果有備份系統,我是不建議從生產直接duplicate資料庫的。因為直接操作生產系統還是有些風險的,比如你搞錯源和目標了,刪庫跑路了。

  

那麼開搞吧

  

1.新的資料庫一定要使用使用新的dbname有別於生產

  因為如果使用了相同的名字,你將在最後的時候發現新的資料庫無法OPEN。

*.audit_file_dest='/data/app/oracle/admin/gtmstt/adump'
*.audit_trail='db'
*.compatible='11.2.0.4.0'
*.control_files='/data/app/oracle/oradata/gtmstt/control01.ctl','/data/app/oracle/fast_recovery_area/gtmstt/control02.ctl'
*.db_block_size=8192
*.db_domain=''
*.db_name='gtmstt'
*.db_recovery_file_dest='/data/app/oracle/fast_recovery_area'
*.db_recovery_file_dest_size=4385144832
*.diagnostic_dest='/data/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=gtmsttXDB)'
*.open_cursors=300
*.pga_aggregate_target=2434793472
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.sga_target=4293918720
*.undo_tablespace='UNDOTBS1'
*.log_file_name_convert='/data/app/oracle/oradata/gtmsdb','/data/app/oracle/oradata/gtmstt'
*.db_file_name_convert='/data/app/oracle/oradata/gtmsdb','/data/app/oracle/oradata/gtmstt','/data/app/oracle/oradata','/data/app/oracle/oradata/gtmstt'


2.建立新的路徑

mkdir -p /data/app/oracle/admin/gtmstt/adump

mkdir -p /data/app/oracle/oradata/gtmstt

mkdir -p /data/app/oracle/fast_recovery_area/gtmstt


3.新庫要在listener中靜態註冊

listenser.ora 和 tnsnames.ora檔案中的 行縮排是不能省略的。否則你會遇到奇奇怪怪的問題。

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

SID_LIST_LISTENER =
   (SID_LIST =
    (SID_DESC =
      (SID_NAME = gtmstt)
      (ORACLE_HOME = /data/app/oracle/product/11.2.0/dbhome_1)
    )
  )

ADR_BASE_LISTENER = /data/app/oracle

 

[oracle@gtmstestdb ~]$ lsnrctl status

LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 07-NOV-2020 17:13:54

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

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 11.2.0.4.0 - Production
Start Date 07-NOV-2020 16:57:03
Uptime 0 days 0 hr. 16 min. 50 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /data/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora
Listener Log File /data/app/oracle/diag/tnslsnr/gtmstestdb/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=10.1.1.3)(PORT=1521)))
Services Summary...
Service "gtmstt" has 2 instance(s).
Instance "gtmstt", status  UNKNOWN, has 1 handler(s) for this service...  這個UNKNOWN 就是靜態註冊上的意思。
The command completed successfully


4.一定要檢查防火牆是否關閉

[root@gtmstestdb ~]$ /bin/systemctl status firewalld

● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: inactive (dead)
Docs: man:firewalld(1)

 

Nov 05 17:22:39 gtmstestdb systemd[1]: Starting firewalld - dynamic firewall daemon...
Nov 05 17:22:39 gtmstestdb systemd[1]: Started firewalld - dynamic firewall daemon.
Nov 06 16:11:54 gtmstestdb systemd[1]: Stopping firewalld - dynamic firewall daemon...
Nov 06 16:11:54 gtmstestdb systemd[1]: Stopped firewalld - dynamic firewall daemon.

 

5.配置源庫tnsnames.ora 或者配置 測試庫tnsnames.ora均可,取決於你想在哪一邊進行操作

gtmsdb_du =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 10.1.1.3)(PORT = 1521))
      (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME= gtmsdb)
    )
  )

gtmsdb=
  (DESCRIPTION=
    (ADDRESS=(PROTOCOL=TCP)(HOST=10.1.1.2)(PORT=1521))
    (CONNECT_DATA=
      (SERVER=dedicated)
      (SERVICE_NAME=gtmsdb)
    )
  )

5.開始duplicate在哪一端操作均可以,命令是一樣的

target 後面加源庫
auxiliary 後面加新庫

rman target sys/oracle@gtmsdb auxiliary sys/oracle@gtmsdb_du


run{
allocate channel c1 type disk;
allocate channel c2 type disk;
allocate channel c3 type disk;
allocate channel c4 type disk;
allocate AUXILIARY channel c5 type disk;
allocate AUXILIARY channel c6 type disk;
allocate AUXILIARY channel c7 type disk;
allocate AUXILIARY channel c8 type disk;
duplicate target database to gtmstt from active database nofilenamecheck ;
release channel c1;
release channel c2;
release channel c3;
release channel c4;
release channel c5;
release channel c6;
release channel c7;
release channel c8;

}

 


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26474945/viewspace-2889762/,如需轉載,請註明出處,否則將追究法律責任。

相關文章