利用RMAN搭建DATAGARD進行主備切換

使用rman的duplicate來創建備庫,過程簡潔了不少,無需在手動創建備庫控制文件。


主庫SPFILE  

*.log_archive_format='%T%S%r.ARC'
*.DB_UNIQUE_NAME='primary'
*.log_archive_config='DG_CONFIG=(primary,standby)'
*.log_archive_dest_1='location=C:/oracle/product/10.2.0/oradata/arch VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=primary'
*.log_archive_dest_2='SERVICE=standby arch ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=standby'
*.STANDBY_FILE_MANAGEMENT=AUTO
*.LOG_ARCHIVE_DEST_STATE_1=ENABLE
*.LOG_ARCHIVE_DEST_STATE_2=ENABLE

*.FAL_SERVER='standby'

*.FAL_CLIENT='primary'


備庫SPFILE  在主庫創建SPFILE給備庫 並修改

*.log_archive_format='%T%S%r.ARC'
*.DB_UNIQUE_NAME='standby'
*.log_archive_config='DG_CONFIG=(primary,standby)'
*.log_archive_dest_1='location=C:/oracle/product/10.2.0/oradata/arch VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=standby'
*.log_archive_dest_2='SERVICE=primary arch ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=primary'
*.STANDBY_FILE_MANAGEMENT=AUTO
*.LOG_ARCHIVE_DEST_STATE_1=ENABLE
*.LOG_ARCHIVE_DEST_STATE_2=ENABLE
*.FAL_SERVER='primary'
*.FAL_CLIENT='standby'


配置好TNS 監聽能互相TNSPING通

主庫操作

修改LOGFILE大小爲100M,添加4組備用聯機日誌

SQL> alter database add logfile group 4 'c:\oracle\product\10.2.0\oradata\orcl\r
edolog04.log' size 50M;

SQL> alter database add logfile group 5 'c:\oracle\product\10.2.0\oradata\orcl\r
edolog05.log' size 50M;

SQL> alter system switch logfile;

SQL> alter database drop logfile group 1;

SQL> alter database drop logfile group 2;

SQL> alter database drop logfile group 3;

SQL> alter database add logfile group 2 'c:\oracle\product\10.2.0\oradata\orcl\r
edolog02.log' size 100M;

SQL> alter database add logfile group 3 'c:\oracle\product\10.2.0\oradata\orcl\r
edolog03.log' size 100M;

SQL> alter database drop logfile group 4;

SQL> select group#,sequence#,status from v$log;


    GROUP#  SEQUENCE# STATUS
---------- ---------- --------------------------------
         1         15 CURRENT
         2          0 UNUSED
         3          0 UNUSED
         5         14 ACTIVE


SQL> alter system switch logfile;

SQL> select group#,sequence#,status from v$log;


    GROUP#  SEQUENCE# STATUS
---------- ---------- --------------------------------
         1         19 INACTIVE
         2         20 ACTIVE
         3         21 CURRENT
         5         18 INACTIVE

SQL> alter database drop logfile group 5;

數據庫已更改。

SQL> select group#,sequence#,status from v$log;


    GROUP#  SEQUENCE# STATUS
---------- ---------- --------------------------------
         1         19 INACTIVE
         2         20 ACTIVE
         3         21 CURRENT

SQL> alter database add standby logfile group 4 'c:\oracle\product\10.2.0\oradat
a\orcl\standbylog04.log' size 50M;

數據庫已更改。

SQL> alter database add standby logfile group 5 'c:\oracle\product\10.2.0\oradat
a\orcl\standbylog05.log' size 50M;

數據庫已更改。

SQL> alter database add standby logfile group 6 'c:\oracle\product\10.2.0\oradat
a\orcl\standbylog06.log' size 50M;

數據庫已更改。

SQL> alter database add standby logfile group 7 'c:\oracle\product\10.2.0\oradat
a\orcl\standbylog07.log' size 50M;

數據庫已更改。

-- 添加日誌組成員方法
SQL> alter database add logfile member 'c:\oracle\product\10.2.0\oradata\orcl\re
dolog012.log' to group 1;

數據庫已更改。

--刪除日誌組成員方法

