rman>backup full database format '/u01/rmanbak/port_full_backup%U.bk';
$ cd /home/oracle/product/10.2.0/
$ tar cvf /u01/oraclehomebak/product.tar db_1
sql>create pfile='/home/oracle/initport1.ora' from spfile;
ALTER DATABASE FORCE LOGGING;
ALTER SYSTEM SET DB_UNIQUE_NAME=port scope=spfile;
ALTER SYSTEM SET LOG_ARCHIVE_CONFIG='DG_CONFIG=(port,standby)' scope=both;
ALTER SYSTEM SET LOG_ARCHIVE_DEST_1='LOCATION=/home/oracle/archivelog/ VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=port' scope=both;
--当该库充当主库角色时,设置物理备库redo data的传输目的地
ALTER SYSTEM SET LOG_ARCHIVE_DEST_2='SERVICE=standby LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=standby' scope=spfile;
--许redo传输服务传输数据到目的地,默认是enable
ALTER SYSTEM SET LOG_ARCHIVE_DEST_STATE_1=ENABLE scope=spfile;
ALTER SYSTEM SET LOG_ARCHIVE_DEST_STATE_2=ENABLE scope=spfile;
--exclusive or shared,所有库sys密码要一致,默认是exclusive
ALTER SYSTEM SET REMOTE_LOGIN_PASSWORDFILE=EXCLUSIVE scope=spfile;
ALTER SYSTEM SET LOG_ARCHIVE_FORMAT='%t_%s_%r.arc' scope=spfile;
ALTER SYSTEM SET LOG_ARCHIVE_MAX_PROCESSES=4 scope=spfile;
--配置网络服务名,fal_server拷贝丢失的归档文件到这里
ALTER SYSTEM SET FAL_CLIENT=port SCOPE=SPFILE;
--配置网络服务名,假如转换为备库角色时,从这里获取丢失的归档文件
ALTER SYSTEM SET FAL_SERVER=STANDBY SCOPE=SPFILE;
--auto后当主库的datafiles增删时备库也同样自动操作,且会把日志传送到备库standby_archive_dest参数指定的目录下,
--确保该目录存在,如果你的存储采用文件系统没有问题,但是如果采用了裸设备,你就必须将该参数设置为manual
ALTER SYSTEM SET STANDBY_FILE_MANAGEMENT=AUTO SCOPE=SPFILE;--前为切换后的主库路径,后为切换后的备库路径,如果主备库目录结构完全一样,则无需设定
ALTER SYSTEM SET DB_FILE_NAME_CONVERT='/u01/oracle/oradata/port/','/u01/oracle/oradata/port/' SCOPE=SPFILE;
--同上,这两个名字转换参数是主备库的路径映射关系,可能会是路径全名,看情况而定
ALTER SYSTEM SET LOG_FILE_NAME_CONVERT='/u01/oracle/oradata/port/','/u01/oracle/oradata/port/' SCOPE=SPFILE;
--一般和LOG_ARCHIVE_DEST_1的位置一样,如果备库采用ARCH传输方式,那么主库会把归档日志传到该目录下
ALTER SYSTEM SET STANDBY_ARCHIVE_DEST='/home/oracle/archivelog/' scope=spfile;
(ADDRESS = (PROTOCOL = TCP)(HOST =172.16.3.56)(PORT = 1521))
allocate channel c1 device type disk format '/u01/rmanbak/forstandby/%U' connect sys/password@port;
SQL>alter database create standby controlfile as '/u01/rmanbak/forstandby/ctl/controlfile.ctl';
allocate channel c1 device type disk format '/u01/rmanbak/forstandby/ctl/CON_%U';
backup current controlfile for standby;
6、如果主库没有密码文件则建立密码文件,从而可以OS验证的方式登陆
$ orapwd file=$ORACLE_HOME/dbs/orapw$ORACLE_SID password=iamwangnc entries=5
cd /home/oracle/product/10.2.0/db_1/dbs
cd /home/oracle/product/10.2.0/db_1/dbs/
-bash-3.2$ scp -r root@172.16.3.46:/home/oracle/product/10.2.0/db_1/dbs/orapwport /home/oracle/product/10.2.0/db_1/dbs/orapwport
root@172.16.3.46's password:orapwport 100% 1536 1.5KB/s 00:00 -bash-3.2$
orapwd file=orapwport password=oracle entries=5(未执行)
/home/oracle/admin/port/adump
/home/oracle/admin/port/bdump
/home/oracle/admin/port/cdump
/home/oracle/admin/port/udump
3、配置tnsnames.ora和listener.ora
############################################# tnsnames.ora文件
#############################################port =
(ADDRESS = (PROTOCOL = TCP)(HOST = 172.16.3.46)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST =172.16.3.56)(PORT = 1521))
(ORACLE_HOME = /home/oracle/product/10.2.0/db_1)
(GLOBAL_DBNAME = standby)
(ORACLE_HOME = /home/oracle/product/10.2.0/db_1)
(ADDRESS = (PROTOCOL = TCP)(HOST = 172.16.3.56)(PORT = 1521))
5、修改参数文件/home/oracle/product/10.2.0/db_1/dbs/initport.ora
create pfile = '/home/oracle/product/10.2.0/db_1/dbs/initport.ora' from spfile;
*.audit_file_dest='/home/oracle/admin/port/adump'
*.background_dump_dest='/home/oracle/admin/port/bdump'
*.core_dump_dest='/home/oracle/admin/port/cdump'
*.user_dump_dest='/home/oracle/admin/port/udump'
*.compatible='10.2.0.4.0'
*.control_files='/u01/oracle/oradata/port/control01.ctl','/u01/oracle/oradata/port/control02.ctl','/u01/oracle/oradata/port/control03.ctl'
*.db_file_multiblock_read_count=32
*.db_unique_name='standby'
*.fal_client='STANDBY'*.fal_server='port'
*.log_archive_config='DG_CONFIG=(port,standby)'
*.log_archive_dest_1='LOCATION=/home/oracle/archivelog valid_for=(all_logfiles,all_roles) db_unique_name=standby'
*.log_archive_dest_2='service=port lgwr async valid_for=(online_logfiles,primary_role) db_unique_name=port'
*.log_archive_dest_state_1='ENABLE'
*.log_archive_dest_state_2='ENABLE'
*.log_archive_max_processes=4
*.log_file_name_convert='/u01/oracle/oradata/port/','/u01/oracle/oradata/port/'
*.db_file_name_convert='/u01/oracle/oradata/port/','/u01/oracle/oradata/port/'
*.pga_aggregate_target=1092957696
*.remote_login_passwordfile='EXCLUSIVE'
*.sga_max_size=4589934592
*.standby_file_management='AUTO'
*.undo_tablespace='UNDOTBS1'
startup nomount pfile='/home/oracle/product/10.2.0/db_1/dbs/initport.ora';
7、从主库拷贝备份到备库上--注意rman备份的文件在主备库主机上目录要一致
scp -r root@172.16.3.46:/u01/rmanbak/forstandby/ /u01/rmanbak/forstandby/
rman target / auxiliary sys/password@standby
duplicate target database for standby nofilenamecheck;
allocate channel c1 device type disk format '/u01/rmanbak/forstandby/%U' connect sys/password@port;
allocate auxiliary channel ac1 device type disk format '/u01/rmanbak/forstandby/%U';duplicate target database for standby;
如果新创建备库的数据库文件路径名称和主库一样,oracle为了避免错误的覆盖,会抛出RMAN-05001错误,
需要先执行如下语句即可成功,不做数据库文件的名称正确性检查
RMAN>duplicate target database for standby nofilenamecheck;
alter database recover managed standby database disconnect from session;
alter database recover managed standby database cancel;
ALTER DATABASE ADD STANDBY LOGFILE group 4 ('/u01/oracle/oradata/port/redo04.log') SIZE 50M;
ALTER DATABASE ADD STANDBY LOGFILE group 5 ('/u01/oracle/oradata/port/redo05.log') SIZE 50M;
ALTER DATABASE ADD STANDBY LOGFILE group 6 ('/u01/oracle/oradata/port/redo06.log') SIZE 50M;
ALTER DATABASE ADD STANDBY LOGFILE group 7 ('/u01/oracle/oradata/port/redo07.log') SIZE 50M;
standby redolog的组数参考公式:(online redolog组数 + 1) * 数据库线程数;单机线程数为1,RAC一般为2。
standby redolog的组成员数和大小也尽量和online redolog一样。
alter database recover managed standby database disconnect from session;
select sequence#,applied from v$archived_log ;
create table test as select * from dba_users;
insert into test select * from test;
alter system switch logfile;
recover managed standby database cancel;
若在实施过程中出现故障,并会影响到业务的情况,就执行回退机制。具体的操作如下:
alter database archivelog;
alter database no force logging;
本文转自zylhsy 51CTO博客,原文链接:http://blog.51cto.com/yunlongzheng/775195,如需转载请自行联系原作者