oracle-11g-配置dataguard

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了oracle-11g-配置dataguard相关的知识,希望对你有一定的参考价值。

1、环境信息:
系统:
oracle-linux 5.7

数据库版本:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
PL/SQL Release 11.2.0.3.0 - Production
CORE 11.2.0.3.0 Production
TNS for Linux: Version 11.2.0.3.0 - Production
NLSRTL Version 11.2.0.3.0 - Production

主库:192.168.12.31 SID:yoon db_unique_name:yoon 
备库:192.168.12.231 SID:yoon db_unique_name:yoondg

 

2、查看DG是否已经安装:
SQL> select * from v$option where parameter = ‘Oracle Data Guard‘;
PARAMETER VALUE
-------------------- --------------------
Oracle Data Guard TRUE
TRUE表示已经安装可以配置,否则需要安装相应软件

 

3、查看主库是否开启归档:
SQL> archive log list;
Database log mode No Archive Mode
Automatic archival Disabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 4
Current log sequence 6

 

4、设置主库为归档模式:
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.

SQL> startup mount
ORACLE instance started.

Total System Global Area 2505338880 bytes
Fixed Size 2230952 bytes
Variable Size 553649496 bytes
Database Buffers 1946157056 bytes
Redo Buffers 3301376 bytes
Database mounted.

SQL> alter database archivelog;

Database altered.

SQL> alter database open;

Database altered.

SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 4
Next log sequence to archive 6
Current log sequence 6

 

5、设置主库为强制记录日志:
SQL> alter database force logging;

Database altered.

 

6、创建standy log files:
SQL> select group#,member from v$logfile;

GROUP# MEMBER
------- -----------------------------------
3 /opt/oracle/oradata/yoon/redo03.log
2 /opt/oracle/oradata/yoon/redo02.log
1 /opt/oracle/oradata/yoon/redo01.log
添加:
SQL> alter database add standby logfile group 7 ‘/opt/oracle/oradata/yoon/standby07.log‘ size 50m;

Database altered.

SQL> alter database add standby logfile group 8 ‘/opt/oracle/oradata/yoon/standby08.log‘ size 50m;

Database altered.

SQL> alter database add standby logfile group 9 ‘/opt/oracle/oradata/yoon/standby09.log‘ size 50m;

Database altered.

SQL> alter database add standby logfile group 10 ‘/opt/oracle/oradata/yoon/standby10.log‘ size 50m;

Database altered.

 

7、创建standby控制文件:
SQL> shutdown immediate

SQL> startup mount

SQL> alter database create standby controlfile as ‘/opt/oracle/oradata/yoon/standby_control01.ctl‘;

Database altered.

SQL>alter database open;

 

8、设置db_unique_name:
默认db_name和db_unique_name是一样的,主库是yoon
在配置DG中主库和备库的SID可以一样,But,db_unique_name不能相同,备库设置为:yoondg
SQL> show parameter db_unique_name;

NAME TYPE VALUE
------------------------------------ ---------- ------------------------------
db_unique_name string yoon

--注意虽然默认db_unique_name和db_name是一致的,但是需要显式设置,否则在spfile中没有此参数
SQL> alter system set db_unique_name=yoon scope=spfile;

System altered.

 

9、配置主库listener.ora:
# listener.ora Network Configuration File: /opt/oracle/product/11.2.0/db_1/network/admin/listener.ora
# Generated by Oracle configuration tools.

SID_LIST_LISTENER=
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = yoon)
(ORACLE_HOME = /opt/oracle/product/11.2.0/db_1/)
(SID_NAME = yoon)
)
)


LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.12.31)(PORT = 1521))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
)

ADR_BASE_LISTENER = /opt/oracle

配置tnsnames.ora
# listener.ora Network Configuration File: /opt/oracle/product/11.2.0/db_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.


YOON =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.12.31)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = yoon)
)
)

YOONDG =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.12.231)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = yoondg)
)
)

10、将主库listener.ora和tnsnames.ora拷贝到备库修改
[[email protected] admin]# scp listener.ora tnsnames.ora [email protected]:/opt/oracle/product/11.2.0/db_1/network/admin/ 
配置listener.ora
# listener.ora Network Configuration File: /opt/oracle/product/11.2.0/db_1/network/admin/listener.ora
# Generated by Oracle configuration tools.

 

