Chinaunix首页 | 论坛 | 博客
  • 博客访问: 667323
  • 博文数量: 128
  • 博客积分: 265
  • 博客等级: 二等列兵
  • 技术积分: 1464
  • 用 户 组: 普通用户
  • 注册时间: 2011-09-27 20:44
个人简介

just do it

文章分类

全部博文(128)

文章存档

2023年(1)

2020年(1)

2019年(1)

2018年(3)

2017年(6)

2016年(17)

2015年(16)

2014年(39)

2013年(34)

2012年(10)

分类: SOLARIS

2015-09-24 10:18:33


点击(此处)折叠或打开

  1. 搭建环境:
  2. OS:Solaris10 x86-64
  3. DB:Oracle 11.2.0
  4. 主库所在主机:sol01
  5. 备库所在主机:sol02
  6. 2 主库部署步骤
  7. 2.1 主库操作
  8. 创建归档目录,开启归档模式。
  9. su – oracle
  10. mkdir /orahome/oracle/archivelog
  11. sqlplus /as sysdba
  12. shutdown immediate
  13. startup mount
  14. alter database archivelog;
  15. 查看是否force_logging模式
  16. SQL> select log_mode,force_logging from v$database;
  17. 开启force_logging模式
  18. alter database force logging;
  19. create pfile from spfile;
  20. 创建备库控制文件
  21. alter database create standby controlfile as '/orahome/oracle/bak/controlfile01.ctl';
  22. 创建备库日志组路径
  23. alter database add standby logfile group 4 '/orahome/oracle/app/oradata/test/standbyredo04.log' size 50m;
  24. alter database add standby logfile group 5 '/orahome/oracle/app/oradata/test/standbyredo05.log' size 50m;
  25. alter database add standby logfile group 6 '/orahome/oracle/app/oradata/test/standbyredo06.log' size 50m;
  26. alter database add standby logfile group 7 '/orahome/oracle/app/oradata/test/standbyredo07.log' size 50m;
  27. cd $ORACLE_HOME/dbs
  28. 备份参数文件
  29. cp inittest.ora  inittest.ora.bk
  30. 2.2 在inittest.ora参数文件中加入:
  31. 修改参数文件:
  32. db_unique_name=test
  33. log_archive_config='dg_config=(test,test_dg)'
  34. log_archive_dest_1='location=/orahome/oracle/archivelog valid_for=(all_logfiles,all_roles) db_unique_name=test'
  35. log_archive_dest_2='service=test_dg lgwr async valid_for=(online_logfiles,primary_role) db_unique_name=test_dg'
  36. log_archive_dest_state_1=enable
  37. log_archive_dest_state_2=enable
  38. fal_server=test_dg
  39. fal_client=test
  40. db_file_name_convert='/orahome/oracle/app/oradata/test','/orahome/oracle/app/oradata/test'
  41. log_file_name_convert='/orahome/oracle/app/oradata/test','/orahome/oracle/app/oradata/test'
  42. standby_file_management=auto
  43. 2.3 使更改参数生效:
  44. sqlplus / as sysdba
  45. startup nomount pfile= '$ORACLE_HOME/dbs/inittest.ora';
  46. create spfile from pfile;
  47. shutdown immediate
  48. startup mount
  49. 2.4 把相应的文件SCP到standby主机:
  50. 控制文件:
  51. scp /orahome/oracle/bak/controlfile01.ctl 192.168.0.22: $ORACLE_BASE/oradata/$ORACLE_SID/control01.ctl
  52. scp /orahome/oracle/bak/controlfile01.ctl 192.168.0.22: $ORACLE_BASE/oradata/$ORACLE_SID/control02.ctl
  53. oracle口令文件:
  54. scp orapwgisdb1 192.168.111.129:/home/oracle/u01/11.2.3/dbhome_1/dbs/orapwgisdb2
  55. oracle数据文件:
  56. scp $ORACLE_BASE/oradata/$ORACLE_SID/*.dbf 192.168.0.22:$ORACLE_BASE/oradata/$ORACLE_SID/
  57. oracle redo日志文件(不包括standyredo.log)
  58. scp $ORACLE_BASE/oradata/$ORACLE_SID/*.log 192.168.0.22:$ORACLE_BASE/oradata/$ORACLE_SID/
  59. 参数文件
  60. scp $ORACLE_HOME/dbs/inittest.ora 192.168.0.22:$ORACLE_HOME/dbs/
  61. 2.5 更改备库使用的pfile:inittest.ora
  62. db_unique_name=test_dg
  63. log_archive_config='dg_config=(test,test_dg)'
  64. log_archive_dest_1='location=/orahome/oracle/archivelog valid_for=(all_logfiles,all_roles) db_unique_name=test_dg'
  65. log_archive_dest_2='service=test lgwr async valid_for=(online_logfiles,primary_role) db_unique_name=test'
  66. log_archive_dest_state_1=enable
  67. log_archive_dest_state_2=enable
  68. fal_server=test
  69. fal_client=test_dg
  70. db_file_name_convert='/orahome/oracle/app/oradata/test','/orahome/oracle/app/oradata/test'
  71. log_file_name_convert='/orahome/oracle/app/oradata/test','/orahome/oracle/app/oradata/test'
  72. standby_file_management=auto
  73. 2.6 配置监听:
  74.  bash-3.00$ more tnsnames.ora
  75. test =
  76.   (DESCRIPTION =
  77.     (ADDRESS_LIST =
  78.       (ADDRESS = (PROTOCOL = TCP)(HOST =192.168.0.21 )(PORT = 1521))
  79.     )
  80.     (CONNECT_DATA =
  81.       (SERVICE_NAME = test)
  82.     )
  83.   )
  84. test_dg =
  85.   (DESCRIPTION =
  86.     (ADDRESS_LIST =
  87.       (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.22)(PORT = 1521))
  88.     )
  89.     (CONNECT_DATA =
  90.       (SERVICE_NAME = test_dg)
  91.     )
  92.   )
  93. 将tnsnames.ora文件拷贝到备库相同位置。
  94. 2.7 打开主库:
  95. Alter database open;
  96. 日志如下:
  97. 3 从库上操作:
  98. 3.1 创建需要的目录
  99. mkdir -p $ORACLE_BASE/oradata/test
  100. mkdir -p $ORACLE_BASE/admin/test/{a,dp}dump
  101. sqlplus / as sysdba
  102. startup nomount pfile='$ORACLE_HOME/dbs/inittest.ora';
  103. create spfile from pfile;
  104. startup nomount
  105. 3.2 配置网络服务
  106. 启动监听(lsnrctl start),再tnsnames.ora中加入如下内容
  107. bash-3.00$ more tnsnames.ora
  108. test =
  109.   (DESCRIPTION =
  110.     (ADDRESS_LIST =
  111.       (ADDRESS = (PROTOCOL = TCP)(HOST =192.168.0.21 )(PORT = 1521))
  112.     )
  113.     (CONNECT_DATA =
  114.       (SERVICE_NAME = test)
  115.     )
  116.   )
  117. test_dg =
  118.   (DESCRIPTION =
  119.     (ADDRESS_LIST =
  120.       (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.22)(PORT = 1521))
  121.     )
  122.     (CONNECT_DATA =
  123.       (SERVICE_NAME = test_dg)
  124.     )
  125.   )
  126. 查看tnsping是否互通
  127. 将备库启动到mount状态
  128. alter database mount;
  129. 添加备库日志组
  130. alter database add standby logfile group 4 '/orahome/oracle/app/oradata/test/standbyredo04.log' size 50m;
  131. alter database add standby logfile group 5 '/orahome/oracle/app/oradata/test/standbyredo05.log' size 50m;
  132. alter database add standby logfile group 6 '/orahome/oracle/app/oradata/test/standbyredo06.log' size 50m;
  133. alter database add standby logfile group 7 '/orahome/oracle/app/oradata/test/standbyredo07.log' size 50m;
  134. 3.3 开启日志应用
  135. alter database recover managed standby database disconnect from session;
  136. 相关LOG:
  137.  alter database recover managed standby database disconnect from session
  138. Attempt to start background Managed Standby Recovery process (test)
  139. Thu Sep 24 09:01:44 2015
  140. MRP0 started with pid=26, OS id=3901
  141. MRP0: Background Managed Standby Recovery process started (test)
  142. Serial Media Recovery started
  143. Managed Standby Recovery not using Real Time Apply
  144. Waiting for all non-current ORLs to be archived...
  145. All non-current ORLs have been archived.
  146. Media Recovery Log /orahome/oracle/archivelog/1_79_891106389.dbf
  147. Completed: alter database recover managed standby database disconnect from session
  148. Media Recovery Waiting for thread 1 sequence 80 (in transit)
  149. 4 测试:
  150. 4.1 主库上:
  151. Conn scott/tiger
  152. SQL> create table a as select * from emp;
  153. Table created.
  154. SQL> conn / as sysdba
  155. Connected.
  156. SQL> alter system switch logfile;
  157. System altered.
  158. SQL>
  159. 4.2 从库上操作:
  160. SQL> alter database recover managed standby database cancel;
  161. Database altered.
  162. SQL> alter database open read only;
  163. Database altered.
  164. SQL> conn scott/tiger
  165. Connected.
  166. SQL> select * from tab;
  167. TNAME                          TABTYPE  CLUSTERID
  168. ------------------------------ ------- ----------
  169. A                              TABLE
  170. BONUS                          TABLE
  171. DEPT                           TABLE
  172. EMP                            TABLE
  173. SALGRADE                       TABLE
  174. 成功完成了同步
  175. 5 转换成ADG(active dataguard)
  176. /////////////////备库 Database mounted.///////////////
  177. SQL> alter database recover managed standby database disconnect from session;
  178. Database altered.
  179. SQL> alter database recover managed standby database cancel;
  180. Database altered.
  181. SQL> alter database open;          
  182. Database altered.
  183. SQL> alter database recover managed standby database using current logfile disconnect ;
  184. Database altered.
  185. SQL> SELECT OPEN_MODE FROM V$DATABASE;
  186. OPEN_MODE
  187. --------------------
  188. READ ONLY WITH APPLY
  189. 6 Swithover 测试:
  190. 6.1 检查主从库的信息:
  191. 主库上查询:
  192. SQL> select status ,gap_status from v$archive_dest_status where dest_id in (1,2);
  193.  
  194. STATUS    GAP_STATUS
  195. --------- ------------------------
  196. VALID
  197. VALID     NO GAP
  198. SQL> select switchover_status from v$database;
  199.  
  200. SWITCHOVER_STATUS
  201. --------------------
  202. TO STANDBY
  203. 此处的信息一定要显示是“to standby”
  204. 从库信息:
  205. SQL> select status,gap_status from v$archive_dest_status where dest_id in (1,2);
  206.  
  207. STATUS    GAP_STATUS
  208. --------- ------------------------
  209. VALID
  210. VALID     NO GAP
  211. 6.2 开始switchover:
  212. -- 主库的执行:
  213. SQL> alter database commit to switchover to physical standby with session shutdown ;
  214.  
  215. Database altered.
  216. SQL> shutdown abort;
  217. ORACLE instance shut down.
  218. SQL> startup mount
  219. ORACLE instance started.
  220.  
  221. Total System Global Area  413372416 bytes
  222. Fixed Size                  2228904 bytes
  223. Variable Size             339742040 bytes
  224. Database Buffers           62914560 bytes
  225. Redo Buffers                8486912 bytes
  226. Database mounted.
  227. SQL> select switchover_status from v$database;
  228.  
  229. SWITCHOVER_STATUS
  230. --------------------
  231. TO PRIMARY
  232.  
  233. SQL> alter database open;
  234.  
  235. Database altered.
  236.  
  237. SQL> select switchover_status from v$database;
  238.  
  239. SWITCHOVER_STATUS
  240. --------------------
  241. TO PRIMARY
  242. --- 从库上操行:
  243. SQL> select switchover_status from v$database;
  244.  
  245. SWITCHOVER_STATUS
  246. --------------------
  247. TO PRIMARY
  248.  
  249. SQL> alter database commit to switchover to primary with session shutdown ;
  250.  
  251. Database altered.
  252. SQL> select open_mode from v$database;
  253.  
  254. OPEN_MODE
  255. --------------------
  256. MOUNTED
  257.  
  258. SQL> alter database open;
  259.  
  260. Database altered.
  261. ---- 在现在的从库上(之前的主库上执行):
  262. SQL> select open_mode from v$database;
  263.  
  264. OPEN_MODE
  265. --------------------
  266. READ ONLY
  267.  
  268. SQL> alter database recover managed standby database using current logfile disconnect ;
  269.  
  270. Database altered.
  271. SQL> select open_mode from v$database;
  272.  
  273. OPEN_MODE
  274. --------------------
  275. READ ONLY WITH APPLY
  276. 6.3 切换后 再次测试:
  277. --- 主上执行:
  278.  SQL> conn scott/tiger
  279. Connected.
  280. SQL> create table b as select * from tab;
  281. Table created.
  282. SQL> conn /as sysdba
  283. Connected.
  284. SQL> alter system switch logfile;
  285. System altered.
  286. SQL>  conn scott/tiger
  287. Connected.
  288. SQL> select count(*) from a;
  289.   COUNT(*)
  290. ----------
  291.         14
  292. SQL> insert into a select * from a;
  293. 14 rows created.
  294. SQL> r
  295.   1* insert into a select * from a
  296. 28 rows created.
  297. SQL> r
  298.   1* insert into a select * from a
  299. 56 rows created.
  300. SQL> r
  301.   1* insert into a select * from a
  302. 112 rows created.
  303. SQL> select count(*) from a;
  304.   COUNT(*)
  305. ----------
  306.        224
  307. SQL> conn /as sysdba
  308. Connected.
  309. SQL> alter system switch logfile;
  310. System altered.
  311. 查看主库角色
  312. SQL> select database_role from v$database;
  313. DATABASE_ROLE
  314. ----------------
  315. PRIMARY
  316. 再从库上查询:
  317.  SQL> conn scott/tiger
  318. Connected.
  319. SQL> select * from tab;
  320. TNAME                          TABTYPE  CLUSTERID
  321. ------------------------------ ------- ----------
  322. A                              TABLE
  323. B                              TABLE
  324. BONUS                          TABLE
  325. DEPT                           TABLE
  326. EMP                            TABLE
  327. SALGRADE                       TABLE
  328. 6 rows selected.
  329. SQL> r
  330.   1* select count(*) from a
  331.   COUNT(*)
  332. ----------
  333.        224
  334. 查看备库角色
  335. SQL> select database_role from v$database;
  336. DATABASE_ROLE
  337. ----------------
  338. PHYSICAL STANDBY

阅读(1648) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~