2019独角兽企业重金招聘Python工程师标准>>>
如果搭建dg 先安装主库database 并建库,同时建备库database 软件,不需要建库。
1 主库打开归档功能
启动到mount状态下,打开归档功能
alter database archivelog;
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 17
Next log sequence to archive 19
Current log sequence 19
# 检查已经打开归档功能
2 配置主库监听和tnsnames文件
# listener.ora Network Configuration File: /u01/oracle/11g/network/admin/listene
r.ora
# Generated by Oracle configuration tools.
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = orcl)
(ORACLE_HOME = /u01/oracle/11g)
(SID_NAME = orcl)
)
(SID_DESC =
(GLOBAL_DBNAME = porcl)
(ORACLE_HOME = /u01/oracle/11g)
(SID_NAME = orcl)
)
(SID_DESC =
(GLOBAL_DBNAME = porcl_DGMGRL)
(ORACLE_HOME = /u01/oracle/11g)
(SID_NAME = orcl)
)
)
LISTENER =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = dghost)(PORT = 1521))
)
ADR_BASE_LISTENER = /u01/oracle
[oracle@dghost root]$ cat /u01/oracle/11g/network/admin/tnsnames.ora
# tnsnames.ora Network Configuration File: /u01/oracle/11g/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.
SORCL =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = dgstandby)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = sorcl)
)
)
PORCL =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = dghost)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = porcl)
)
)
ORCL =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = dghost)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl.dghost)
)
)
备库也配置监听
注意主库和备库配置完监听要用tnsping测试都能ping通
[oracle@dghost root]$ tnsping porcl
TNS Ping Utility for Linux: Version 11.2.0.3.0 - Production on 17-JAN-2017 00:19:12
Copyright (c) 1997, 2011, Oracle. All rights reserved.
Used parameter files:
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = dghost)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = porcl)))
OK (10 msec)
#主库tnsping自己成功
[oracle@dghost root]$ tnsping sorcl
TNS Ping Utility for Linux: Version 11.2.0.3.0 - Production on 17-JAN-2017 00:19:42
Copyright (c) 1997, 2011, Oracle. All rights reserved.
Used parameter files:
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = dgstandby)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = sorcl)))
OK (20 msec)
#主库tnsping备库成功
# 下面同样需要在备库中tnsping自己和主库,这里就不一一举例
3 主库修改db_unique_name
SQL> show parameter db_un
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_unique_name string PORCL #db_unique_name 需要配置成tnsname里面能解析的域名
db_unrecoverable_scn_tracking boolean TRUE
# alter system set db_unique_name='porcl' scope=spfile;
4 主库修改standby_file_management
SQL> show parameter standby_f
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
standby_file_management string AUTO #修改为auto
5 主库打开强制日志和dg_broker
alter database force logging;
SQL> show parameter dg_b
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
dg_broker_config_file1 string /u01/oracle/11g/dbs/dr1PORCL.d
at
dg_broker_config_file2 string /u01/oracle/11g/dbs/dr2PORCL.d
at
dg_broker_start boolean TRUE #设置为true 打开
6 增加备库日志
alter database add standby logfile;
多增加几个
7 切换日志
alter system switch logfile;
多切换几次
8 主库参数文件拷贝到备库中
[oracle@dgstandby dbs]$ strings spfileorcl.ora
orcl.__db_cache_size=218103808
orcl.__java_pool_size=4194304
orcl.__large_pool_size=4194304
orcl.__oracle_base='/u01/oracle'#ORACLE_BASE set from environment
orcl.__pga_aggregate_target=205520896
orcl.__sga_target=381681664
orcl.__shared_io_pool_size=0
orcl.__shared_pool_size=142606336
orcl.__streams_pool_size=4194304
*.archive_lag_target=0
*.audit_file_dest='/u01/oracle/admin/orcl/adump' #备库需要创建这个目录
*.audit_trail='db'
*.compatible='11.2.0.0.0'
*.control_files='/u01/oracle/oradata/orcl/control01 #备库需要创建这个目录
.ctl','/u01/oracle/fast_recovery_area/orcl/control02.ctl' #备库需要创建这个目录
*.db_block_size=8192
*.db_domain='dghost'
*.db_name='orcl'
*.db_recovery_file_dest='/u01/oracle/fast_recovery_area' #备库需要创建这个目录
*.db_recovery_file_dest_size=4322230272
*.db_unique_name='SORCL'
*.dg_broker_start=TRUE
*.diagnostic_dest='/u01/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=orclXDB)'
*.fal_server='porcl'
*.log_archive_config='dg_config=(SORCL,porcl)'
*.log_archive_dest_1='location=USE_DB_RECOVERY_FILE_DEST','valid_for=(ALL_LOG
FILES, ALL_ROLES)'
orcl.log_archive_format='%t_%s_%r.dbf'
*.log_archive_max_processes=4
*.log_archive_min_succeed_dest=1
orcl.log_archive_trace=0
*.memory_target=585105408
*.open_cursors=300
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.standby_file_management='AUTO'
*.undo_tablespace='UNDOTBS1'
备库启动到nomount状态下,如果能正常启动到nomount 状态下说明参数文件没有问题
9 主库密码文件拷贝到备库
10 在备库中克隆
[oracle@dgstandby dbs]$ rman target sys/oracle@porcl auxiliary sys/oracle@sorcl nocatalog;
Recovery Manager: Release 11.2.0.3.0 - Production on Tue Jan 17 00:31:46 2017
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
connected to target database: ORCL (DBID=1461163151)
using target database control file instead of recovery catalog
connected to auxiliary database: ORCL (DBID=1461163151)
# 通过rman链接了主库和备库
RMAN> duplicate target database for standby nofilenamecheck from active database;
# 用这个进行克隆,不能有任何错误
11 dgbroker 创建主库和备库
DGMGRL for Linux: Version 11.2.0.3.0 - 64bit Production
Copyright (c) 2000, 2009, Oracle. All rights reserved.
Welcome to DGMGRL, type "help" for information.
Connected.
#进入 dgbroker 环境
DGMGRL> help create
Creates a broker configuration
Syntax:
CREATE CONFIGURATION AS
PRIMARY DATABASE IS
CONNECT IDENTIFIER IS ;
# 使用帮助查看创建dgbroker的语法
DGMGRL> CREATE CONFIGURATION dgc as PRIMARY DATABASE IS porcl CONNECT IDENTIFIER IS porcl;
# 创建主库dgbroker
DGMGRL> help add
Adds a standby database to the broker configuration
Syntax:
ADD DATABASE
[AS CONNECT IDENTIFIER IS ]
[MAINTAINED AS {PHYSICAL|LOGICAL}];
#使用帮助文档查看添加备库dgbroker的语法
DGMGRL> ADD DATABASE sorcl as CONNECT IDENTIFIER IS sorcl;
12 激活dgbroker
DGMGRL> enable configuration;
13 启动备库到open 中测试主库和备库是否实时同步。
14 主备切换
switchover to sorcl;