一。说明:
本次DataGuard配置的环境是102050,操作系统为Oracle linux6.3,DG为单实例到单实例。初始同步用的是rman的duplicate主库:
hostname:db10h1
db_unique_name: tan01
ip: 192.168.20.246
备库:
hostname:db10h2
db_unique_name: tan021
ip: 192.168.20.247
二。源端配置:
1.必要的参数修改:SQL> ALTER DATABASE FORCE LOGGING;
查看主库当前是否为force logging:
SQL> select force_logging from v$database;
SQL> ALTER SYSTEM SET LOG_ARCHIVE_CONFIG = 'DG_CONFIG=(tan01,tan02)' scope=both;
SQL>ALTER SYSTEM SET LOG_ARCHIVE_DEST_1 = 'LOCATION=/u01/arch1/ VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=tan01';
SQL>ALTER SYSTEM SET LOG_ARCHIVE_DEST_2 = 'SERVICE=tan02 LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) db_unique_name=tan02' scope=both;
SQL> alter system set log_archive_format= '%t_%s_%r.arc' scope=spfile;
SQL> alter system set standby_file_management=auto;
-- standby_file_management=auto:主库有表空间变动时,能够自动同步到备库。
2.开启归档:
SQL> shutdown immediate
SQL> startup mount;
SQL> alter database archivelog;
SQL> alter database open;
3.静态监听:
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 0.0.0.0)(PORT = 1521))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
)
SID_LIST_LISTENER=
(SID_LIST=
(SID_DESC=
(GLOBAL_DBNAME=tan01)
(SID_NAME=tan01)
(ORACLE_HOME=/apps/oracle/product/10.2.0/db_1)
)
)
[oracle@db10h1 ~]$ lsnrctl start
4.网络连接tnsnames.ora
tan01 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST =db10h1)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = tan01)
)
)
tan02 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(host = db10h2)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(service_name = tan02)
)
)
5.REDO信息查询:
SQL>select group#,member from V$logfile;
3 /apps/oradata/tan01/redo03.log
2 /apps/oradata/tan01/redo02.log
1 /apps/oradata/tan01/redo01.log
SQL> select group#,thread#,bytes from V$log;
GROUP# THREAD# BYTES
---------- ---------- ----------
1 1 52428800
2 1 52428800
3 1 52428800
6.添加standby REDO:
alter database add standby logfile thread 1 group 4 ('/apps/oradata/tan01/s_redo04.log') size 50m;
alter database add standby logfile thread 1 group 5 ('/apps/oradata/tan01/s_redo05.log') size 50m;
alter database add standby logfile thread 1 group 6 ('/apps/oradata/tan01/s_redo06.log') size 50m;
alter database add standby logfile thread 1 group 7 ('/apps/oradata/tan01/s_redo07.log') size 50m;
7.查询standby REDO:
SQL> select group#,thread#,bytes/1024/1024 MB,status,used from V$standby_log;
GROUP# THREAD# MB STATUS USED
---------- ---------- ---------- ---------- ----------
4 1 50 UNASSIGNED 512
5 1 50 UNASSIGNED 512
6 1 50 UNASSIGNED 512
7 1 50 UNASSIGNED 512
8.为备库的参数文件做准备:
SQL> create pfile='/tmp/inittan01.ora' from spfile;
9.为备库用rman备份数据库
[oracle@db10h1 ~]$ rman target sys/oracle@tan01
CROSSCHECK BACKUP;
delete noprompt expired backup;
crosscheck archivelog all;
delete noprompt expired archivelog all;
run
{
backup as compressed backupset
database
include current controlfile
format '/u01/backup/db_%d_%T_%U';
}
10.为备库创建控制文件:
SQL> alter database create standby controlfile as '/apps/oradata/tan02/control01.ctl';
三。目标端备库配置
1.创建必要的目录:
[root@db10h2 ~]# mkdir -p /u01/arch1/
[root@db10h2 ~]# mkdir -p /u01/backup
[root@db10h2 ~]# chown -R oracle:oinstall /u01
[oracle@db10h2 dbs]$ mkdir -p /apps/admin/tan02/adump
[oracle@db10h2 dbs]$ mkdir -p /apps/admin/tan02/bdump
[oracle@db10h2 dbs]$ mkdir -p /apps/oradata/tan02/
[oracle@db10h2 dbs]$ mkdir -p /apps/admin/tan02/cdump
[oracle@db10h2 dbs]$ mkdir -p /apps/admin/tan02/udump
2.传输必要的文件:
[oracle@db10h2 dbs]$ pwd
/apps/oracle/product/10.2.0/db_1/dbs
[oracle@db10h2 dbs]$ scp oracle@db10h1:/tmp/inittan01.ora ./
[oracle@db10h2 dbs]$ scp oracle@db10h1:/apps/oracle/product/10.2.0/db_1/dbs/orapwtan01 ./
[oracle@db10h2 tan02]$ scp oracle@db10h1:/u01/backup/* /u01/backup/
[oracle@db10h2 ~]$ scp oracle@db10h1:/apps/oradata/tan02/control01.ctl /apps/oradata/tan02/control01.ctl
3.修改inittan01.ora
主要修改以下几个参数:
db_name
db_unique_name
control_files
log_archive_dest_1
log_archive_dest_2
log_archive_config
db_file_name_convert
log_file_name_convert
具体如下:
[oracle@db10h2 dbs]$ vi inittan01.ora
*.audit_file_dest='/apps/admin/tan02/adump'
*.background_dump_dest='/apps/admin/tan02/bdump'
*.compatible='10.2.0.5.0'
*.control_files='/apps/oradata/tan02/control01.ctl'
*.core_dump_dest='/apps/admin/tan02/cdump'
*.db_block_size=8192
*.db_domain=''
*.db_file_multiblock_read_count=16
*.db_name='tan01'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=tan02XDB)'
*.job_queue_processes=10
*.log_archive_dest_1='LOCATION=/u01/arch1/ VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=tan02'
*.log_archive_dest_2='SERVICE=tan01 ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) db_unique_name=tan01'
*.log_archive_format='%t_%s_%r.arc'
*.open_cursors=300
*.pga_aggregate_target=67108864
*.processes=600
*.remote_login_passwordfile='EXCLUSIVE'
*.sessions=665
*.sga_target=203423744
*.standby_file_management='AUTO'
*.undo_management='AUTO'
*.undo_tablespace='UNDOTBS1'
*.user_dump_dest='/apps/admin/tan02/udump'
db_unique_name=tan02
log_archive_config='DG_CONFIG=(tan01,tan02)'
db_file_name_convert='tan01','tan02'
log_file_name_convert='tan01','tan02'
4.静态监听:
[oracle@db10h2 admin]$ vi listener.ora
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 0.0.0.0)(PORT = 1521))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
)
SID_LIST_LISTENER=
(SID_LIST=
(SID_DESC=
(GLOBAL_DBNAME=tan02)
(SID_NAME=tan01)
(ORACLE_HOME=/apps/oracle/product/10.2.0/db_1)
)
)
[oracle@db10h2 ~]$ lsnrctl start
5.网络连接tnsnames
[oracle@db10h2 admin]$ vi tnsnames.ora
tan01 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST =db10h1)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = tan01)
)
)
tan02 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(host = db10h2)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(service_name = tan02)
)
)
6.将备库启动到nomount:
SQL> startup nomount;
7.用rman初始化备库:
[oracle@db10h2 ~]$ rman target sys/oracle@tan01 auxiliary sys/oracle@tan02
RMAN> duplicate target database for standby ;
8.开启redo apply
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE disconnect from session;
至此DataGuard配置完成
四。其他查询:
SQL> select SWITCHOVER_STATUS,PROTECTION_MODE, DATABASE_ROLE,open_mode from V$database;
SWITCHOVER_STATUS PROTECTION_MODE DATABASE_ROLE OPEN_MODE
-------------------- -------------------- ---------------- ----------
SESSIONS ACTIVE MAXIMUM PERFORMANCE PHYSICAL STANDBY MOUNTED
SQL> select sequence#,applied from V$archived_log order by sequence#;
SEQUENCE# APP
---------- ---
5 YES
6 YES
7 YES
8 YES
9 YES