不少數據庫小白剛入行確定會面臨這幾個問題:sql
數據庫何時須要開啓歸檔?何時不須要開啓歸檔呢?數據庫
歸檔好處多多,因此通常在生產環境上是要開啓歸檔的。可是在什麼環境下是不須要開啓歸檔的呢?oracle
下面安老師結合本身數年的擼碼經驗,教你們兩招輕鬆搞定這些問題!ide
RAC節點一 開啓歸檔spa
一. 基本步驟code
1. 建立歸檔目錄blog
2. RAC節點一 數據庫實例啓動到mount狀態圖片
3. 開啓歸檔ci
4. 檢查歸檔string
(敲黑板:如下代碼都可左右滑動查看&複製粘貼)
1. 規劃歸檔目錄
[oracle@RACZJ-DB01 ~]$ cd /oracle/arch01/RACZJDB1
[oracle@RACZJ-DB01 RACZJDB1]$ export ORACLE_SID=RACZJDB1
2. 將RAC節點1數據庫實例 RACZJDB1 啓動到mount狀態
[oracle@RACZJ-DB01 RACZJDB1]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Fri Oct 5 11:46:57 2018
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to an idle instance.
SQL> startup nomount
ORACLE instance started.
Total System Global Area 835104768 bytes
Fixed Size 2257840 bytes
Variable Size 603982928 bytes
Database Buffers 226492416 bytes
Redo Buffers 2371584 bytes
SQL> set lines 200
SQL> show parameter name
NAME TYPE VALUE
------------------------------------ ---------------------- ------------------------------
cell_offloadgroup_name string
db_file_name_convert string
db_name string RACZJDB
db_unique_name string RACZJDB
global_names boolean FALSE
instance_name string RACZJDB1
lock_name_space string
log_file_name_convert string
processor_group_name string
service_names string RACZJDB.oracle.com, srvdb1, zjdb1
SQL> alter database mount;
Database altered.
3. 開啓歸檔模式
SQL> alter database archivelog;
Database altered.
SQL> archive log list
Database log mode Archive Mode
Automatic archival Enabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 33
Next log sequence to archive 34
Current log sequence 34
4. 設置歸檔路徑
SQL> alter system set log_archive_dest_1="LOCATION=/oracle/arch01/RACZJDB1" sid='RACZJDB1';
System altered.
SQL> archive log list
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /oracle/arch01/RACZJDB1
Oldest online log sequence 33
Next log sequence to archive 34
Current log sequence 34
5. 打開數據庫
SQL> alter database open;
Database altered.
SQL> archive log list
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /oracle/arch01/RACZJDB1
Oldest online log sequence 33
Next log sequence to archive 34
Current log sequence 34
6. 查看數據庫狀態
SQL> select instance_name,status from v$instance;
INSTANCE_NAME STATUS
---------------- ------------
RACZJDB1 OPEN
7. 檢查是否開啓歸檔
SQL> select log_mode from v$database;
LOG_MODE
------------
ARCHIVELOG
8. 切歸檔並檢查是否有歸檔
SQL> alter system switch logfile;
System altered.
SQL> !ls -l /oracle/arch01/RACZJDB1/*
-rw-r----- 1 oracle oinstall 3599872 Oct 5 12:09 /oracle/arch01/RACZJDB1/1_34_978812479.dbf
RAC節點二 開啓歸檔
二. 基本步驟:
1. 建立歸檔目錄
2. RAC節點二 數據庫實例啓動到mount狀態
3. 開啓歸檔
4. 檢查歸檔
(敲黑板:如下代碼都可左右滑動查看&複製粘貼)
1. 規劃歸檔目錄
[oracle@RACZJ-DB02.example.com ~]cd /oracle/arch02/RACZJDB2
2. 將RAC節點2數據庫實例 RACZJDB2 啓動到mount狀態
[oracle@RACZJ-DB02.example.com]/oracle/arch02/RACZJDB2$sqlplus / as susdna
SQL*Plus: Release 11.2.0.4.0 Production on 星期五 10月 5 11:46:53 2018
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to an idle instance.
SQL> startup nomount
ORACLE instance started.
Total System Global Area 835104768 bytes
Fixed Size 2257840 bytes
Variable Size 637537360 bytes
Database Buffers 192937984 bytes
Redo Buffers 2371584 bytes
SQL> set lines 200
SQL> show parameter name
NAME TYPE VALUE
------------------------------------ ---------------------- ------------------------------
cell_offloadgroup_name string
db_file_name_convert string
db_name string RACZJDB
db_unique_name string RACZJDB
global_names boolean FALSE
instance_name string RACZJDB2
lock_name_space string
log_file_name_convert string
processor_group_name string
service_names string RACZJDB.oracle.com, srvdb2, zjdb2
SQL> alter database mount;
Database altered.
3. 開啓歸檔模式
SQL> alter database archivelog;
Database altered.
SQL> archive log list
Database log mode Archive Mode
Automatic archival Enabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 33
Next log sequence to archive 0
Current log sequence 34
4. 設置歸檔路徑
SQL> alter system set log_archive_dest_1="LOCATION=/oracle/arch02/RACZJDB2" sid='RACZJDB2';
System altered.
SQL> archive log list
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /oracle/arch02/RACZJDB2
Oldest online log sequence 33
Next log sequence to archive 0
Current log sequence 34
5. 打開數據庫
SQL> alter database open;
Database altered.
6. 查看數據庫狀態
SQL> select instance_name,status from v$instance;
INSTANCE_NAME STATUS
---------------- ------------
RACZJDB2 OPEN
7. 檢查是否開啓歸檔
SQL> select log_mode from v$database;
LOG_MODE
------------
ARCHIVELOG
8. 切歸檔並檢查是否有歸檔
SQL> alter system switch logfile;
System altered.
SQL> !ls -l /oracle/arch02/RACZJDB2/*
-rw-r----- 1 oracle oinstall 58368 10月 5 12:06 /oracle/arch02/RACZJDB2/2_35_978812479.dbf
總結
RAC數據庫開啓歸檔是一個一個節點分開進行的,第一個節點開啓歸檔後,接着到第二個節點開啓歸檔,這樣是否是很方便呢?
那何時須要開啓歸檔何時不須要開啓歸檔呢?說一個重點哈,若是你的數據庫是專門存儲歷史的數據,那是否是不須要開啓歸檔呢?