將Standby資料庫臨時轉換為主資料庫用於測試

尛樣兒發表於2012-12-06
        這篇文章討論將Standby資料庫臨時轉換為主資料庫,原本的主資料庫不發生變化。

1.在主資料庫延遲向Standby資料庫傳送日誌。
SQL> alter system set log_archive_dest_state_2=defer;

System altered.

2.啟用Standby資料庫flashback database特性。
SQL> startup mount
ORACLE instance started.

Total System Global Area  784998400 bytes
Fixed Size                  2230600 bytes
Variable Size             281020088 bytes
Database Buffers          494927872 bytes
Redo Buffers                6819840 bytes
Database mounted.
SQL> alter database flashback on;

Database altered.

SQL> show parameter recover

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
db_recovery_file_dest                string      +DGFRA
db_recovery_file_dest_size           big integer 10G
db_unrecoverable_scn_tracking        boolean     TRUE
recovery_parallelism                 integer     0

3.在備用資料庫取消FAL配置。
SQL> show parameter fal

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
fal_client                           string
fal_server                           string      ractest
SQL> alter system set fal_server='';

System altered.

4.建立還原點。
SQL> select open_mode from v$database;

OPEN_MODE
--------------------
MOUNTED

SQL>                     
SQL> create restore point Before_App_Test guarantee flashback database; 

Restore point created.

5.啟用Standby資料庫。
SQL> alter database activate standby database;

Database altered.

SQL> alter database open;

Database altered.

SQL> select open_mode from v$database;

OPEN_MODE
--------------------
READ WRITE

6.模擬測試資料。
SQL> create table test199(id number primary key);

Table created.

SQL> begin
  2  for i in 1..1000 loop
  3  insert into test199 values(i);
  4  end loop;
  5  end;
  6  /

PL/SQL procedure successfully completed.

SQL> commit;

Commit complete.

SQL> select count(1) from test199;

  COUNT(1)
----------
      1000

7.將Standby資料庫利用flashback database特性恢復到還原點。
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.

Total System Global Area  784998400 bytes
Fixed Size                  2230600 bytes
Variable Size             281020088 bytes
Database Buffers          494927872 bytes
Redo Buffers                6819840 bytes
Database mounted.
SQL> flashback database to restore point before_app_test; 

Flashback complete.

8.將主資料庫轉換為Standby資料庫。
SQL> alter database convert to physical standby; 

Database altered.

SQL> alter database open;
alter database open
*
ERROR at line 1:
ORA-01507: database not mounted


SQL> select status from v$instance;

STATUS
------------
STARTED

SQL> alter database mount;
alter database mount
*
ERROR at line 1:
ORA-00750: database has been previously mounted and dismounted


SQL> shutdown immediate
ORA-01507: database not mounted


ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.

Total System Global Area  784998400 bytes
Fixed Size                  2230600 bytes
Variable Size             281020088 bytes
Database Buffers          494927872 bytes
Redo Buffers                6819840 bytes
Database mounted.
SQL> alter database open;

Database altered.

SQL> select name,open_mode from v$database;

NAME      OPEN_MODE
--------- --------------------
RACTEST   READ ONLY

SQL> select count(1) from test199;
select count(1) from test199
                     *
ERROR at line 1:
ORA-00942: table or view does not exist

9.恢復主資料庫向Standby資料庫的日誌傳遞。
SQL> alter system set log_archive_dest_state_2=enable;

System altered.

SQL> alter system switch logfile;

System altered.

SQL> select thread#,dest_id,max(sequence#) from v$archived_log where resetlogs_id=786500749 group by thread#,dest_id;

   THREAD#    DEST_ID MAX(SEQUENCE#)
---------- ---------- --------------
         2          1             71
         1          2            102
         1          1            102
         2          2             70

SQL> select thread#,dest_id,max(sequence#) from v$archived_log where resetlogs_id=786500749 group by thread#,dest_id;

   THREAD#    DEST_ID MAX(SEQUENCE#)
---------- ---------- --------------
         2          1             72
         1          2            102
         1          1            102
         2          2             72

10.恢復Standby資料庫的FAL配置。
SQL> alter system set fal_server='ractest';

System altered.


參考文章:
http://blog.csdn.net/henrybai/article/details/3020068

--end--




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

相關文章