[oracle@oraclenode1 ~]$ cd /data
[oracle@oraclenode1 ~]$tar zcf oracle-clone.tar.gz oracle/ oraInventory/
[oracle@oraclenode1 ~]$ scp oracle-clone.tar.gz oracle2:/data
[oracle@oraclenode2 ~]$rm –rf /data/oraInventory/*
[oracle@oraclenode2 ~]$$ORACLE_HOME/clone/bin/clone.pl
\ORACLE_BASE=/data/oracle \ORACLE_HOME=/data/oracle/product/12.1.0/dbhome_1
\OSDBA_GROUP=dba OSOPER_GROUP=dba
\OSBACKUPDBA_GROUP=dba
\OSRACDBA_GROUP=dba
\INVENTORY_LOCATION=/data/oraInventory -defaultHomeName
# netca
# dbca
# netmgr
[oracle@oraclenode1 ~]$ sqlplus / as sysdba
SQL> select log_mode,force_logging from v$database;
SQL> shutdown immediate
SQL> startup mount
SQL> alter database archivelog;
SQL> alter database force logging;
SQL>alter database create standby controlfile as '/data/oracle/oradata/onisdb/standby.ctl';
SQL> select group#,bytes/1024/1024 from v$log;
select group#,bytes/1024/1024 from v$standby_log;
mkdir -p /data/oracle/{onlinelog,datafile}
mkdir -p /data/oracle/onisdb/archivelog
SQL> alter database add standby logfile group 4 '/data/oracle/onlinelog/stdredo01.log' size 50M;
SQL> alter database add standby logfile group 5 '/data/oracle/onlinelog/stdredo02.log' size 50M;
SQL> alter database add standby logfile group 6 '/data/oracle/onlinelog/stdredo03.log' size 50M;
SQL> alter database add standby logfile group 7 '/data/oracle/onlinelog/stdredo04.log' size 50M;
SQL> select group#,bytes/1024/1024 from v$standby_log;
SQL> alter system set log_archive_config='DG_CONFIG=(onisdb,sonisdb)';
SQL> alter system set log_archive_dest_2='SERVICE=sonisdb VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=sonisdb' scope=spfile;
SQL> alter system set log_archive_dest_state_1='enable';
SQL> alter system set log_archive_dest_state_2='enable';
SQL> alter system set db_file_name_convert='/data/oracle/datafile','/data/oracle/datafile' scope=spfile;
SQL> alter system set log_file_name_convert='/data/oracle/onlinelog','/data/oracle/onlinelog' scope=spfile;
SQL> alter system set fal_server='sonisdb';
SQL> alter system set fal_client='onisdb';
SQL> alter system set standby_file_management='AUTO';
SQL> quit
[oracle@oraclenode1 ~]$ vi /data/oracle/product/12.1.0/dbhome_1/network/admin/listener.ora
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = onisdb)
(ORACLE_HOME = /data/oracle/product/12.1.0/dbhome_1)
(SID_NAME = onisdb)
)
)
修改tnsnames.ora配置文件
[oracle@oraclenode1 ~]$vi /data/oracle/product/12.1.0/dbhome_1/network/admin/tnsnames.ora
SONISDB =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = oraclenode2)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = sonisdb.localdomain)
)
)
[oracle@oraclenode1 ~]$ lsnrctl stop
[oracle@oraclenode1 ~]$ lsnrctl start
[oracle@oraclenode1 ~]$sqlplus / as sysdba
SQL> create pfile from spfile;
*.db_unique_name='onisdb'
*.log_archive_dest_1='LOCATION=/data/oracle/sonisdb/archivelog VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=sonisdb'
SQL> create spfile from pfile;
SQL> alter database open;
[oracle@oraclenode1 ~]$ cd /data/oracle/product/12.1.0/dbhome_1/dbs/
[oracle@oraclenode1 dbs]$ scp initonisdb.ora orapwonisdb
\oraclenode2:/data/oracle/product/12.1.0/dbhome_1/dbs/
[oracle@oraclenode2 ~]$ cd /data/oracle/product/12.1.0/dbhome_1/dbs/
[oracle@oraclenode2 dbs]$ mv initonisdb.ora initsonisdb.ora
[oracle@oraclenode2 dbs]$ mv orapwonisdb orapwsonisdb
[oracle@oraclenode2 dbs]$ vi initsonisdb.ora
*.audit_file_dest='/data/oracle/admin/sonisdb/adump'
*.control_files='/data/oracle/oradata/sonisdb/control01.ctl','/data/oracle/oradata/sonisdb/control02.ctl'
*.db_unique_name='sonisdb'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=sonisdbXDB)'
*.fal_client='sonisdb'
*.fal_server='onisdb'
*.log_archive_config='DG_CONFIG=(onisdb,sonisdb)'
*.log_archive_dest_1='LOCATION=/data/oracle/sonisdb/archivelog VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=sonisdb'
*.log_archive_dest_2='SERVICE=onisdb VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=onisdb'
[oracle@oraclenode2 dbs]$ mkdir -p /data/oracle/admin/sonisdb/adump
[oracle@oraclenode2 dbs]$ mkdir -p /data/oracle/oradata/{onisdb,sonisdb}
[oracle@oraclenode2 dbs]$ mkdir -p /data/oracle/{datafile,onlinelog}
[oracle@oraclenode2 dbs]$ mkdir -p /data/oracle/sonisdb/archivelog
[oracle@oraclenode1 ~]$vi /data/oracle/product/12.1.0/dbhome_1/network/admin/tnsnames.ora
SONISDB =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = oraclenode2)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = sonisdb.localdomain)
)
)
[oracle@oraclenode1 ~]$ lsnrctl stop
[oracle@oraclenode1 ~]$ lsnrctl start
[oracle@oraclenode2 ~]$ sqlplus / as sysdba
SQL> startup nomount
[oracle@oraclenode1 ~]$ tnsping onisdb
[oracle@oraclenode1 ~]$ tnsping sonisdb
[oracle@oraclenode1 ~]$ sqlplus sys/81977100@onisdb as sysdba
[oracle@oraclenode1 ~]$ sqlplus sys/81977100@sonisdb as sysdba
[oracle@oraclenode2 ~]$ tnsping onisdb
[oracle@oraclenode2 ~]$ tnsping sonisdb
[oracle@oraclenode2 ~]$ sqlplus sys/81977100@onisdb as sysdba
[oracle@oraclenode2 ~]$ sqlplus sys/81977100@sonisdb as sysdba
[oracle@oraclenode1~]$rman target sys/81977100@onisdb \
auxiliary sys/81977100@sonisdb
RMAN> duplicate target database for standby from active database nofilenamecheck dorecover;
SQL> alter database open read only;
SQL> alter database recover managed standby database using current logfile disconnect from session;
alter system switch logfile;
select thread#,max(sequence#) from v$log_history group by thread#;
select process,status from v$managed_standby;
select max(sequence#) from v$standby_log;
select max(sequence#) from v$archived_log;
SQL>create table test as select * from dba_objects where rownum < 101;
#su - oracle
$sqlplus / as sysdba
SQL>select count(*) from test;