Oracle11gR2 DataGuard 实验

 

 
一.系统复制
1. 建用户组和用户
groupadd -g 507 oinstall
groupadd -g 502 dba
useradd -u 502 -g oinstall -G dba oracle
passwd oracle
2. 复制.bash_profile从10.253.32.106到10.253.81.14
scp [email protected]:/home/oracle/.bash_profile ./
3. 以root身份打包原服务器上oracle目录
[root@CSICN01TESTDB /]# du -sh /u01
5.9G     /u01
[root@CSICN01TESTDB /]# tar -zcvpf /tmp/u01.tar.gz /u01
tar: Removing leading `/' from member names
/u01/
/u01/app/
/u01/app/oracle/
         tar –help / man tar
4. 复制到目标机上,并解压(如上图)
scp [email protected]:/tmp/u01.tar.gz /tmp
tar -zxvpf /tmp/u01.tar.gz -C /
 
5. 修改两台机器上的listener.ora 和 tnsnames.ora里面的主机名
 
6. 开启侦听和数据库
Lsnrctl start
Sql>startup
 
二.在主库上的操作:
1.       修改dataguard配置相关的各个参数
SQL> alter database force logging;
 
SQL> alter system set db_unique_name='testdb' scope=spfile;
 
System altered.
 
SQL> alter system set log_archive_config='DG_CONFIG=(testdb,testdb_standby)';
 
System altered.
 
SQL> alter system set log_archive_dest_1='LOCATION=/u01/app/oracle/flash_recovery_area VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=testdb';
 
System altered.
 
SQL> alter system set log_archive_dest_2='SERVICE=testdb_standby lgwr sync valid_for=(online_logfile,primary_role) db_unique_name=testdb_standby';
 
System altered.
 
SQL> alter system set LOG_ARCHIVE_DEST_STATE_1=ENABLE scope=both;
 
System altered.
 
SQL> alter system set LOG_ARCHIVE_DEST_STATE_2=ENABLE scope=both;
 
System altered.
 
SQL> alter system set fal_server=testdb_standby;
 
System altered.
 
SQL> alter system set fal_client=testdb;
 
System altered.
 
SQL> alter system set standby_file_management=auto;
 
System altered.
 
 
2.       建standby log
alter database add standby logfile
group 4 ('/u01/app/oracle/oradata/testdb/STD_REDO04.LOG') size 50m,
group 5 ('/u01/app/oracle/oradata/testdb/STD_REDO05.LOG') size 50m,
group 6 ('/u01/app/oracle/oradata/testdb/STD_REDO06.LOG') size 50m,
group 7 ('/u01/app/oracle/oradata/testdb/STD_REDO07.LOG') size 50m
;
3.       生成pfile
create pfile='/home/oracle/testdb.pfile.ora' from spfile;
 
三.在备库上的操作:
1.       配置standby pfile(从主库机复制过来,并修改)
scp [email protected]:/home/oracle/testdb.pfile.ora /home/oracle/
cp testdb.pfile.ora ./standby.testdb.pfile.ora
 
修改后如后面的附件一,二
 
2.       开启listener,并开启数据库到nomount
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> create spfile from pfile='/home/oracle/standby.testdb.pfile.ora';
 
File created.
 
SQL> startup nomount
ORACLE instance started.
 
Total System Global Area 409194496 bytes
Fixed Size                   2213856 bytes
Variable Size              310380576 bytes
Database Buffers            88080384 bytes
Redo Buffers                 8519680 bytes
SQL>
SQL>
 
3.       主库lisener
 
SID_LIST_LISTENER =
 (SID_LIST =
    (SID_DESC =
      (SID_NAME = PLSExtProc)
      (ORACLE_HOME = /u01/app/oracle/product/11.2.0/dbhome_1)
      (PROGRAM = extproc)
    )
    (SID_DESC =
      (GLOBAL_DBNAME = TESTDB)
      (ORACLE_HOME = /u01/app/oracle/product/11.2.0/dbhome_1)
      (SID_NAME = TESTDB)
    )
 )
 
LISTENER =
 (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
      (ADDRESS = (PROTOCOL = TCP)(HOST = CSICN01TESTDB)(PORT = 1521))
    )
 )
4.       备库listener
SID_LIST_LISTENER =
 (SID_LIST =
    (SID_DESC =
      (SID_NAME = PLSExtProc)
      (ORACLE_HOME = /u01/app/oracle/product/11.2.0/dbhome_1)
      (PROGRAM = extproc)
    )
    (SID_DESC =
      (GLOBAL_DBNAME = TESTDB)
      (ORACLE_HOME = /u01/app/oracle/product/11.2.0/dbhome_1)
      (SID_NAME = TESTDB)
    )
 )
 
LISTENER =
 (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
      (ADDRESS = (PROTOCOL = TCP)(HOST = SAPTEST)(PORT = 1521))
    )
 )
 
ADR_BASE_LISTENER = /u01/app/oracle
 
Sqlplus sys/xxx@testdb_standby as sysdba;
报错ORA-01031: insufficient privileges 处理:
orapwd file=$ORACLE_HOME/dbs/orapwtestdb.ora  password=oracle4U entries=5;
或者
orapwd file=$ORACLE_HOME/dbs/orapwTESTDB password=oracle4U entries=5;
scp [email protected]: $ORACLE_HOME/dbs/orapwtestdb /home/oracle/
 
然后重启lsnrctl再连
注: 注意密码文件的大小写
 
四.用rman连上主库和备库,并同步数据
rman target sys/xxxxx@testdb auxiliary sys/xxxxxx@testdb_standby
duplicate target database for standby nofilenamecheck from active database;
 
五.用rman全备恢复的方式
1.       主库上
Run{
Backup full database format '/home/oracle/tmp_std/full_%U.db';
SQL 'ALTER SYSTEM ARCHIVE LOG CURRENT';
Backup archivelog all format '/home/oracle/tmp_std/arc_%U.arc';
}
 
ALTER DATABASE CREATE STANDBY CONTROLFILE AS '/home/oracle/tmp_std/standby.testdb.ctl';
 
并记下主库的id
SQL> select dbid from V$database;
 
      DBID
----------
2589250042 
2.       在备库上
scp oracle@csicn01testdb:/tmp/standby.testdb.ctl /home/oracle
 
3.       启动备库,进到rman 执行
startup force nomount pfile='/home/oracle/standby.testdb.pfile.ora';
set dbid 2589250042
restore controlfile from '/home/oracle/tmp_std/standby.testdb.ctl';
----recover database using backup controlfile until cancel;
 
alter database mount;
catalog start with '/home/oracle/tmp_std';
list backup;
low scn : 2193488
 
run{
restore database;
Switch datafile all;
recover database until SCN 2193488;
}
 
以下错可以乎略
 
RMAN> run{
restore database;
Switch datafile all;
recover database until SCN 2193488;
}
2> 3> 4> 5>
Starting restore at 25-MAR-13
using channel ORA_DISK_1
 
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of restore command at 03/25/2013 09:36:16
ORA-01013: user requested cancel of current operation
 
跳过,直接启到standby模式
SQL> shutdown immediate;
SQL> startup mount;
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;
 
六.Active Dataguard
alter database recover managed standby database using current logfile disconnect from session;
 
 
 
1. 开启standby
 
shutdown immediate;
 
startup nomount;
 
alter database mount standby database;
 
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;
 
 
 
2. 切到read only
--------------------------------------------------
 alter database recover managed standby database cancel;
 alter database open read only;
然后再开启同步
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;
 
==================对standby库做个备份======================
rman>
Run{
SQL "create pfile=''/backup/stdbak20130408/pfile.ora'' from spfile";
Backup full database format '/backup/stdbak20130408/full_%U.db';
Backup archivelog all format '/backup/stdbak20130408/arc_%U.arc';
backup as copy current controlfile format '/backup/stdbak20130408/control01.ctl';
}
注意:外面一层是一个双引号,里面一层是两个单引号
SQL "create pfile=''/backup/stdbak20130408/pfile.ora'' from spfile";
 
 
附件一
----------primary.testdb.pfile.ora---------------

testdb.__db_cache_size=92274688
testdb.__java_pool_size=4194304
testdb.__large_pool_size=4194304
testdb.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment
testdb.__pga_aggregate_target=142606336
testdb.__sga_target=268435456
testdb.__shared_io_pool_size=0
testdb.__shared_pool_size=155189248
testdb.__streams_pool_size=4194304
*.audit_file_dest='/u01/app/oracle/admin/testdb/adump'
*.audit_trail='db'
*.compatible='11.2.0.0.0'
*.control_files='/u01/app/oracle/oradata/testdb/control01.ctl','/u01/app/oracle/flash_recovery_area/testdb/control02.ctl'
*.db_block_size=8192
*.db_domain=''
*.db_name='testdb'
*.db_recovery_file_dest='/u01/app/oracle/flash_recovery_area'
*.db_recovery_file_dest_size=4070572032
*.db_unique_name='testdb'
*.diagnostic_dest='/u01/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=testdbXDB)'
*.fal_client='TESTDB'
*.fal_server='TESTDB_STANDBY'

*.log_archive_format='testdb_%t_%s_%r.arc'
*.log_archive_config='DG_CONFIG=(testdb,testdb_standby)'
*.log_archive_dest_1='LOCATION=/u01/app/oracle/flash_recovery_area VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=testdb'
*.log_archive_dest_2='SERVICE=testdb_standby lgwr sync valid_for=(online_logfile,primary_role) db_unique_name=testdb_standby'

*.log_archive_dest_state_1='ENABLE'
*.log_archive_dest_state_2='ENABLE'
*.memory_target=408944640
*.nls_language='american'
*.nls_territory='america'
*.open_cursors=300
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.standby_file_management='AUTO'
*.undo_tablespace='UNDOTBS1'
 

 

附件二:

----------standby.testdb.pfile.ora---------------------

testdb.__db_cache_size=92274688
testdb.__java_pool_size=4194304
testdb.__large_pool_size=4194304
testdb.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment
testdb.__pga_aggregate_target=142606336
testdb.__sga_target=268435456
testdb.__shared_io_pool_size=0
testdb.__shared_pool_size=155189248
testdb.__streams_pool_size=4194304
*.audit_file_dest='/u01/app/oracle/admin/testdb/adump'
*.audit_trail='db'
*.compatible='11.2.0.0.0'
*.control_files='/u01/app/oracle/oradata/testdb/control01.ctl','/u01/app/oracle/flash_recovery_area/testdb/control02.ctl'
*.db_block_size=8192
*.db_domain=''
*.db_name='testdb'
*.db_recovery_file_dest='/u01/app/oracle/flash_recovery_area'
*.db_recovery_file_dest_size=4070572032
*.db_unique_name='testdb_standby'
*.diagnostic_dest='/u01/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=testdbXDB)'
*.fal_client='TESTDB_STANDBY'
*.fal_server='TESTDB'
*.log_archive_format='testdb_%t_%s_%r.arc'
*.log_archive_config='DG_CONFIG=(testdb,testdb_standby)'
*.log_archive_dest_1='LOCATION=/u01/app/oracle/flash_recovery_area VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=testdb_standby'
*.log_archive_dest_2='SERVICE=testdb lgwr sync valid_for=(online_logfile,primary_role) db_unique_name=testdb'
*.log_archive_dest_state_1='ENABLE'
*.log_archive_dest_state_2='ENABLE'
*.log_archive_format='testdb_%t_%s_%r.arc'
*.memory_target=408944640
*.nls_language='american'
*.nls_territory='america'
*.open_cursors=300
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.service_names='testdb'
*.standby_file_management='AUTO'
*.undo_tablespace='UNDOTBS1'
 

 

----------------完------------------

你可能感兴趣的:(dataguard,oracle11gR2,实验)