开始前,备库创建还原点:
SQL> alter database recover managed standby database cancel; Database altered. SQL> !date 2016年 06月 22日 星期三 20:00:07 CST SQL> SQL> create restore point before_active_20160622 guarantee flashback database; Restore point created. SQL> SQL> desc v$restore_point; Name Null? Type ----------------------------------------- -------- ---------------------------- SCN NUMBER DATABASE_INCARNATION# NUMBER GUARANTEE_FLASHBACK_DATABASE VARCHAR2(3) STORAGE_SIZE NUMBER TIME TIMESTAMP(9) RESTORE_POINT_TIME TIMESTAMP(9) PRESERVED VARCHAR2(3) NAME VARCHAR2(128) SQL> set linesize 400 SQL> col name for a28 SQL> SQL> select name,scn,storage_size,to_char(time,'yyyy-mm-dd hh24:mi:ss') "Time",to_char(restore_point_time,'yyyy-mm-dd hh24:mi:ss') "Restore Point Time",database_incarnation#,guarantee_flashback_database,preserved from v$restore_point; NAME SCN STORAGE_SIZE Time Restore Point Time DATABASE_INCARNATION# GUA PRE ---------------------------- ---------- ------------ ------------------- ------------------- --------------------- --- --- BEFORE_ACTIVE_20160622 1276388 52428800 2016-06-22 20:00:31 2 YES YES SQL>
查询相关的数据文件:
数据文件。
SQL> select name from v$datafile; NAME ---------------------------- /oradata/orcl/system01.dbf /oradata/orcl/sysaux01.dbf /oradata/orcl/undotbs01.dbf /oradata/orcl/users01.dbf /oradata/orcl/example01.dbf SQL>
控制文件。
SQL> select name from v$controlfile; NAME ---------------------------- /oradata/orcl/control01.ctl SQL>
日志文件。
SQL> col member for a80 SQL> select member from v$logfile; MEMBER -------------------------------------------------------------------------------- /oradata/orcl/redo03.log /oradata/orcl/redo02.log /oradata/orcl/redo01.log /oradata/orcl/standby_redo01.log /oradata/orcl/standby_redo02.log /oradata/orcl/standby_redo03.log /oradata/orcl/standby_redo04.log 7 rows selected. SQL>
关闭备库数据库:
SQL> select instance_name,status from v$instance; INSTANCE_NAME STATUS ---------------- ------------ orcl MOUNTED SQL> shutdown immediate; ORA-01109: database not open Database dismounted. ORACLE instance shut down. SQL>
冷备:
文件系统备份相应的数据文件与目录:
[oracle@oradg2 ~]$ cd /oradata/ [oracle@oradg2 oradata]$ ls orcl [oracle@oradg2 oradata]$ ls -ltr 总计 4 drwxr-xr-x 2 oracle oinstall 4096 06-19 18:51 orcl [oracle@oradg2 oradata]$ [oracle@oradg2 oradata]$ mv orcl/ orcl_orig_dg_20160622 [oracle@oradg2 oradata]$ [oracle@oradg2 oradata]$ ls -ltr 总计 4 drwxr-xr-x 2 oracle oinstall 4096 06-19 18:51 orcl_orig_dg_20160622 [oracle@oradg2 oradata]$
冷备:
[oracle@oradg2 oradata]$ ls -ltr 总计 4 drwxr-xr-x 2 oracle oinstall 4096 06-19 18:51 orcl_orig_dg_20160622 [oracle@oradg2 oradata]$ [oracle@oradg2 oradata]$ ls -ltr orcl_orig_dg_20160622/* -rw-r----- 1 oracle oinstall 9748480 06-18 07:42 orcl_orig_dg_20160622/orcl_standby.ctl -rw-r----- 1 oracle oinstall 20979712 06-19 18:55 orcl_orig_dg_20160622/temp01.dbf -rw-r----- 1 oracle oinstall 52429312 06-19 19:01 orcl_orig_dg_20160622/standby_redo04.log -rw-r----- 1 oracle oinstall 52429312 06-19 19:01 orcl_orig_dg_20160622/standby_redo03.log -rw-r----- 1 oracle oinstall 52429312 06-19 19:28 orcl_orig_dg_20160622/redo03.log -rw-r----- 1 oracle oinstall 52429312 06-19 19:28 orcl_orig_dg_20160622/redo02.log -rw-r----- 1 oracle oinstall 52429312 06-19 19:32 orcl_orig_dg_20160622/redo01.log -rw-r----- 1 oracle oinstall 5251072 06-22 20:00 orcl_orig_dg_20160622/users01.dbf -rw-r----- 1 oracle oinstall 110108672 06-22 20:00 orcl_orig_dg_20160622/undotbs01.dbf -rw-r----- 1 oracle oinstall 796925952 06-22 20:00 orcl_orig_dg_20160622/system01.dbf -rw-r----- 1 oracle oinstall 618668032 06-22 20:00 orcl_orig_dg_20160622/sysaux01.dbf -rw-r----- 1 oracle oinstall 346693632 06-22 20:00 orcl_orig_dg_20160622/example01.dbf -rw-r----- 1 oracle oinstall 52429312 06-22 20:15 orcl_orig_dg_20160622/standby_redo01.log -rw-r----- 1 oracle oinstall 52429312 06-22 20:20 orcl_orig_dg_20160622/standby_redo02.log -rw-r----- 1 oracle oinstall 9781248 06-22 20:20 orcl_orig_dg_20160622/control01.ctl [oracle@oradg2 oradata]$ [oracle@oradg2 oradata]$ cp -rp orcl_orig_dg_20160622/ orcl_standalone/ [oracle@oradg2 oradata]$ [oracle@oradg2 oradata]$ ls -ltr 总计 8 drwxr-xr-x 2 oracle oinstall 4096 06-19 18:51 orcl_standalone drwxr-xr-x 2 oracle oinstall 4096 06-19 18:51 orcl_orig_dg_20160622 [oracle@oradg2 oradata]$ [oracle@oradg2 oradata]$ ls -ltr orcl_standalone/ 总计 2214464 -rw-r----- 1 oracle oinstall 9748480 06-18 07:42 orcl_standby.ctl -rw-r----- 1 oracle oinstall 20979712 06-19 18:55 temp01.dbf -rw-r----- 1 oracle oinstall 52429312 06-19 19:01 standby_redo04.log -rw-r----- 1 oracle oinstall 52429312 06-19 19:01 standby_redo03.log -rw-r----- 1 oracle oinstall 52429312 06-19 19:28 redo03.log -rw-r----- 1 oracle oinstall 52429312 06-19 19:28 redo02.log -rw-r----- 1 oracle oinstall 52429312 06-19 19:32 redo01.log -rw-r----- 1 oracle oinstall 5251072 06-22 20:00 users01.dbf -rw-r----- 1 oracle oinstall 110108672 06-22 20:00 undotbs01.dbf -rw-r----- 1 oracle oinstall 796925952 06-22 20:00 system01.dbf -rw-r----- 1 oracle oinstall 618668032 06-22 20:00 sysaux01.dbf -rw-r----- 1 oracle oinstall 346693632 06-22 20:00 example01.dbf -rw-r----- 1 oracle oinstall 52429312 06-22 20:15 standby_redo01.log -rw-r----- 1 oracle oinstall 52429312 06-22 20:20 standby_redo02.log -rw-r----- 1 oracle oinstall 9781248 06-22 20:20 control01.ctl [oracle@oradg2 oradata]$
制作软链接:
[oracle@oradg2 oradata]$ ls -ltr 总计 8 drwxr-xr-x 2 oracle oinstall 4096 06-19 18:51 orcl_standalone drwxr-xr-x 2 oracle oinstall 4096 06-19 18:51 orcl_orig_dg_20160622 [oracle@oradg2 oradata]$ [oracle@oradg2 oradata]$ ln -s orcl_standalone/ orcl [oracle@oradg2 oradata]$ [oracle@oradg2 oradata]$ ls -ltr 总计 8 drwxr-xr-x 2 oracle oinstall 4096 06-19 18:51 orcl_standalone drwxr-xr-x 2 oracle oinstall 4096 06-19 18:51 orcl_orig_dg_20160622 lrwxrwxrwx 1 oracle oinstall 16 06-22 20:38 orcl -> orcl_standalone/ [oracle@oradg2 oradata]$
这样,软链接就制作好了。
你可以测试一下,使用软链接:
[oracle@oradg2 oradata]$ ls -ltr /oradata/orcl/* -rw-r----- 1 oracle oinstall 9748480 06-18 07:42 /oradata/orcl/orcl_standby.ctl -rw-r----- 1 oracle oinstall 20979712 06-19 18:55 /oradata/orcl/temp01.dbf -rw-r----- 1 oracle oinstall 52429312 06-19 19:01 /oradata/orcl/standby_redo04.log -rw-r----- 1 oracle oinstall 52429312 06-19 19:01 /oradata/orcl/standby_redo03.log -rw-r----- 1 oracle oinstall 52429312 06-19 19:28 /oradata/orcl/redo03.log -rw-r----- 1 oracle oinstall 52429312 06-19 19:28 /oradata/orcl/redo02.log -rw-r----- 1 oracle oinstall 52429312 06-19 19:32 /oradata/orcl/redo01.log -rw-r----- 1 oracle oinstall 5251072 06-22 20:00 /oradata/orcl/users01.dbf -rw-r----- 1 oracle oinstall 110108672 06-22 20:00 /oradata/orcl/undotbs01.dbf -rw-r----- 1 oracle oinstall 796925952 06-22 20:00 /oradata/orcl/system01.dbf -rw-r----- 1 oracle oinstall 618668032 06-22 20:00 /oradata/orcl/sysaux01.dbf -rw-r----- 1 oracle oinstall 346693632 06-22 20:00 /oradata/orcl/example01.dbf -rw-r----- 1 oracle oinstall 52429312 06-22 20:15 /oradata/orcl/standby_redo01.log -rw-r----- 1 oracle oinstall 52429312 06-22 20:20 /oradata/orcl/standby_redo02.log -rw-r----- 1 oracle oinstall 9781248 06-22 20:20 /oradata/orcl/control01.ctl [oracle@oradg2 oradata]$
然后,去操作切换,并打开数据库(standalone)。
[oracle@oradg2 oradata]$ ps -ef | grep pmon oracle 9255 3947 0 20:43 pts/1 00:00:00 grep pmon [oracle@oradg2 oradata]$ [oracle@oradg2 oradata]$ env | grep SID ORACLE_SID=orcl [oracle@oradg2 oradata]$ [oracle@oradg2 oradata]$ sqlplus / as sysdba SQL*Plus: Release 11.2.0.4.0 Production on Wed Jun 22 20:43:13 2016 Copyright (c) 1982, 2013, Oracle. All rights reserved. Connected to an idle instance. SQL> startup nomount; ORACLE instance started. Total System Global Area 1653518336 bytes Fixed Size 2253784 bytes Variable Size 1006636072 bytes Database Buffers 637534208 bytes Redo Buffers 7094272 bytes SQL> SQL> alter database mount; Database altered. SQL> select name,database_role from v$database; NAME DATABASE_ROLE --------- ---------------- ORCL PHYSICAL STANDBY SQL> SQL> alter database activate standby database; Database altered. SQL> SQL> select name,database_role from v$database; NAME DATABASE_ROLE --------- ---------------- ORCL PRIMARY SQL> SQL> shutdown immediate; ORA-01109: database not open Database dismounted. ORACLE instance shut down. SQL> SQL> startup; ORACLE instance started. Total System Global Area 1653518336 bytes Fixed Size 2253784 bytes Variable Size 1006636072 bytes Database Buffers 637534208 bytes Redo Buffers 7094272 bytes Database mounted. Database opened. SQL> SQL> select name,database_role,open_mode,log_mode from v$database; NAME DATABASE_ROLE OPEN_MODE LOG_MODE --------- ---------------- -------------------- ------------ ORCL PRIMARY READ WRITE ARCHIVELOG SQL>
模拟应用端测试:
SQL> select * from scott.dept; DEPTNO DNAME LOC ---------- -------------- ------------- 10 ACCOUNTING NEW YORK 20 RESEARCH DALLAS 30 SALES CHICAGO 40 OPERATIONS BOSTON SQL> insert into scott.dept values (90,'Angela Baby','Bei Jin'); 1 row created. SQL> commit; Commit complete. SQL> select * from scott.dept; DEPTNO DNAME LOC ---------- -------------- ------------- 10 ACCOUNTING NEW YORK 20 RESEARCH DALLAS 30 SALES CHICAGO 40 OPERATIONS BOSTON 90 Angela Baby Bei Jin SQL>
恢复备库:Standalone —> DG,Pysical Standby。
关闭当前,standalone的备库:
SQL> select instance_name,status from v$instance; INSTANCE_NAME STATUS ---------------- ------------ orcl OPEN SQL> shutdown immediate; Database closed. Database dismounted. ORACLE instance shut down. SQL>
Linux:取消软链接:
[oracle@oradg2 oradata]$ pwd /oradata [oracle@oradg2 oradata]$ ls -ltr 总计 8 drwxr-xr-x 2 oracle oinstall 4096 06-19 18:51 orcl_standalone drwxr-xr-x 2 oracle oinstall 4096 06-19 18:51 orcl_orig_dg_20160622 lrwxrwxrwx 1 oracle oinstall 16 06-22 20:38 orcl -> orcl_standalone/ [oracle@oradg2 oradata]$ rm -rf orcl [oracle@oradg2 oradata]$ [oracle@oradg2 oradata]$ ls -ltr 总计 8 drwxr-xr-x 2 oracle oinstall 4096 06-19 18:51 orcl_standalone drwxr-xr-x 2 oracle oinstall 4096 06-19 18:51 orcl_orig_dg_20160622 [oracle@oradg2 oradata]$ [oracle@oradg2 oradata]$ ls orcl_standalone/ control01.ctl orcl_standby.ctl redo02.log standby_redo01.log standby_redo03.log sysaux01.dbf temp01.dbf users01.dbf example01.dbf redo01.log redo03.log standby_redo02.log standby_redo04.log system01.dbf undotbs01.dbf [oracle@oradg2 oradata]$
还原,原数据文件(DG,Pysical Standby)的路径:
[oracle@oradg2 oradata]$ ls -ltr 总计 8 drwxr-xr-x 2 oracle oinstall 4096 06-19 18:51 orcl_standalone drwxr-xr-x 2 oracle oinstall 4096 06-19 18:51 orcl_orig_dg_20160622 [oracle@oradg2 oradata]$ [oracle@oradg2 oradata]$ mv orcl_orig_dg_20160622/ orcl/ [oracle@oradg2 oradata]$ [oracle@oradg2 oradata]$ ls -ltr 总计 8 drwxr-xr-x 2 oracle oinstall 4096 06-19 18:51 orcl_standalone drwxr-xr-x 2 oracle oinstall 4096 06-19 18:51 orcl [oracle@oradg2 oradata]$
数据库:启动备库。
[oracle@oradg2 oradata]$ ps -ef | grep pmon oracle 15187 3947 0 20:52 pts/1 00:00:00 grep pmon [oracle@oradg2 oradata]$ [oracle@oradg2 oradata]$ env | grep SID ORACLE_SID=orcl [oracle@oradg2 oradata]$ [oracle@oradg2 oradata]$ sqlplus / as sysdba SQL*Plus: Release 11.2.0.4.0 Production on Wed Jun 22 20:53:01 2016 Copyright (c) 1982, 2013, Oracle. All rights reserved. Connected to an idle instance. SQL> startup nomount ORACLE instance started. Total System Global Area 1653518336 bytes Fixed Size 2253784 bytes Variable Size 1006636072 bytes Database Buffers 637534208 bytes Redo Buffers 7094272 bytes SQL> SQL> alter database mount standby database; Database altered. SQL> alter database recover managed standby database disconnect from session; Database altered. SQL> SQL> select name,database_role from v$database; NAME DATABASE_ROLE -------------------------------------------------- ---------------- ORCL PHYSICAL STANDBY SQL> SQL> set linesize 400 SQL> col name for a50 SQL> SQL> select name,to_char(first_time,'yyyy-mm-dd hh24:mi:ss') "First",to_char(next_time,'yyyy-mm-dd hh24:mi:ss') "Next",applied,archived,deleted,status,to_char(completion_time,'yyyy-mm-dd hh24:mi:ss') "Completion",sequence# from v$archived_log order by sequence#; NAME First Next APPLIED ARC DEL S Completion SEQUENCE# -------------------------------------------------- ------------------- ------------------- --------- --- --- - ------------------- ---------- /u01/arch/1_1_914957351.dbf 2016-06-19 18:49:11 2016-06-19 18:51:49 NO YES NO A 2016-06-19 18:52:48 1 /u01/arch/1_2_914957351.dbf 2016-06-19 18:51:49 2016-06-19 18:55:10 NO YES NO A 2016-06-19 18:55:11 2 /u01/arch/1_9_914817615.dbf 2016-06-18 06:25:57 2016-06-18 06:27:52 YES YES NO A 2016-06-18 08:42:06 9 /u01/arch/1_10_914817615.dbf 2016-06-18 06:27:52 2016-06-18 08:49:56 YES YES NO A 2016-06-18 08:42:07 10 /u01/arch/1_11_914817615.dbf 2016-06-18 08:49:56 2016-06-18 08:53:21 YES YES NO A 2016-06-18 08:42:06 11 /u01/arch/1_12_914817615.dbf 2016-06-18 08:53:21 2016-06-18 08:55:35 YES YES NO A 2016-06-18 08:42:14 12 /u01/arch/1_13_914817615.dbf 2016-06-18 08:55:35 2016-06-18 08:57:59 YES YES NO A 2016-06-18 08:44:35 13 /u01/arch/1_14_914817615.dbf 2016-06-18 08:57:59 2016-06-18 09:24:44 YES YES NO A 2016-06-18 09:11:20 14 /u01/arch/1_15_914817615.dbf 2016-06-18 09:24:44 2016-06-18 09:26:56 YES YES NO A 2016-06-18 09:13:33 15 /u01/arch/1_16_914817615.dbf 2016-06-18 09:26:56 2016-06-18 09:26:59 YES YES NO A 2016-06-18 09:13:36 16 /u01/arch/1_17_914817615.dbf 2016-06-18 09:26:59 2016-06-18 09:27:44 YES YES NO A 2016-06-18 09:14:19 17 NAME First Next APPLIED ARC DEL S Completion SEQUENCE# -------------------------------------------------- ------------------- ------------------- --------- --- --- - ------------------- ---------- /u01/arch/1_18_914817615.dbf 2016-06-18 09:27:44 2016-06-18 09:28:17 YES YES NO A 2016-06-18 09:14:52 18 /u01/arch/1_19_914817615.dbf 2016-06-18 09:28:17 2016-06-18 10:10:42 YES YES NO A 2016-06-18 09:57:20 19 /u01/arch/1_20_914817615.dbf 2016-06-18 10:10:42 2016-06-18 10:26:25 YES YES NO A 2016-06-18 10:13:03 20 /u01/arch/1_21_914817615.dbf 2016-06-18 10:26:25 2016-06-18 14:07:16 YES YES NO A 2016-06-18 13:53:54 21 /u01/arch/1_22_914817615.dbf 2016-06-18 14:07:16 2016-06-18 19:32:02 YES YES NO A 2016-06-18 19:19:53 22 /u01/arch/1_23_914817615.dbf 2016-06-18 19:32:02 2016-06-19 00:00:42 YES YES NO A 2016-06-18 23:48:33 23 /u01/arch/1_24_914817615.dbf 2016-06-19 00:00:42 2016-06-19 06:00:26 YES YES NO A 2016-06-19 05:48:49 24 /u01/arch/1_25_914817615.dbf 2016-06-19 06:00:26 2016-06-19 10:08:01 YES YES NO A 2016-06-19 09:56:18 25 /u01/arch/1_26_914817615.dbf 2016-06-19 10:08:01 2016-06-19 14:20:32 YES YES NO A 2016-06-19 14:08:42 26 /u01/arch/1_27_914817615.dbf 2016-06-19 14:20:32 2016-06-19 18:20:12 YES YES NO A 2016-06-19 18:08:23 27 /u01/arch/1_28_914817615.dbf 2016-06-19 18:20:12 2016-06-19 19:17:17 YES YES NO A 2016-06-19 19:05:27 28 NAME First Next APPLIED ARC DEL S Completion SEQUENCE# -------------------------------------------------- ------------------- ------------------- --------- --- --- - ------------------- ---------- /u01/arch/1_28_914817615.dbf 2016-06-19 18:20:12 2016-06-19 18:49:11 NO YES YES D 2016-06-19 18:49:12 28 /u01/arch/1_29_914817615.dbf 2016-06-19 19:17:17 2016-06-19 19:39:12 YES YES NO A 2016-06-19 19:27:20 29 /u01/arch/1_30_914817615.dbf 2016-06-19 19:39:12 2016-06-19 19:43:06 YES YES NO A 2016-06-19 19:31:15 30 /u01/arch/1_31_914817615.dbf 2016-06-19 19:43:06 2016-06-19 19:44:03 YES YES NO A 2016-06-19 19:32:11 31 /u01/arch/1_32_914817615.dbf 2016-06-19 19:44:03 2016-06-19 22:22:15 YES YES NO A 2016-06-22 19:43:23 32 /u01/arch/1_33_914817615.dbf 2016-06-19 22:22:15 2016-06-19 22:25:34 YES YES NO A 2016-06-22 19:43:17 33 /u01/arch/1_34_914817615.dbf 2016-06-19 22:25:34 2016-06-19 22:25:41 YES YES NO A 2016-06-22 19:43:17 34 /u01/arch/1_35_914817615.dbf 2016-06-19 22:25:41 2016-06-19 22:25:59 YES YES NO A 2016-06-22 19:43:17 35 /u01/arch/1_36_914817615.dbf 2016-06-19 22:25:59 2016-06-19 22:26:00 YES YES NO A 2016-06-22 19:43:18 36 /u01/arch/1_37_914817615.dbf 2016-06-19 22:26:00 2016-06-19 22:26:01 YES YES NO A 2016-06-22 19:43:18 37 /u01/arch/1_38_914817615.dbf 2016-06-19 22:26:01 2016-06-19 22:26:02 YES YES NO A 2016-06-22 19:43:18 38 NAME First Next APPLIED ARC DEL S Completion SEQUENCE# -------------------------------------------------- ------------------- ------------------- --------- --- --- - ------------------- ---------- /u01/arch/1_39_914817615.dbf 2016-06-19 22:26:02 2016-06-19 22:29:57 YES YES NO A 2016-06-22 19:43:24 39 /u01/arch/1_40_914817615.dbf 2016-06-19 22:29:57 2016-06-19 23:01:47 NO YES NO A 2016-06-22 20:15:14 40 /u01/arch/1_41_914817615.dbf 2016-06-19 23:01:47 2016-06-19 23:30:30 NO YES NO A 2016-06-22 20:53:26 41 /u01/arch/1_42_914817615.dbf 2016-06-19 23:30:30 2016-06-19 23:40:03 NO YES NO A 2016-06-22 20:53:29 42 37 rows selected. SQL>
至此,在DG备库激活的过程中如何使用软链接的方法,已经全部呈现完成。
——————————————————————————
Done。