SID_LIST_LISTENER=
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = yoon)
(ORACLE_HOME = /opt/oracle/product/11.2.0/db_1/)
(SID_NAME = yoon)
)
)

 


LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.12.231)(PORT = 1521))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
)

ADR_BASE_LISTENER = /opt/oracle

配置tnsnames.ora
# listener.ora Network Configuration File: /opt/oracle/product/11.2.0/db_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.

YOONDG =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.12.231)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = yoondg)
)
)

YOON =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.12.31)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = yoon)
)
)

11、配置完以后在主和备的oralce用户下测试下是否能ping通
主:
[[email protected] ~]$ tnsping yoon
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.12.31)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = yoon)))
OK (0 msec)

[[email protected] ~]$ tnsping yoondg
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.12.231)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = yoondg)))
OK (10 msec)

备:
[[email protected] ~]$ tnsping yoon
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.12.31)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = yoon)))
OK (0 msec)

[[email protected] ~]$ tnsping yoondg
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.12.231)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = yoondg)))
OK (0 msec)

 

12、重做日志传输配置
a.配置归档日志位置:
SQL> alter system set log_archive_dest_1=‘location=/opt/oracle/archive_bak valid_for=(all_logfiles,primary_roles) db_unique_name=yoon‘ scope=spfile;

System altered.

b.配置重做日志到备份库:
SQL> alter system set log_archive_dest_2=‘service=yoondg lgwr sync valid_for=(online_logfiles,primary_role) db_unique_name=yoondg‘ scope=spfile;

System altered.

 

13、配置FAL_SERVER
主:
SQL> alter system set fal_server=‘yoondg‘;

System altered.

 

14、Data Guard 配置里的另外一个库的名字
SQL> alter system set log_archive_config=‘dg_config=(yoon,yoondg)‘;

System altered.

SQL> alter system set log_archive_dest_state_1=enable scope=spfile;

System altered.

SQL> alter system set log_archive_dest_state_2=enable scope=spfile;

System altered.

SQL> create pfile from spfile;

File created.

SQL> create spfile from pfile;

File created.

 

15、查看主库inityoon.ora信息
yoon.__db_cache_size=1946157056
yoon.__java_pool_size=16777216
yoon.__large_pool_size=16777216
yoon.__oracle_base=‘/opt/oracle‘#ORACLE_BASE set from environment
yoon.__pga_aggregate_target=838860800
yoon.__sga_target=2516582400
yoon.__shared_io_pool_size=0
yoon.__shared_pool_size=520093696
yoon.__streams_pool_size=0
*.audit_file_dest=‘/opt/oracle/admin/yoon/adump‘
*.audit_trail=‘db‘
*.compatible=‘11.2.0.0.0‘
*.control_files=‘/opt/oracle/oradata/yoon/control01.ctl‘,‘/opt/oracle/fast_recovery_area/yoon/control02.ctl‘
*.db_block_size=8192
*.db_domain=‘‘
*.db_name=‘yoon‘
*.db_recovery_file_dest=‘/opt/oracle/fast_recovery_area‘
*.db_recovery_file_dest_size=4322230272
*.db_unique_name=‘YOON‘
*.diagnostic_dest=‘/opt/oracle‘
*.dispatchers=‘(PROTOCOL=TCP) (SERVICE=yoonXDB)‘
*.fal_server=‘yoondg‘
*.log_archive_config=‘dg_config=(yoon,yoondg)‘
*.log_archive_dest_1=‘location=/opt/oracle/archive_bak valid_for=(all_logfiles,primary_roles) db_unique_name=yoon‘
*.log_archive_dest_2=‘service=yoondg lgwr sync valid_for=(online_logfiles,primary_role) db_unique_name=yoondg‘
*.log_archive_dest_state_1=‘ENABLE‘
*.log_archive_dest_state_2=‘ENABLE‘
*.open_cursors=300
*.pga_aggregate_target=837812224
*.processes=150
*.remote_login_passwordfile=‘EXCLUSIVE‘
*.standby_file_management=‘AUTO‘
*.sga_target=2514485248
*.undo_tablespace=‘UNDOTBS1‘

 

