一、备份
1、数据备份(主库上执行)
rman>backup full database format '/u01/rmanbak/port_full_backup%U.bk';
2、数据库软件备份(主库上执行)
$ cd /home/Oracle/product/10.2.0/
$ tar cvf /u01/oraclehomebak/product.tar db_1
3、数据库参数备份(主库上执行)
sqlplus "/as sysdba"
sql>create pfile='/home/oracle/initport1.ora' from spfile;
二、主库实施(阶段一)
1、参数修改
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;
2、重启主库
shutdown immediate;
startup;
3、主库的tnsnames.ora添加内容
STANDBY =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST =172.16.3.56)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = standby)
)
)
4、备份数据库
run{
allocate channel c1 device type disk format '/u01/rmanbak/forstandby/%U' connect sys/password@port;
backup database;
backup archivelog all;
}
5、生成备库控制文件
方法一:
SQL>alter database create standby controlfile as '/u01/rmanbak/forstandby/ctl/controlfile.ctl';
方法二:
run{
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