虛擬機器上單個linux 搭建standby

Nalternative發表於2011-07-05

[root@oracle standby]# mkdir /standby
[root@oracle standby]# mkdir /standby/bdump
[root@oracle standby]# mkdir /standby/udump
[root@oracle standby]# mkdir /standby/archive
[root@oracle standby]# mkdir /standby/oradata/standby
[root@oracle standby]# chown -R oracle:oinstall /standby
--1、enable force logging
SQL> alter database force logging;

Database altered.

--2、create a password file
$ orapwd file=orapwstandby password=zja entries=30

--3、configure a standby redo log

SQL> alter database add standby logfile group 4('/standby/oradata/standby/standby02.log') size 20M;
SQL> alter database add standby logfile group 5('/standby/oradata/standby/standby01.log') size 20M;
SQL> alter database add standby logfile group 6('/standby/oradata/standby/standby03.log') size 20M;

--4、Set Primary Database Initialization Parameters

create pfile from spfile

*.db_unique_name='orcl'
*.log_archive_dest_1='location=/oracle/flash_recovery_area/ORCL/archivelog/
  valid_for=(all_logfiles,all_roles) db_unique_name=orcl'
*.log_archive_dest_2='SERVICE=standby
  valid_for=(online_logfiles,primary_role) db_unique_name=standby'
*.standby_file_management=AUTO
*.log_archive_config='dg_config=(orcl,standby)'
*.fal_server=standby
*.fal_client=orcl


shutdown immediate

create spfile from pfile='/oracle/10g/dbs/initorcl.ora';
startup

--建立備用資料庫
create pfile='/oracle/10g/dbs/initstandby.ora' from spfile;

--修改備用引數檔案
sed -e 's/oracle/standby/g' -e 's/orcl/standby/g'  initstandby.ora >initstandby.ora.2

*.service_names='standby'
*.instance_name='standby'
*.log_archive_dest_1='location=/standby/flash_recovery_area/standby/archivelog/
  valid_for=(all_logfiles,all_roles) db_unique_name=standby'
*.log_archive_dest_2='SERVICE=orcl
  valid_for=(online_logfiles,primary_role) db_unique_name=orcl'
*.db_file_name_convert='/oracle/oradata/orcl/','/standby/oradata/standby/'
*.log_file_name_convert='/oracle/oradata/orcl/','/standby/oradata/standby/'
*.log_archive_config='dg_config=(orcl,standby)'

*.standby_archive_dest='/standby/flash_recovery_area/standby/archivelog/'


--建立伺服器引數檔案

create spfile='/oracle/10g/dbs/spfilestandby.ora' from pfile='/oracle/10g/dbs/initstandby.ora';

SQL>  startup force nomount
ORACLE instance started.

Total System Global Area  285212672 bytes
Fixed Size                  1218992 bytes
Variable Size             104859216 bytes
Database Buffers          176160768 bytes
Redo Buffers                2973696 bytes

SQL> select instance_name from v$instance;

INSTANCE_NAME
----------------
standby

--建立備份
[root@oracle /]# mkdir /backup
[root@oracle /]# chown -R oracle:oinstall /backup
[root@oracle /]# su - oracle
[oracle@oracle ~]$ cd /backup
[oracle@oracle backup]$ rman target  sys/***@orcl   nocatalog

Recovery Manager: Release 10.2.0.1.0 - Production on Sat Jul 2 10:09:49 2011
....................
..........

 


RMAN> backup database plus archivelog format='/backup/%d_%s.bak';


Starting backup at 02-JUL-11
....................
..........


RMAN> backup current controlfile for standby format='/backup/%d_%s.bak';

Starting backup at 02-JUL-11
....................
..........


---配置監聽、域名伺服器

 

 

shutdown immediate
startup mount

alter database create standby controlfile as '/standby/oradata/standby/control01.ctl';
alter database create standby controlfile as '/standby/oradata/standby/control02.ctl';
alter database create standby controlfile as '/standby/oradata/standby/control03.ctl';
alter database open

 

---複製資料庫
[oracle@oracle ~]$ export ORACLE_SID=standby
[oracle@oracle ~]$  rman target sys/zja@orcl auxiliary sys/zja


xhost local:oracle non-network local connections being added to access control list

 

RMAN> duplicate target database for standby dorecover; 

 

--主庫執行:
SQL> alter system switch logfile;

System altered.
--備庫執行:
SQL> select name from v$archived_log;


SQL> conn sys/zja@standby as sysdba
Connected.
SQL> conn sys/zja@orcl as sysdba
Connected.
SQL> alter system switch logfile;

System altered.

SQL> conn sys/zja@standby as sysdba
Connected.
SQL> select name from v$archived_log;

NAME
--------------------------------------------------------------------------------
/standby/flash_recovery_area/standby/archivelog/1_18_751041176.dbf
/standby/flash_recovery_area/standby/archivelog/1_19_751041176.dbf
/standby/flash_recovery_area/standby/archivelog/1_20_751041176.dbf
/standby/flash_recovery_area/standby/archivelog/1_21_751041176.dbf
/standby/flash_recovery_area/standby/archivelog/1_22_751041176.dbf

--測試

create user edu identified by jyedu;

conn edu/jyedu@orcl
conn edu/jyedu@standby

conn jason/marcus@orcl
conn jason/marcus@standby

--啟動redo應用
alter database recover managed standby database disconnect from session;

select max(sequence#) from v$archived_log;

 

--檔案顯示末尾行

netca

netmgr


問題:
1----------
ORA-01103: database name 'ORCL' in control file is not 'STANDBY'

修改 dbname,dbname 需一致,但例項名可以不一致.

2-----------
$ORACLE_HOME/dbs
下面存放密碼檔案 orapw 可以用來共享

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/25323853/viewspace-701382/,如需轉載,請註明出處,否則將追究法律責任。

相關文章