SQL> alter database drop logfile member  'c:\oracle\product\10.2.0\oradata\orcl\
redolog012.log';

數據庫已更改。

RMAN全備數據庫 控制文件 歸檔日誌

RMAN> backup full format 'c:\backup\fullbackup_%d_%T_%s.bak' database include cu

rrent controlfile for standby;


RMAN> sql 'alter system archive log current';

sql 語句: alter system archive log current
RMAN> backup archivelog all format 'c:\backup\archive_%d_%T_%s';

拷貝備份到備庫相同目錄c:\backup下

備庫操作

C:\Documents and Settings\Administrator>rman target sys/oracle@primary auxiliary
 /

恢復管理器: Release 10.2.0.1.0 - Production on 星期三 11月 6 16:04:22 2013

Copyright (c) 1982, 2005, Oracle.  All rights reserved.

連接到目標數據庫: ORCL (DBID=1351749857)
已連接到輔助數據庫: ORCL (未裝載)

RMAN> duplicate target database for standby dorecover nofilenamecheck;
介質恢復完成, 用時: 00:00:03
完成 recover 於 06-11月-13
完成 Duplicate Db 於 06-11月-13

SQL> select status from v$instance;

STATUS
------------
MOUNTED

SQL> alter database recover managed standby database disconnect from session;

數據庫已更改。

主庫操作

SQL> archive log list
數據庫日誌模式            存檔模式
自動存檔             啓用
存檔終點            C:/oracle/product/10.2.0/oradata/arch
最早的聯機日誌序列     22
下一個存檔日誌序列   24
當前日誌序列           24

插入一條數據測試

SQL> insert into wang2 values(1);


已創建 1 行。

SQL> commit;

提交完成。

SQL> alter system switch logfile;

系統已更改。

SQL> archive log list;
數據庫日誌模式            存檔模式
自動存檔             啓用
存檔終點            C:/oracle/product/10.2.0/oradata/arch
最早的聯機日誌序列     23
下一個存檔日誌序列   25
當前日誌序列           25

備庫操作

SQL> archive log list;
數據庫日誌模式            存檔模式
自動存檔             啓用
存檔終點            C:/oracle/product/10.2.0/oradata/arch
最早的聯機日誌序列     24
下一個存檔日誌序列   0
當前日誌序列           25

SQL> shutdown immediate;
ORA-01109: 數據庫未打開

已經卸載數據庫。
ORACLE 例程已經關閉。
SQL> startup
ORACLE 例程已經啓動。

Total System Global Area  167772160 bytes
Fixed Size                  1247900 bytes
Variable Size              88081764 bytes
Database Buffers           75497472 bytes
Redo Buffers                2945024 bytes
數據庫裝載完畢。
數據庫已經打開。


驗證 數據已插入過來
SQL> select * from wang2;


        ID
----------
         1


主備切換

主庫操作
SQL> select switchover_status from v$database;


SWITCHOVER_STATUS
----------------------------------------
SESSIONS ACTIVE

SQL> alter database commit to switchover to physical standby with session shutdo
wn;

數據庫已更改。

SQL> select status from v$instance;

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

SQL> shutdown immediate;
ORA-01507: ??????

ORACLE 例程已經關閉。
SQL> startup mount;
ORACLE 例程已經啓動。

Total System Global Area  167772160 bytes
Fixed Size                  1247900 bytes
Variable Size              83887460 bytes
Database Buffers           79691776 bytes
Redo Buffers                2945024 bytes
數據庫裝載完畢。
SQL> alter database recover managed standby database disconnect from session;

數據庫已更改。

SQL> select database_role from v$database;

DATABASE_ROLE
----------------
PHYSICAL STANDBY

SQL> select switchover_status from v$database;

SWITCHOVER_STATUS
-------------------
TO PRIMARY

SQL>alter database commit to switchover to primary;

數據庫已更改。

主庫切換備庫操作

SQL> select database_role from v$database;

DATABASE_ROLE
----------------
PHYSICAL STANDBY

SQL> select switchover_status from v$database;

SWITCHOVER_STATUS
--------------------
TO PRIMARY

SQL> alter database commit to switchover to primary;

數據庫已更改。

SQL> shutdown immediate;
ORA-01109: 數據庫未打開

