三、配置备库
创建catalog数据库
用dbca创建数据库,用oracle自带模板,不用em,启用归档,同一管理密码oracle,global name:dbcat1.node249.gewara,实例名:dbcat1
$export $ORACLE_SID=dbcat1
$sqlplus / as sysdba
SQL>create tablespace tbs_rman datafile '/u01/app/oracle/oradata/dbtest/tbs_rman01.dbf' size 500m autoextned on next 1m extent management local;
SQL>create user rman identified by rman default tablespace tbs_rman temporary tablespace temp;
SQL>grant connect,resource,recovery_catalog_owner to rman;
SQL>conn rman/rman
SQL>show user
创建catalog
$rman
RMAN>connect catalog rman/rman@dbcat1;
RMAN>create catalog;
创建密码文件,或者直接将主库的密码文件复制过来,放在$ORACLE_HOME/dbs/下,更改文件属住为oracle:oinstall
orapwd file=$ORACLE_HOME/dbs/orapwdbtest password=oracle entries=10
配置TNS,修改$ORACLE_HOME/netword/admin/tnsnames.ora
DBCAT1 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.2.249)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = dbcat1)
)
)
DBPRIMARY =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.2.248)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = dbtest.node248.gewara)
(SID=dbtest)
)
)
DBSTANDBY =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.2.249)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = dbtest.node249.gewara)
)
)
配置监听
修改$ORACLE_HOME/network/admin/listener.ora
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = PLSExtProc)
(ORACLE_HOME = /u01/app/oracle/products/11.2/db_1)
(PROGRAM = extproc)
)
(SID_DESC =
(GLOBAL_DBNAME = dbtest.node249.gewara)
(ORACLE_HOME = /u01/app/oracle/products/11.2/db_1)
(SID_NAME = dbtest)
)
(SID_DESC =
(GLOBAL_DBNAME = dbcat1)
(ORACLE_HOME = /u01/app/oracle/products/11.2/db_1)
(SID_NAME = dbcat1)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST =192.168.2.249)( PORT = 1521))
)
)
ADR_BASE_LISTENER = /u01/app/oracle
启动监听
$lsnrctl start
?测试tns是否配置成功
$tnsping dbprimary
$tnsping dbstandby
$tnsping dbcat1
为备库准备pfile
可以把之前为主库准备的pfile拷贝到node249上,做相应修改
# /tmp/initdbtest.ora
dbtest.__db_cache_size=671088640
dbtest.__java_pool_size=16777216
dbtest.__large_pool_size=16777216
dbtest.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment
dbtest.__pga_aggregate_target=671088640
dbtest.__sga_target=973078528
dbtest.__shared_io_pool_size=0
dbtest.__shared_pool_size=251658240
dbtest.__streams_pool_size=0
*.audit_file_dest='/u01/app/oracle/admin/dbtest/adump'
*.audit_trail='db'
*.compatible='11.2.0.0.0'
*.control_files='/u01/app/oracle/oradata/dbtest/control01.ctl','/u01/app/oracle/flash_recovery_area/dbtest/control02.ctl'
*.db_block_size=8192
*.db_domain='node249.gewara'
*.db_name='dbtest'
*.db_recovery_file_dest='/u01/app/oracle/flash_recovery_area'
*.db_recovery_file_dest_size=4070572032
*.diagnostic_dest='/u01/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=dbtestXDB)'
*.memory_target=1639972864
*.open_cursors=300
*.processes=150
*.undo_tablespace='UNDOTBS1'
*.DB_UNIQUE_NAME='db249'
*.FAL_CLIENT='dbstandby'
*.FAL_SERVER='dbprimary'
*.LOG_ARCHIVE_CONFIG='DG_CONFIG=(db248,db249)'
*.log_archive_dest_1='LOCATION=/u01/app/oracle/archive/
VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=db249' #这里的DB_UNIQUE_NAME为备库的DB_UNIQUE_NAME
*.LOG_ARCHIVE_DEST_2='SERVICE=dbprimary LGWR ASYNC
VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=db248'
*.LOG_ARCHIVE_DEST_STATE_1='ENABLE'
*.LOG_ARCHIVE_DEST_STATE_2='ENABLE'
*.LOG_ARCHIVE_FORMAT='%t_%s_%r.arc'
*.remote_login_passwordfile='EXCLUSIVE'
*.standby_file_management='AUTO'
按照pfile中指定的目录,在oracle用户下,用mkdir –p 命令,创建所有需要的文件夹,保证所有目录的属主为oracle:oinstall.
启动备库到nomount状态:
$export ORACLE_SID=dbtest
$echo $ORACLE_SID
$sqlplus / as sysdba
SQL>startup nomount pfile='/tmp/initdbtest.ora'
启动rman,用duplicate命令,建立备库
$rman
RMAN>connect catalog rman/rman@dbcat1
RMAN>connect target sys/oracle@dbprimary
RMAN>connect auxiliary sys/oracle@dbstandby
RMAN>register database;
RMAN>duplicate target database for standby from active database nofilenamecheck;
四、添加standby logfile
主库:
SQL>alter database add standby logfile group 4 ('/u01/app/oracle/oradata/dbtest/stdy_redo04.log') size 10m;
SQL>alter database add standby logfile group 5 ('/u01/app/oracle/oradata/dbtest/stdy_redo05.log') size 10m;
SQL>alter database add standby logfile group 6 ('/u01/app/oracle/oradata/dbtest/stdy_redo06.log') size 10m;
SQL>alter database add standby logfile group 7 ('/u01/app/oracle/oradata/dbtest/stdy_redo07.log') size 10m;
备库:
SQL>alter database add standby logfile group 4 ('/u01/app/oracle/oradata/dbtest/stdy_redo04.log') size 10m;
SQL>alter database add standby logfile group 5 ('/u01/app/oracle/oradata/dbtest/stdy_redo05.log') size 10m;
SQL>alter database add standby logfile group 6 ('/u01/app/oracle/oradata/dbtest/stdy_redo06.log') size 10m;
SQL>alter database add standby logfile group 7 ('/u01/app/oracle/oradata/dbtest/stdy_redo07.log') size 10m;
SQL>shutdown immediate
SQL>startup nomount;
SQL>alter database mount standby database;
五、datagurad管理
启用dataguard
SQL>startup nomount;
SQL>alter database mount standby database;
SQL>alter database recover managed standby database disconnect from session;
切换为readonly状态
SQL>alter database recover managed standby database concel;
SQL>alter database open read only;
SQL>select * from dual;
主备切换:
主库端:
SQL>alter database commit to switchover to physical standby database with session shutdown;
SQL>shutdown immediate;
SQL>startup nomount;
SQL>alter database mount standby database;
SQL>alter database recover managed standby database disconnect from session;
备库端:
SQL>alter database commit to switchover to primary with session shutdown;
SQL>shutdown immediate
SQL>startup
trouble shooting:
ora-00845:
$su – root
#mount –t tmpfs shmfs –o size=3g /dev/shm