利用flashback將Dataguard備庫啟用可讀寫

shawnloong發表於2015-06-14

oracle 利用flashback將備庫啟用為read wirte(10g 及上)
環境:
OS: CENTOS 6.5 X64
DB: ORACLE 10.2.0.5
主庫操作:
SQL> alter system switch logfile;
System altered.
SQL>
備庫操作
取消歸檔應用
SQL> alter database recover managed standby database cancel;
Database altered.
SQL>
建立還原點
SQL>  create restore point restore_point_dg guarantee flashback database;
Restore point created.
SQL>
主庫操作
將備庫的歸檔目的設定為defer(這樣後臺不會報錯,防止主庫傳輸資料到備庫)
官方解釋
defer
Specifies that valid destination information and attributes are preserved, but the destination is excluded from archiving operations until re-enable
SQL> alter system set log_archive_dest_state_2=defer;
將備庫啟用為read/wirte
SQL> alter database activate standby database;
Database altered.
SQL> alter database open;
Database altered.
SQL>
備庫狀態為read/write
SQL> select open_mode from v$database;
OPEN_MODE
----------
READ WRITE
SQL>
這樣我們可以在備庫Export操作了
[oracle@oracle10g-dg2-213-101 backup]$ expdp directory=backup dumpfile=test1`date +%F`.dmp logfile=test1`date +%F`.log schemas=test1
Export: Release 10.2.0.5.0 - 64bit Production on Monday, 15 September, 2014 22:37:17
Copyright (c) 2003, 2007, Oracle.  All rights reserved.
Username: / as sysdba
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Starting "SYS"."SYS_EXPORT_SCHEMA_01":  /******** AS SYSDBA directory=backup dumpfile=test12014-09-15.dmp logfile=test12014-09-15.log schemas=test1
Estimate in progress using BLOCKS method...
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 64 KB
Processing object type SCHEMA_EXPORT/USER
Processing object type SCHEMA_EXPORT/SYSTEM_GRANT
Processing object type SCHEMA_EXPORT/ROLE_GRANT
Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
. . exported "TEST1"."TEST"                              4.960 KB       5 rows
Master table "SYS"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SYS.SYS_EXPORT_SCHEMA_01 is:
  /u01/app/oracle/dump/test12014-09-15.dmp
Job "SYS"."SYS_EXPORT_SCHEMA_01" successfully completed at 22:37:31
[oracle@oracle10g-dg2-213-101 backup]$
主庫操作
主庫上新增記錄
SQL> insert into test values(10);
1 row created.
SQL> insert into test values(10);
1 row created.
SQL> insert into test values(10);
1 row created.
SQL> insert into test values(11);
1 row created.
SQL> insert into test values(11);
1 row created.
SQL> commit;
Commit complete.
System altered.
SQL>
SQL> conn / as sysdba
Connected.
SQL> alter system switch logfile;
System altered.
SQL>
備庫操作
備庫上刪除表
[oracle@oracle10g-dg2-213-101 backup]$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.5.0 - Production on Mon Sep 15 22:40:53 2014
Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> conn test1/test1
Connected.
SQL> drop table test purge;
Table dropped.
SQL>
準備重新恢復到dg備庫環境
SQL> startup mount force;
ORACLE instance started.
Total System Global Area  704643072 bytes
Fixed Size              2098912 bytes
Variable Size            192940320 bytes
Database Buffers       503316480 bytes
Redo Buffers              6287360 bytes
Database mounted.
SQL>
閃回資料庫
SQL>  flashback database to restore point restore_point_dg;
Flashback complete.
SQL>
SQL> shutdown immediate;
ORA-01507: database not mounted
ORACLE instance shut down.
SQL> startup nomount;
ORACLE instance started.
Total System Global Area  704643072 bytes
Fixed Size              2098912 bytes
Variable Size            192940320 bytes
Database Buffers       503316480 bytes
Redo Buffers              6287360 bytes
SQL> alter database mount standby database; #或者alter database convert to physical standby;
Database altered.
主庫操作
SQL> alter system set log_archive_dest_state_2=enable scope=both;
System altered.
SQL>
備庫操作,檢查程式是否正常
SQL> select process,status from v$managed_standby;
PROCESS   STATUS
--------- ------------
ARCH       CONNECTED
ARCH       CONNECTED
ARCH       CONNECTED
MRP0       WAIT_FOR_LOG
RFS       IDLE
RFS       IDLE
6 rows selected.
SQL>
主庫操作
切換日誌
SQL> alter system switch logfile;
System altered.
SQL>
備庫已正常
FS[1]: Successfully opened standby log 8: '/u01/app/oracle/oradata/netdata/st_redo08a.log'
Mon Sep 15 22:50:22 CST 2014
Media Recovery Log /u01/app/oracle/archive/netdata/1_79_857898543.arc
Media Recovery Waiting for thread 1 sequence 80

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/24486203/viewspace-1698663/,如需轉載,請註明出處,否則將追究法律責任。

相關文章