[讀書筆記]ORACLE資料庫檔案管理

來源:互聯網
上載者:User

標籤:資料庫檔案   oracle   檔案管理   

  資料庫檔案包括資料檔案、記錄檔、控制檔案和密碼檔案、參數檔案等,對於這些檔案的管理可以看作是增刪改查的過程。

1.資料檔案管理

增:

新增資料表空間時增加資料檔案

create tablespace test_2016 datafile ‘/u01/app/oracle/oradata/orcl/test_01.dbf‘ size 10M autoextend on next 10M maxsize 100M;

    

資料表空間增加資料檔案

alter tablespace test_2016 add datafile ‘/u01/app/oracle/oradata/orcl/test_02.dbf‘ size 10M;

alter tablespace test_2016 add datafile ‘/u01/app/oracle/oradata/orcl/test_03.dbf‘ size 10M;


刪:

刪除某一個資料檔案

alter tablespace test_2016 drop datafile 7;

alter tablespace test_2016 drop datafile ‘/u01/app/oracle/oradata/orcl/test_02.dbf‘; 

資料檔案為空白時才能刪除。

刪除資料表空間:

drop tablespace test_2016 including contents and datafiles; 


改:改變物理檔案的位置

修改資料檔案的物理位置有兩種方法,一種是關機後修改物理位置,另一種offline後修改物理位置。

第一種方式:關機後修改物理檔案的位置

SQL> shutdown immediate;

[[email protected] orcl]$ mv test_0* ../

[[email protected] orcl]$ cd ..

[[email protected] oradata]$ ls

orcl  test_01.dbf  test_02.dbf

[[email protected] oradata]$ 

SQL> startup nomount;

SQL> alter database mount;

SQL> alter database rename file ‘/u01/app/oracle/oradata/orcl/test_01.dbf‘ to ‘/u01/app/oracle/oradata/test_01.dbf‘;

SQL> alter database rename file ‘/u01/app/oracle/oradata/orcl/test_02.dbf‘ to ‘/u01/app/oracle/oradata/test_02.dbf‘;

SQL> alter database open;

SQL> select file_name from dba_data_files where file_name like ‘%test%‘;

FILE_NAME

--------------------------------------------------------------------------------

/u01/app/oracle/oradata/test_01.dbf

/u01/app/oracle/oradata/test_02.dbf

第二種方式:資料表空間下線之後移動資料檔案

SQL>alter tablespace test_2016 offline;

作業系統中操作:

[[email protected] oradata]$ mv test_0* orcl/

[[email protected] oradata]$ cd orcl/

[[email protected] orcl]$ ls test_0*

test_01.dbf  test_02.dbf

SQL> alter database rename file ‘/u01/app/oracle/oradata/test_01.dbf‘ to ‘/u01/app/oracle/oradata/orcl/test_01.dbf‘;

SQL> alter database rename file ‘/u01/app/oracle/oradata/test_02.dbf‘ to ‘/u01/app/oracle/oradata/orcl/test_02.dbf‘;

SQL> alter tablespace test_2016 online;

查:

select file_name,file_id,online_status  from dba_data_files;

2.聯機重做記錄檔管理

增:

增加日誌成員:

alter database add logfile member ‘路徑‘ to group t;

SQL> alter database add logfile member ‘/u01/app/oracle/oradata/orcl/redo_11.log‘ to group 1;

記錄檔組增加:

alter database add logfile [group n] (‘路徑‘) size 100M;  

SQL> alter database add logfile ‘/u01/app/oracle/oradata/orcl/redo_04.log‘ size 50M;

SQL> alter database add logfile group 6 ‘/u01/app/oracle/oradata/orcl/redo_06.log‘ size 50M;#可以跨序列增加記錄檔組

刪:

刪除日誌成員:

alter database drop logfile member ‘路徑‘ 

SQL> alter database drop logfile member ‘/u01/app/oracle/oradata/orcl/redo_11.log‘;

刪除日誌組:

SQL>alter database drop logfile group 6;--只能刪除INACTIVE狀態的日誌組


改:

與其關掉資料庫去修改記錄檔的位置,不如直接在資料庫中添加新的記錄檔組,再刪除舊的檔案組。

查:

select * from v$log;

select * from v$logfile order by group#;

3.控制檔案管理

     控制檔案中記錄著資料庫的名稱,資料庫的物理布局:包括資料檔案的位置、聯機記錄檔、備份檔案以及資料庫當前SCN等重要訊息,在資料庫啟動的第二階段會讀入控制檔案。

    要求控制檔案有多個拷貝,以防單個檔案損壞後危害資料庫。當資料庫修改控制檔案時,所有拷貝都要同時被修改。

查看方式:

select * from v$controlfile;

show parameter control_files;

建立控制檔案副本的步驟:

1)修改參數檔案

alter system set control_files = ‘/u01/app/oracle/oradata/orcl/control01.ctl‘,‘/u01/app/oracle/flash_recovery_area/orcl/control02.ctl‘ scope=spfile;

alter system set control_files = ‘/u01/app/oracle/oradata/orcl/control01.ctl‘

2)停止資料庫

SQL> shutdown immediate;

3)複製控制檔案

[[email protected] yoon]$ cp /u01/app/oracle/oradata/orcl/control01.ctl /u01/app/oracle/flash_recovery_area/orcl/control02.ctl

4)啟動資料庫

SQL> statup

5)驗證,查看v$controlfile

SQL> select name from v$controlfile;

刪除控制檔案副本的步驟與建立的步驟相比,少了一步複製控制檔案。

4.密碼檔案管理:

詳見:密碼檔案總結

5.參數檔案管理

參數檔案分為靜態參數檔案(pfile)和動態參數檔案(Spile)兩種。pfile是文字文件,spfile是二進位檔案。

參數修改:

alter system set parameter=value [scope=spfile|memory|both]

scope中,spfile表示修改在spile檔案中,不影響當前設定;memory是立即修改當前設定,不會修改spile;both是同時修改了spfile和當前設定。

對於靜態參數,只能使用scope=spfile

Oracle啟動過程負載檔案順序: spfilesid.ora spfile.ora initsid.ora

參數檔案的位置:

show parameter spfile;

show parameter pfile;

參數檔案的建立:

create pfile=‘...‘;

create spile=‘...‘;

用指定的參數檔案啟動資料庫的方式:

startup pfile=‘...‘;

startup spfile=‘...‘;



本文出自 “三國冷笑話” 部落格,請務必保留此出處http://myhwj.blog.51cto.com/9763975/1796009

[讀書筆記]ORACLE資料庫檔案管理

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.