Environment:
Role
|
Machine name
|
Operating system
|
Ip
|
Note
|
Main Library
|
Db1
|
CentOS 5.11 x86_64 |
192.168.2.241
|
Install Oracle, create a database
|
Standby Library
|
Db2
|
CentOS 5.11 x86_64
|
192.168.2.242
|
Install only Oracle
|
Preparatory work:
Increased in the/etc/hosts of DB1
127.0.0.1 DB1
192.168.2.242 DB2
Increased in the/etc/hosts of DB2
127.0.0.1 DB2
192.168.2.241 DB1
Directory
Main Library Open archive and forced archive
Create 3 groups of standby Redolog
Modifying a parameter file
Modifying a listening file
Rman Backup Main Library
Copying files to a standby library
1. Open Archive and forced archive for Main library (DB1)
Check if Oracle is open for archiving
sql> archive log list;
Database log mode No Archive mode
Automatic Archival Disabled
Archive Destination Use_db_recovery_file_dest
Oldest online log sequence 6
Current Log Sequence 8
#可以看到Automatic Archival Disabled Description not open archive
Open Archive (you need to shut down Oracle before opening the archive and then boot the database to the Mount state to modify)
sql> shutdown immediate;
sql> startup Mount;
sql> ALTER DATABASE Archivelog; #打开归档
sql> ALTER DATABASE force logging; #打开强制归档也可以在数据库open状态下打开
sql> ALTER DATABASE open; #打开数据库
sql> archive log list;
Database Log Mode Archive mode
Automatic Archival Enabled
Archive Destination Use_db_recovery_file_dest
Oldest online log sequence 6
Next Log sequence to archive 8
Current Log Sequence 8
2. Create multiple sets of standby redo log, at least one more set, standby redo log is necessary for using real time apply
Sql> Select Group#,member from V$logfile;
group# member
------------------------ --------------------------------------------------------
3 /opt/oracle/ Oradata/tpy100/redo03.log
2 /opt/oracle/oradata/tpy100/redo02.log
1 /opt/oracle/oradata/tpy100/redo01.log
Sql> ALTER DATABASE add standby logfile ('/opt/oracle/oradata/tpy100/standby04.log ') size 50m;
sql> ALTER DATABASE add standby logfile ('/opt/oracle/oradata/tpy100/standby05.log ') size 50m;
sql> ALTER DATABASE add standby logfile ('/opt/oracle/oradata/tpy100/standby06.log ') size 50m;
sql> ALTER DATABASE add standby logfile ('/opt/oracle/oradata/tpy100/standby07.log ') size 50m;
Sql> Select Group#,member from V$logfile;
group# member
------------------------ --------------------------------------------------------
3 /opt/oracle/ Oradata/tpy100/redo03.log
2 /opt/oracle/oradata/tpy100/redo02.log
1 /opt/oracle/oradata/tpy100/redo01.log
4/opt/oracle/oradata/tpy100/standby04.log
5/opt/oracle/oradata/tpy100/standby05.log
6/opt/oracle/oradata/tpy100/standby06.log
7/opt/oracle/oradata/tpy100/standby07.log
3. Modify the parameter file
Before modifying the parameter file, we should make a backup
sql> create pfile= '/tmp/tpy100.pfile ' from SPFile;
Before modifying, we need to review the parameter file of the backup, change the following statement according to the specific environment
Sql> alter system set DB_UNIQUE_NAME=DB1 Scope=spfile;
Sql> alter system set log_archive_config= ' dg_config= (db1,db2) ' Scope=both;
Sql> alter system set log_archive_dest_1= ' Location=/opt/oracle/flash_recovery_area/valid_for= (All_logfiles,all_ roles) db_unique_name=db1 ' Scope=both;
Error:
ERROR at line 1:
Ora-02097:parameter cannot be modified because specified value is invalid
Ora-16053:db_unique_name DB1 is not in the Data Guard Configuration
May encounter the following error message, this time need to restart the database
sql> shutdown immediate;
Sql> Startup
Sql> alter system set log_archive_dest_1= ' Location=/opt/oracle/flash_recovery_area/valid_for= (All_logfiles,all_ roles) db_unique_name=db1 ' Scope=both;
Sql> alter system set log_archive_dest_2= ' service=db2 async valid_for= (online_logfiles,primary_role) db_unique_ Name=db2 ' Scope=both;
Sql> alter system set log_archive_dest_state_1=enable Scope=both;
Sql> alter system set log_archive_dest_state_2=enable Scope=both;
Sql> alter system set Standby_file_management=auto Scope=both;
Sql> alter system set FAL_SERVER=DB2 Scope=both;
Sql> alter system set FAL_CLIENT=DB1 Scope=both;
Sql> alter system set db_file_name_convert= '/opt/oracle/flash_recovery_area ', '/opt/oracle/flash_recovery_area ' Scope=spfile;
Sql> alter system set log_file_name_convert= '/opt/oracle/flash_recovery_area ', '/opt/oracle/flash_recovery_area ' Scope=spfile;
4. Modify the Listening file
[Email protected] ~]$ Vim/opt/oracle/product/11.2.0/network/admin/tnsnames.ora
Increase in the back
DB1 =
(DESCRIPTION =
(Address_list =
(ADDRESS = (PROTOCOL = TCP) (HOST = db1) (PORT = 1521))
)
(Connect_data =
(SERVER = dedicated)
(service_name = DB1)
)
)
DB2 =
(DESCRIPTION =
(Address_list =
(ADDRESS = (PROTOCOL = TCP) (HOST = DB2) (PORT = 1521))
)
(Connect_data =
(SERVER = dedicated)
(service_name = DB2)
)
)
5.RMAN Backup Main Library
Create a backup storage directory
[Email protected] ~]$ mkdir-p/opt/oracle/dbackup
Perform a backup
rman>run{
Allocate channel C1 type disk;
Backup format '/opt/oracle/dbackup/tpy100_%t_%s_%p ' database;
SQL ' alter system archive log current ';
Backup format '/opt/oracle/dbackup/archive_log_%t_%s_%p ' Archivelog all;
Backup spfile format '/opt/oracle/dbackup/spfile_%u_%t.bak ';
Release channel C1;
}
Rman>copy current controlfile for standby to '/opt/oracle/dbackup/standby.ctl ';
6. Copying files to the standby library
[Email protected] ~]$ scp-r/opt/oracle/dbackup/db2:/opt/oracle
[Email protected] ~]$ CD $ORACLE _home/dbs
[Email protected] dbs]$ scp-r orapwtpy100 DB2: $ORACLE _home/dbs
[Email protected] dbs]$ CD $ORACLE _home/network/admin
[Email protected] admin]$ scp-r listener.ora tnsnames.ora DB2: $ORACLE _home/network/admin
7. Recovery parameters File (DB2)
Rman> set dbid 2926260986
rman> startup Nomount;
#这里会报错不用理会即可
rman> restore SPFile to Pfile '/tmp/tpy100.pfile ' from '/opt/oracle/dbackup/spfile_04quaekm_20160219.bak ';
#我们将参数文件恢复至/tmp/tpy100.pfile, because this is the main library parameter file, the repository is slightly different
[Email protected] ~]$ Vim/tmp/tpy100.pfile
#将里面的DB1 db1 into the corresponding DB2 DB2, turning DB1 into DB1
tpy100.__db_cache_size=322961408
tpy100.__java_pool_size=4194304
tpy100.__large_pool_size=4194304
Tpy100.__oracle_base= '/opt/oracle ' #ORACLE_BASE set from environment
tpy100.__pga_aggregate_target=339738624
tpy100.__sga_target=503316480
Tpy100.__shared_io_pool_size=0
tpy100.__shared_pool_size=159383552
Tpy100.__streams_pool_size=0
*.audit_file_dest= '/opt/oracle/admin/tpy100/adump '
*.audit_trail= ' DB '
*.compatible= ' 11.2.0.0.0 '
*.control_files= '/opt/oracle/oradata/tpy100/control01.ctl ', '/opt/oracle/flash_recovery_area/tpy100/ Control02.ctl '
*.db_block_size=8192
*.db_domain= "
*.db_file_name_convert= '/opt/oracle/flash_recovery_area ', '/opt/oracle/flash_recovery_area '
*.db_name= ' tpy100 '
*.db_recovery_file_dest= '/opt/oracle/flash_recovery_area '
*.db_recovery_file_dest_size=4070572032
*.db_unique_name= ' DB2 '
*.diagnostic_dest= '/opt/oracle '
*.dispatchers= ' (protocol=tcp) (SERVICE=TPY100XDB) '
*.fal_client= ' DB2 '
*.fal_server= ' DB1 '
*.log_archive_config= ' dg_config= (db2,db1) '
*.log_archive_dest_1= ' location=/opt/oracle/flash_recovery_area/valid_for= (all_logfiles,all_roles) db_unique _name=db2 '
*.log_archive_dest_2= ' service=db1 async valid_for= (online_logfiles,primary_role) db_unique_name=db1 '
*.log_archive_dest_state_1= ' ENABLE '
*.log_archive_dest_state_2= ' ENABLE '
*.log_file_name_convert= '/opt/oracle/flash_recovery_area ', '/opt/oracle/flash_recovery_area '
*.memory_target=843055104
*.open_cursors=300
*.processes=150
*.remote_login_passwordfile= ' EXCLUSIVE '
*.standby_file_management= ' AUTO '
*.undo_tablespace= ' UNDOTBS1 '
Create the appropriate directory to start the Oracle
[Email protected] ~]$ mkdir-p/opt/oracle/admin/tpy100/adump
[Email protected] ~]$ mkdir-p/opt/oracle/oradata/tpy100
[Email protected] ~]$ mkdir-p/opt/oracle/flash_recovery_area/tpy100
[Email protected] ~]$ Cp/opt/oracle/dbackup/standby.ctl/opt/oracle/oradata/tpy100/control01.ctl
[Email protected] ~]$ Cp/opt/oracle/dbackup/standby.ctl/opt/oracle/flash_recovery_area/tpy100/control02.ctl
sql> shutdown immediate;
sql> startup Nomount pfile= '/tmp/tpy100.pfile '
Sql> create SPFile from pfile= '/tmp/tpy100.pfile ';
Sql> ALTER DATABASE Mount;
rman> Restore Database;
SQL > ALTER DATABASE open Read only;
SQL > ALTER DATABASE recover managed standby database using current logfile disconnect from session;
If you need to restart the repository, you will need to restart the command as follows
sql> startup Mount;
Sql> ALTER DATABASE open read only;
#在这里启动的时候如果出现
ERROR at line 1:
Ora-10458:standby database requires recovery
Ora-01152:file 1 was wasn't restored from a sufficiently old backup
Ora-01110:data file 1: '/OPT/ORACLE/ORADATA/TPY100/SYSTEM01.DBF '
Is the standby monitoring is not open, using lsnrctl start, start monitoring, and then open the database will not error.
sql> ALTER DATABASE recover managed standby database using current logfile disconnect from session;
The test has the following statement:
Sql> select sequence#,applied from V$archived_log;
Sql> select Process,status from V$managed_standby;
Sql> select sequence# from V$log_history;
This article is from "Maple Night" blog, please be sure to keep this source http://fengwan.blog.51cto.com/508652/1743295
Oracle 11G R2 uses Rman to build Dataguard environment