已經卸載數據庫。
ORACLE 例程已經關閉。
SQL> startup
ORACLE 例程已經啓動。

Total System Global Area  167772160 bytes
Fixed Size                  1247900 bytes
Variable Size              88081764 bytes
Database Buffers           75497472 bytes
Redo Buffers                2945024 bytes
數據庫裝載完畢。
ORA-01092: ORACLE 實例終止。強制斷開連接

SQL>
SQL> exit
從 Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options 斷開

C:\Documents and Settings\Administrator>sqlplus "/as sysdba"

SQL*Plus: Release 10.2.0.1.0 - Production on 星期三 11月 6 16:42:21 2013

Copyright (c) 1982, 2005, Oracle.  All rights reserved.

已連接到空閒例程。

SQL> startup
ORACLE 例程已經啓動。

Total System Global Area  167772160 bytes
Fixed Size                  1247900 bytes
Variable Size              88081764 bytes
Database Buffers           75497472 bytes
Redo Buffers                2945024 bytes
數據庫裝載完畢。
ORA-01092: ORACLE 實例終止。強制斷開連接

SQL> exit

從 Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options 斷開

--通過查看ALER錯誤 是SPFILE中UNDO表空間設置錯誤導致的


Wed Nov 06 16:42:32 2013
Errors in file c:\oracle\product\10.2.0\admin\orcl\bdump\orcl_mman_476.trc:
ORA-30012: undo tablespace '' does not exist or of wrong type

Wed Nov 06 16:42:32 2013
Errors in file c:\oracle\product\10.2.0\admin\orcl\bdump\orcl_psp0_1632.trc:
ORA-30012: undo tablespace '' does not exist or of wrong type

Wed Nov 06 16:42:32 2013
Instance terminated by USER, pid = 3408
ORA-1092 signalled during: ALTER DATABASE OPEN...

C:\Documents and Settings\Administrator>sqlplus "/as sysdba"

SQL*Plus: Release 10.2.0.1.0 - Production on 星期三 11月 6 16:44:06 2013

Copyright (c) 1982, 2005, Oracle.  All rights reserved.

已連接到空閒例程。

SQL> startup mount;
ORACLE 例程已經啓動。

Total System Global Area  167772160 bytes
Fixed Size                  1247900 bytes
Variable Size              88081764 bytes
Database Buffers           75497472 bytes
Redo Buffers                2945024 bytes
數據庫裝載完畢。
SQL> show parameter undo;

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
undo_management                      string      AUTO
undo_retention                       integer     900
undo_tablespace                      string      UNDOTBS01
SQL> exit
從 Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options 斷開

C:\Documents and Settings\Administrator>sqlplus "/as sysdba"

SQL*Plus: Release 10.2.0.1.0 - Production on 星期三 11月 6 16:44:52 2013

Copyright (c) 1982, 2005, Oracle.  All rights reserved.

連接到:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options

SQL> create pfile='c:\pfile.ora' from spfile;

文件已創建。

SQL> show parameter spfile;

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
spfile                               string      C:\ORACLE\PRODUCT\10.2.0\DB_1\
                                                 DATABASE\SPFILEORCL.ORA
SQL> alter system set undo_tablespace='undotbs1' scope=both;
alter system set undo_tablespace='undotbs1' scope=both
*
第 1 行出現錯誤:
ORA-02097: 無法修改參數, 因爲指定的值無效
ORA-30012: 還原表空間 'undotbs1' 不存在或類型不正確

SQL> alter system set undo_tablespace='undotbs1' scope=spfile;

系統已更改。

SQL> shutdown immediate;
ORA-01109: 數據庫未打開

已經卸載數據庫。
ORACLE 例程已經關閉。
SQL> startup
ORACLE 例程已經啓動。

Total System Global Area  167772160 bytes
Fixed Size                  1247900 bytes
Variable Size              88081764 bytes
Database Buffers           75497472 bytes
Redo Buffers                2945024 bytes
數據庫裝載完畢。
數據庫已經打開。
SQL> show parameter undo;

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
undo_management                      string      AUTO
undo_retention                       integer     900
undo_tablespace                      string      undotbs1


完畢


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章