16、将主库的数据文件、控制文件、参数文件、密码文件拷贝到备库对应的目录
[[email protected] oracle]# scp -r admin/ fast_recovery_area/ oradata/ [email protected]:/opt/oracle/

 

17、修改备库参数文件
yoon.__db_cache_size=1946157056
yoon.__java_pool_size=16777216
yoon.__large_pool_size=16777216
yoon.__oracle_base=‘/opt/oracle‘#ORACLE_BASE set from environment
yoon.__pga_aggregate_target=838860800
yoon.__sga_target=2516582400
yoon.__shared_io_pool_size=0
yoon.__shared_pool_size=520093696
yoon.__streams_pool_size=0
*.audit_file_dest=‘/opt/oracle/admin/yoon/adump‘
*.audit_trail=‘db‘
*.compatible=‘11.2.0.0.0‘
*.control_files=‘/opt/oracle/oradata/yoon/control01.ctl‘,‘/opt/oracle/fast_recovery_area/yoon/control02.ctl‘
*.db_block_size=8192
*.db_domain=‘‘
*.db_name=‘yoon‘
*.db_recovery_file_dest=‘/opt/oracle/fast_recovery_area‘
*.db_recovery_file_dest_size=4322230272
*.db_unique_name=‘YOONDG‘
*.diagnostic_dest=‘/opt/oracle‘
*.dispatchers=‘(PROTOCOL=TCP) (SERVICE=yoonXDB)‘
*.fal_server=‘yoon‘
*.log_archive_config=‘dg_config=(yoondg,yoon)‘
*.log_archive_dest_1=‘location=/opt/oracle/archive_bak valid_for=(all_logfiles,primary_roles) db_unique_name=yoondg‘
*.log_archive_dest_2=‘service=yoon lgwr sync valid_for=(online_logfiles,primary_role) db_unique_name=yoon‘
*.log_archive_dest_state_1=‘ENABLE‘
*.log_archive_dest_state_2=‘ENABLE‘
*.open_cursors=300
*.pga_aggregate_target=837812224
*.processes=150
*.remote_login_passwordfile=‘EXCLUSIVE‘
*.standby_file_management=‘AUTO‘
*.sga_target=2514485248
*.undo_tablespace=‘UNDOTBS1‘

 

18、在备库通过pfile创建spfile

 

19、删除备库的控制文件control01.ctl和control02.ctl
将standby_control01.ctl替换成control01.ctl和control02.ctl

 

20、启动备库
SQL> startup nomount
ORACLE instance started.

Total System Global Area 2505338880 bytes
Fixed Size 2230952 bytes
Variable Size 553649496 bytes
Database Buffers 1946157056 bytes
Redo Buffers 3301376 bytes
SQL>

SQL> alter database mount standby database;

Database altered.

启用redo应用
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;

停止standby
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;
SQL>shutdown immediate;

21、备用服务器的管理模式与只读模式
a.启动到管理模式

SQL>shutdown immediate;

SQL>startup nomount;

SQL>alter database mount standby database;

SQL>alter database recover managed standby database disconnect from session;

b.启动到只读模式
SQL>shutdown immediate;

SQL>startup nomount;

SQL>alter database mount standby database;

SQL> alter database open read only;

c.在管理恢复模式下到只读模式
SQL> recover managed standby database cancel;

SQL> alter database open read only;

d.从只读方式到管理恢复方式
SQL> recover managed standby database disconnect from session;

 

22、DG启动:
监听:先起备库再起主库

数据库:先起备库再起主库

关闭:与启动相反.

以上是关于oracle-11g-配置dataguard的主要内容,如果未能解决你的问题,请参考以下文章

oracle 11g dataguard ORA-10458问题求助

oracle dataguard详解和环境搭建

oracle11g dataguard 完全手册

oracle11g dataguard 完全手册

Oracle 11g Dataguard 配置,维护与详解 (ADG)

在oracle11g中配置多个DataGuard物理备机