通過RMAN創建dataguard(原創)
通過RMAN創建dataguard(原創)
環境介紹:數據庫版本10G,兩個節點分別是rednum1(192.168.212.128)和rednum2(192.168.212.130)
主庫主機名稱是rednum1,從庫主機名稱是rednum2
配置步驟如下:
1、在主庫和從庫配置tnsnames如下:
standbydb1 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = rednum1)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = standbydb01) (UR=A)
)
standbydb2 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = rednum2)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = standbydb02)(UR=A)
)
)
2、在主庫上配置inits
standbydb.db_cache_size=637534208
standbydb.java_pool_size=16777216
standbydb.large_pool_size=33554432
standbydb.oracle_base=‘/u01/app/oracle‘#ORACLE_BASE set from environment
standbydb.sga_target=956301312
standbydb.__shared_io_pool_size=0
standbydb.shared_pool_size=251658240
standbydb.streams_pool_size=0
.audit_file_dest=‘/u01/app/oracle/admin/standbydb/adump‘
.audit_trail=‘db‘
.compatible=‘11.2.0.4.0‘
.control_files=‘/u01/app/oracle/oradata/standbydb/control01.ctl‘,‘/u01/app/oracle/fast_recovery_area/standbydb/control02.ctl‘
.db_domain=‘‘
.db_recovery_file_dest=‘/u01/app/oracle/fast_recovery_area‘
.db_recovery_file_dest_size=5218762752
.diagnostic_dest=‘/u01/app/oracle‘
.dispatchers=‘(PROTOCOL=TCP) (SERVICE=standbydbXDB)‘
.memory_target=1600126976
.open_cursors=300
.processes=150
.remote_login_passwordfile=‘EXCLUSIVE‘
*.undo_tablespace=‘UNDOTBS1‘
########for DG
DB_NAME=standbyd
DB_UNIQUE_NAME=standbydb01
LOG_ARCHIVE_CONFIG=‘DG_CONFIG=(standbydb01,standbydb02)‘ ### DG_CONFIG必須包含DG環境中主從庫的DB_UNIQUE_NAME名稱
LOG_ARCHIVE_DEST_1=
‘LOCATION=/u01/app/backup/archlog/
VALID_FOR=(ALL_LOGFILES,ALL_ROLES)
DB_UNIQUE_NAME=standbydb01‘
LOG_ARCHIVE_DEST_2=
‘SERVICE=standbydb2 ASYNC ###service 為從庫的tnsname
VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE)
DB_UNIQUE_NAME=standbydb02‘
LOG_ARCHIVE_DEST_STATE_1=ENABLE
LOG_ARCHIVE_DEST_STATE_2=ENABLE
REMOTE_LOGIN_PASSWORDFILE=EXCLUSIVE
LOG_ARCHIVEFORMAT=%t%s_%r.arc
LOG_ARCHIVE_MAX_PROCESSES=30
fal_server=standbydb2 ###為從庫的tnsnames
STANDBY_FILE_MANAGEMENT=AUTO
3、在從庫上配置init
standbydb.db_cache_size=603979776
standbydb.java_pool_size=16777216
standbydb.large_pool_size=83886080
standbydb.oracle_base=‘/u01/app/oracle‘#ORACLE_BASE set from environment
standbydb.pga_aggregate_target=654311424
standbydb.sga_target=956301312
standbydb.__shared_io_pool_size=0
standbydb.shared_pool_size=234881024
standbydb.streams_pool_size=0
.audit_file_dest=‘/u01/app/oracle/admin/standbydb/adump‘
.audit_trail=‘db‘
.compatible=‘11.2.0.4.0‘
.control_files=‘/u01/app/oracle/oradata/standbydb/standby01.ctl‘,‘/u01/app/oracle/fast_recovery_area/standbydb/ standby01.ctl ‘
.db_block_size=8192
.db_domain=‘‘
.db_name=standbyd
.db_recovery_file_dest=‘/u01/app/oracle/fast_recovery_area‘
.db_recovery_file_dest_size=5218762752
.diagnostic_dest=‘/u01/app/oracle‘
.dispatchers=‘(PROTOCOL=TCP) (SERVICE=standbydbXDB)‘
.memory_target=1600126976
.open_cursors=300
.processes=150
.remote_login_passwordfile=‘EXCLUSIVE‘
.undo_tablespace=‘UNDOTBS1‘
######for DG
DB_UNIQUE_NAME=standbydb02
LOG_ARCHIVE_CONFIG=‘DG_CONFIG=(standbydb01,standbydb02)‘ ### DG_CONFIG必須包含DG環境中主從庫的DB_UNIQUE_NAME名稱
LOG_ARCHIVE_DEST_1=
‘LOCATION=/u01/app/backup/archlog/
VALID_FOR=(ALL_LOGFILES,ALL_ROLES)
DB_UNIQUE_NAME=standbydb02‘
LOG_ARCHIVE_DEST_2=
‘SERVICE=standbydb1 ASYNC ###service 為主庫的tnsnames
VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE)
DB_UNIQUE_NAME=standbydb01‘
LOG_ARCHIVE_DEST_STATE_1=ENABLE
LOG_ARCHIVE_DEST_STATE_2=ENABLE
REMOTE_LOGIN_PASSWORDFILE=EXCLUSIVE
LOG_ARCHIVEFORMAT=%t%s_%r.arc
LOG_ARCHIVE_MAX_PROCESSES=30
FAL_SERVER=standbydb1 ###為主庫tnsnames
STANDBY_FILE_MANAGEMENT=AUTO
4、在主庫上創建orapwd文件並傳送到從庫上
5、在主庫上創建standby控制文件,並傳送到從庫init文件指定目錄下
通過sql命令行創建
Sql>alter database create standby controlfile as ‘XXX‘;
或者通過rman創建
backup format=‘/u01/standby01.ctl‘ current controlfile for standby;
6、nomount從庫數據庫
Startup nomount pfile=‘/u01/app/oracle/product/11.2.0/dbhome_1/dbs/initstandbydb.ora‘
7、在主庫上創建RMAN CATALOG,並進行全備份
步驟1 Sql>create user rman identified by rman;
步驟2 Sql>grant recovery_catalogowner to rman;
步驟3 Rman target / catalog rman/rman
步驟4 Rman> create catalog;
步驟5 Rman> register database;
步驟6 Rman> Sql ‘ALTER SYSTEM ARCHIVE LOG CURRENT’;
步驟7 Rman> configure channel device type disk format ‘/u01/backup/Whole%d%U‘;
步驟8 Rman>backup as compressed backupset database plus archivelog delete input format=‘/u01/backup/Whole%d_%U‘ tag=‘Whole_bak‘;
通過rman 連接主庫 、catalog庫、standby數據庫如下:
步驟9 $rman target sys/manager@standbydb1 catalog rman/rman@standbydb1 AUXILIARY
步驟10 sys/manager@standbydb2
註:1)如果需要把備份文件備份至指定位置需要執行步驟7,duplicate時也是讀此目錄。否則跳過。
2)將備份文件傳遞至從庫,使從庫能訪問到備份文件.
8,創建standby數據庫
1)主從庫路徑相同
如果主庫與從庫的數據文件和在線日誌文件的路徑相同則用如下命令創建
Rman>DUPLICATE TARGET DATABASE FOR STANDBY NOFILENAMECHECK;
2) 主從庫路徑不相同
如果主庫與從庫的數據文件和在線日誌文件的路徑不相同則可用如下方法中的一種創建
2.1)在從庫init文件中配置DB_FILE_NAME_CONVERT和LOG_FILE_NAME_CONVERT,如果主庫的數據文件路徑為 +FAST ,在線日誌文件路徑為 +LOG ,從庫的數據文件路徑為 +FAST1 ,在線日誌文件路徑為 +LOG1,則參數設置為 DB_FILE_NAME_CONVERT=(’+FAST’,’+FAST1’), LOG_FILE_NAME_CONVERT=(’+LOG’,’+LOG1’);如果主庫的數據文件路徑為 /u01/data01/ ,在線日誌文件路徑為 /u01/log01/ ,從庫的數據文件路徑為 /u01/data02/ ,在線日誌文件路徑為 +LOG1,則參數設置為 DB_FILE_NAME_CONVERT=(’/u01/data01/’,’/u01/data02/’), LOG_FILE_NAME_CONVERT=(’/u01/log01/,’ /u01/log02/’);
創建standby數據庫
Rman>DUPLICATE TARGET DATABASE FOR STANDBY;
2.2)通過set newname命令
Rman>RUN
{
set new file names for the datafiles
SET NEWNAME FOR DATAFILE 1 TO ‘?/dbs/standby_data_01.f‘;
SET NEWNAME FOR DATAFILE 2 TO ‘?/dbs/standby_data_02.f‘;
.
.
.
run the DUPLICATE command
DUPLICATE TARGET DATABASE FOR STANDBY;
}
2.3) 通過CONFIGURE AUXNAME命令
Rman> CONFIGURE AUXNAME FOR DATAFILE 1 TO ‘/oracle/auxfiles/aux_1.f‘;
Rman>CONFIGURE AUXNAME FOR DATAFILE 2 TO ‘/oracle/auxfiles/aux_2.f‘;
.
.
.
Rman>CONFIGURE AUXNAME FOR DATAFILE n TO ‘/oracle/auxfiles/aux_n.f‘;
分配至少一個auxiliary通道,並進行創建,如下:
Rman>RUN
{
allocate at least one auxiliary channel of type DISK or sbt
ALLOCATE AUXILIARY CHANNEL standby1 DEVICE TYPE DISK;
.
.
.
issue the DUPLICATE command
DUPLICATE TARGET DATABASE FOR STANDBY;
}
刪除之前的配置,如下:
un-specify auxiliary names for the datafiles
Rman>CONFIGURE AUXNAME FOR DATAFILE 1 CLEAR;
Rman>CONFIGURE AUXNAME FOR DATAFILE 2 CLEAR;
.
.
.
Rman>CONFIGURE AUXNAME FOR DATAFILE n CLEAR;
通過RMAN創建dataguard(原創)