主:192.168.187.152
备:192.168.187.252
ORACLE: 11.2.0.1
SQL> alter system set log_archive_dest_1='location=/home/oracle/archivelog' scope=spfile;
System altered.
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount;
ORACLE instance started.
Total System Global Area 417546240 bytes
Fixed Size 2213936 bytes
Variable Size 268437456 bytes
Database Buffers 138412032 bytes
Redo Buffers 8482816 bytes
Database mounted.
SQL> alter database archivelog;
Database altered.
SQL> alter database force logging;
Database altered.
SQL> alter database open;
Database altered.
[oracle@rac1 dbs]$ orapwd file=$ORACLE_HOME/dbs/orapworcl password=admin
[oracle@rac1 dbs]$ ls
hc_DBUA0.dat hc_orcl.dat init.ora lkORCL orapworcl spfileorcl.ora
[oracle@rac1 dbs]$ scp orapworcl oracle@192.168.187.252:$ORACLE_HOME/dbs
The authenticity of host '192.168.187.252 (192.168.187.252)' can't be established.
RSA key fingerprint is 39:90:95:8e:f9:cc:e1:a0:f6:57:fc:62:a3:e6:be:1d.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.187.252' (RSA) to the list of known hosts.
oracle@192.168.187.252's password:
orapworcl 100% 1536 1.5KB/s 00:00
SQL> create pfile='/home/oracle/initorcl.ora' from spfile;
File created.
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
[oracle@rac1 ~]$ scp initorcl.ora oracle@192.168.187.252:/home/oracle
oracle@192.168.187.252's password:
initorcl.ora 100% 942 0.9KB/s 00:00
在文件的最后加上:
*.db_unique_name=standby
*.log_archive_config='dg_config=(primary,standby)'
*.log_archive_dest_2='service=primary VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLES) db_unique_name=primary'
*.standby_file_management=auto
*.standby_archive_dest='/home/oracle/archivelog'
*.fal_server='primary'
*.fal_client='standby'
[oracle@rac2 ~]$ mkdir flash_recovery_area
[oracle@rac2 ~]$ mkdir -p archivelog
[oracle@rac2 ~]$ mkdir -p /home/oracle/admin/orcl/adump
[oracle@rac2 ~]$ ls
admin checkpoints flash_recovery_area linux.x64_11gR2_database_1of2.zip oraInventory
archivelog database initorcl.ora linux.x64_11gR2_database_2of2.zip product
[oracle@rac2 ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.1.0 Production on Thu Aug 9 21:42:52 2012
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to an idle instance.
SQL> startup nomount pfile='/home/oracle/initorcl.ora';
ORA-32006: STANDBY_ARCHIVE_DEST initialization parameter has been deprecated
ORACLE instance started.
Total System Global Area 417546240 bytes
Fixed Size 2213936 bytes
Variable Size 272631760 bytes
Database Buffers 134217728 bytes
Redo Buffers 8482816 bytes
新建TNSNAME.ORA文件增加以下内容。
primary =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST =192.168.3.120 )(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SID = primary)
)
)
standby =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST =192.168.3.189 )(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SID = primary)
)
)
RMAN> run{
allocate channel a1 type disk;
allocate channel a2 type disk;
backup format='/home/oracle/rman/FULL_%d_%T_%s' database plus archivelog;
backup format='/home/oracle/rman/ctl_%U' current controlfile for standby;
release channel a2;
release channel a1;
}
using target database control file instead of recovery catalog
allocated channel: a1
channel a1: SID=24 device type=DISK
allocated channel: a2
channel a2: SID=147 device type=DISK
Starting backup at 09-AUG-12
current log archived
channel a1: starting archived log backup set
channel a1: specifying archived log(s) in backup set
input archived log thread=1 sequence=6 RECID=1 STAMP=790894352
channel a1: starting piece 1 at 09-AUG-12
channel a1: finished piece 1 at 09-AUG-12
piece handle=/home/oracle/rman/FULL_ORCL_20120809_1 tag=TAG20120809T205232 comment=NONE
channel a1: backup set complete, elapsed time: 00:00:03
Finished backup at 09-AUG-12
Starting backup at 09-AUG-12
channel a1: starting full datafile backup set
channel a1: specifying datafile(s) in backup set
input datafile file number=00001 name=/home/oracle/oradata/orcl/system01.dbf
input datafile file number=00005 name=/home/oracle/oradata/orcl/example01.dbf
channel a1: starting piece 1 at 09-AUG-12
channel a2: starting full datafile backup set
channel a2: specifying datafile(s) in backup set
input datafile file number=00002 name=/home/oracle/oradata/orcl/sysaux01.dbf
input datafile file number=00003 name=/home/oracle/oradata/orcl/undotbs01.dbf
input datafile file number=00004 name=/home/oracle/oradata/orcl/users01.dbf
channel a2: starting piece 1 at 09-AUG-12
channel a1: finished piece 1 at 09-AUG-12
piece handle=/home/oracle/rman/FULL_ORCL_20120809_2 tag=TAG20120809T205236 comment=NONE
channel a1: backup set complete, elapsed time: 00:00:45
channel a1: starting full datafile backup set
channel a1: specifying datafile(s) in backup set
channel a2: finished piece 1 at 09-AUG-12
piece handle=/home/oracle/rman/FULL_ORCL_20120809_3 tag=TAG20120809T205236 comment=NONE
channel a2: backup set complete, elapsed time: 00:00:45
channel a2: starting full datafile backup set
channel a2: specifying datafile(s) in backup set
including current SPFILE in backup set
channel a2: starting piece 1 at 09-AUG-12
including current control file in backup set
channel a1: starting piece 1 at 09-AUG-12
channel a1: finished piece 1 at 09-AUG-12
piece handle=/home/oracle/rman/FULL_ORCL_20120809_4 tag=TAG20120809T205236 comment=NONE
channel a1: backup set complete, elapsed time: 00:00:01
channel a2: finished piece 1 at 09-AUG-12
piece handle=/home/oracle/rman/FULL_ORCL_20120809_5 tag=TAG20120809T205236 comment=NONE
channel a2: backup set complete, elapsed time: 00:00:01
Finished backup at 09-AUG-12
Starting backup at 09-AUG-12
current log archived
channel a1: starting archived log backup set
channel a1: specifying archived log(s) in backup set
input archived log thread=1 sequence=7 RECID=2 STAMP=790894404
channel a1: starting piece 1 at 09-AUG-12
channel a1: finished piece 1 at 09-AUG-12
piece handle=/home/oracle/rman/FULL_ORCL_20120809_6 tag=TAG20120809T205324 comment=NONE
channel a1: backup set complete, elapsed time: 00:00:01
Finished backup at 09-AUG-12
Starting backup at 09-AUG-12
channel a1: starting full datafile backup set
channel a1: specifying datafile(s) in backup set
including standby control file in backup set
channel a1: starting piece 1 at 09-AUG-12
channel a1: finished piece 1 at 09-AUG-12
piece handle=/home/oracle/rman/ctl_07ni85q6_1_1 tag=TAG20120809T205325 comment=NONE
channel a1: backup set complete, elapsed time: 00:00:01
Finished backup at 09-AUG-12
released channel: a2
released channel: a1
RMAN> exit
Recovery Manager complete.
[oracle@rac1 ~]$ scp /home/oracle/rman/* oracle@192.168.187.252:/home/oracle/rman
oracle@192.168.187.252's password:
ctl_07ni85q6_1_1 100% 9568KB 9.3MB/s 00:00
FULL_ORCL_20120809_1 100% 24MB 23.7MB/s 00:01
FULL_ORCL_20120809_2 100% 658MB 19.3MB/s 00:34
FULL_ORCL_20120809_3 100% 470MB 18.8MB/s 00:25
FULL_ORCL_20120809_4 100% 9568KB 9.3MB/s 00:01
FULL_ORCL_20120809_5 100% 96KB 96.0KB/s 00:00
FULL_ORCL_20120809_6 100% 33KB 33.0KB/s 00:00
[oracle@rac2 ~]$ rman target sys/admin@primary auxiliary /
Recovery Manager: Release 11.2.0.1.0 - Production on Thu Aug 9 22:10:28 2012
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
connected to target database: ORCL (DBID=1318672716)
connected to auxiliary database: ORCL (not mounted)
RMAN> duplicate target database for standby nofilenamecheck;
Starting Duplicate Db at 09-AUG-12
using target database control file instead of recovery catalog
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=134 device type=DISK
contents of Memory Script.:
{
restore clone standby controlfile;
}
executing Memory Script
Starting restore at 09-AUG-12
using channel ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: restoring control file
channel ORA_AUX_DISK_1: reading from backup piece /home/oracle/rman/ctl_07ni85q6_1_1
channel ORA_AUX_DISK_1: piece handle=/home/oracle/rman/ctl_07ni85q6_1_1 tag=TAG20120809T205325
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/home/oracle/oradata/orcl/control01.ctl
output file name=/home/oracle/flash_recovery_area/orcl/control02.ctl
Finished restore at 09-AUG-12
contents of Memory Script.:
{
sql clone 'alter database mount standby database';
}
executing Memory Script
sql statement: alter database mount standby database
contents of Memory Script.:
{
set newname for tempfile 1 to
"/home/oracle/oradata/orcl/temp01.dbf";
switch clone tempfile all;
set newname for datafile 1 to
"/home/oracle/oradata/orcl/system01.dbf";
set newname for datafile 2 to
"/home/oracle/oradata/orcl/sysaux01.dbf";
set newname for datafile 3 to
"/home/oracle/oradata/orcl/undotbs01.dbf";
set newname for datafile 4 to
"/home/oracle/oradata/orcl/users01.dbf";
set newname for datafile 5 to
"/home/oracle/oradata/orcl/example01.dbf";
restore
clone database
;
}
executing Memory Script
executing command: SET NEWNAME
renamed tempfile 1 to /home/oracle/oradata/orcl/temp01.dbf in control file
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
Starting restore at 09-AUG-12
using channel ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00001 to /home/oracle/oradata/orcl/system01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00005 to /home/oracle/oradata/orcl/example01.dbf
channel ORA_AUX_DISK_1: reading from backup piece /home/oracle/rman/FULL_ORCL_20120809_2
channel ORA_AUX_DISK_1: piece handle=/home/oracle/rman/FULL_ORCL_20120809_2 tag=TAG20120809T205236
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:15
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00002 to /home/oracle/oradata/orcl/sysaux01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00003 to /home/oracle/oradata/orcl/undotbs01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00004 to /home/oracle/oradata/orcl/users01.dbf
channel ORA_AUX_DISK_1: reading from backup piece /home/oracle/rman/FULL_ORCL_20120809_3
channel ORA_AUX_DISK_1: piece handle=/home/oracle/rman/FULL_ORCL_20120809_3 tag=TAG20120809T205236
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:15
Finished restore at 09-AUG-12
contents of Memory Script.:
{
switch clone datafile all;
}
executing Memory Script
datafile 1 switched to datafile copy
input datafile copy RECID=2 STAMP=790899074 file name=/home/oracle/oradata/orcl/system01.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=3 STAMP=790899074 file name=/home/oracle/oradata/orcl/sysaux01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=4 STAMP=790899074 file name=/home/oracle/oradata/orcl/undotbs01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=5 STAMP=790899074 file name=/home/oracle/oradata/orcl/users01.dbf
datafile 5 switched to datafile copy
input datafile copy RECID=6 STAMP=790899074 file name=/home/oracle/oradata/orcl/example01.dbf
Finished Duplicate Db at 09-AUG-12
SQL> Alter database add standby logfile group 8 ('/home/oracle/oradata/orcl/redo_08.log') size 50m;
Database altered.
SQL> Alter database add standby logfile group 9 ('/home/oracle/oradata/orcl/redo_09.log') size 50m;
Database altered.
SQL> Alter database add standby logfile group 10 ('/home/oracle/oradata/orcl/redo_10.log') size 50m;
Database altered.
SQL> alter database recover managed standby database using current logfile disconnect from session;
Database altered.
SQL> select recovery_mode from v$archive_dest_status;
RECOVERY_MODE
-----------------------
MANAGED REAL TIME APPLY
*.db_unique_name=primary
*.log_archive_config='dg_config=(primary,standby)'
*.log_archive_dest_2='service=standby VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLES) db_unique_name=standby'
*.standby_file_management=auto
*.fal_server='standby'
*.fal_client='primary'
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup nomount pfile='/home/oracle/initorcl.ora';
ORACLE instance started.
Total System Global Area 417546240 bytes
Fixed Size 2213936 bytes
Variable Size 272631760 bytes
Database Buffers 134217728 bytes
Redo Buffers 8482816 bytes
SQL> create spfile from pfile='/home/oracle/initorcl.ora';
File created.
SQL> shutdown immediate;
ORA-01507: database not mounted
ORACLE instance shut down.
SQL> startup
ORACLE instance started.
Total System Global Area 417546240 bytes
Fixed Size 2213936 bytes
Variable Size 272631760 bytes
Database Buffers 134217728 bytes
Redo Buffers 8482816 bytes
Database mounted.
Database opened.
SQL>
SQL> select sequence#, applied from v$archived_log;
SEQUENCE# APPLIED
---------- ---------
9 YES
8 YES
SQL> alter database recover managed standby database cancel;
Database altered.
SQL> alter database open;
Database altered.
SQL> select open_mode from v$database;
OPEN_MODE
--------------------
READ ONLY
SQL> alter database recover managed standby database using current logfile disconnect from session;
Database altered.
SQL> select open_mode from v$database;
OPEN_MODE
--------------------
READ ONLY WITH APPLY
SQL> select process, status from v$managed_standby;
PROCESS STATUS
--------- ------------
ARCH CONNECTED
ARCH CONNECTED
ARCH CLOSING
ARCH CLOSING
MRP0 APPLYING_LOG
RFS IDLE
RFS IDLE
RFS IDLE
主库新建立,表空间,数据文件,用户,表,插入数据,切换归档
SQL> create tablespace test datafile'/home/oracle/oradata/orcl/test01.dbf' size 20m;
Tablespace created.
SQL> create user test identified by test default tablespace test;
User created.
SQL> grant connect, resource to test;
Grant succeeded.
SQL> conn test/test;
Connected.
SQL> create table t(id number(9));
Table created.
SQL> insert into t(id) values(9);
1 row created.
SQL> commit;
Commit complete.
SQL> conn / as sysdba
Connected.
SQL> alter system switch logfile;
System altered.
备库查询
SQL> select sequence#, applied from v$archived_log;
SEQUENCE# APPLIED
---------- ---------
9 YES
8 YES
10 YES
SQL> conn test/test;
Connected.
SQL> select * from t;
ID
----------
9
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/22740983/viewspace-745038/ ,如需转载,请注明出处,否则将追究法律责任。