oracle datafilereuse,Oracle 数据文件 reuse 属性 说明
Oracle表空間創(chuàng)建參數(shù)說(shuō)明
當(dāng)我們對(duì)表空間添加數(shù)據(jù)文件的時(shí)候,有一個(gè)reuse屬性。 10g的官網(wǎng)對(duì)這個(gè)參數(shù)的說(shuō)明如下:
REUSE
Specify REUSE to allow Oracle to reuse an existing file.
(1)If the file already exists, then Oracle reuses the filename and applies the new size (if you specify SIZE) or retains the original size.
--如果file已經(jīng)存在,并且在創(chuàng)建時(shí)指定了file size,那么就重用原文件,并應(yīng)用新的size,如果沒(méi)有指定file size,則保留原有的大小。
(2)If the file does not exist, then Oracle ignores this clause and creates the file.
--如果file不存在,oracle將忽略該參數(shù)。
Restriction on the REUSE Clause
You cannot specify REUSE unless you have specified filename.
Whenever Oracle uses an existing file, the previous contents of the file are lost.
--如果Oracle使用了已經(jīng)存在的file,那么之前file里的數(shù)據(jù)將全部丟失。
From:
在Oracle 11g的官方文檔里沒(méi)有搜到相關(guān)的信息。 因?yàn)槭诸^還沒(méi)有11g的庫(kù),所以也不好測(cè)試。 這篇blog里測(cè)試的是基于Oracle 10g環(huán)境。
下面我們來(lái)做一些測(cè)試:
1.創(chuàng)建一個(gè)表空間Dave
SQL> show user;
USER is "SYS"
SQL> create tablespace dave datafile '/u01/app/oracle/oradata/dave2/dave01.dbf' size 100M;
Tablespace created.
2.創(chuàng)建表anqing,并指定存儲(chǔ)表空間dave
SQL> create table anqing tablespace dave as select * from dba_objects;
Table created.
SQL> commit;
Commit complete.
SQL> select count(*) from anqing;
COUNT(*)
50391
SQL> set wrap off;
SQL> select owner,table_name,tablespace_name from dba_tables where table_name='ANQING';
OWNERTABLE_NAMETABLESPACE_NAME
------------------------------ ------------------------------ ------------------
3.對(duì)表空間dave添加一個(gè)新的數(shù)據(jù)文件,并使用reuse
SQL>alter tablespace dave add datafile '/u01/app/oracle/oradata/dave2/dave02.dbf' reuse;
alter tablespace dave add datafile '/u01/app/oracle/oradata/dave2/dave02.dbf' reuse
*
ERROR at line 1:
ORA-01119: error in creating database file '/u01/app/oracle/oradata/dave2/dave02.dbf'
ORA-17610: file '/u01/app/oracle/oradata/dave2/dave02.dbf' does not exist and no size specified ORA-27037: unable to obtain file status Linux Error: 2: No such file or directory Additional information: 3
--這種情況下,如果文件存在,會(huì)使用原始文件的大小。但dave02.dbf不存在,我們又沒(méi)有指定文件大小,所以無(wú)法創(chuàng)建。我們指定size就可以創(chuàng)建了。
SQL> alter tablespace dave add datafile '/u01/app/oracle/oradata/dave2/dave02.dbf' size 50M reuse;
Tablespace altered.
SQL>
4.保持表空間的狀態(tài),然后使用reuse來(lái)添加數(shù)據(jù)文件https://www.cndba.cn/Dave/article/1140
SQL>alter tablespace dave add datafile '/u01/app/oracle/oradata/dave2/dave01.dbf' size 50M reuse;
alter tablespace dave add datafile '/u01/app/oracle/oradata/dave2/dave01.dbf' size 50M reuse
*
ERROR at line 1:
ORA-01537: cannot add file '/u01/app/oracle/oradata/dave2/dave01.dbf' - file already part of database
--報(bào)錯(cuò),所以即使我們需要使用reuse,前提也是該數(shù)據(jù)文件已經(jīng)不存在該表空間了。
5.先將datafile offline drop,在reuse
offline drop并不會(huì)drop datafile,僅僅是將datafile標(biāo)記為offline,我們online之后還可以recover回來(lái)。 具體參考:
alter database datafile offline drop與alter tablespace drop datafile區(qū)別
SQL> alter database datafile '/u01/app/oracle/oradata/dave2/dave01.dbf' offline drop;
Database altered.
SQL> alter tablespace dave add datafile '/u01/app/oracle/oradata/dave2/dave01.dbf' size 50M reuse;
alter tablespace dave add datafile '/u01/app/oracle/oradata/dave2/dave01.dbf' size 50M reuse
*
ERROR at line 1:
ORA-01537: cannot add file '/u01/app/oracle/oradata/dave2/dave01.dbf' - file already part of database
--依舊報(bào)錯(cuò),因?yàn)榇藭r(shí)數(shù)據(jù)文件dave01.dbf的信息還記錄在數(shù)據(jù)字典里。
--將數(shù)據(jù)文件還原回來(lái)
SQL> alter database datafile '/u01/app/oracle/oradata/dave2/dave01.dbf' online;
alter database datafile '/u01/app/oracle/oradata/dave2/dave01.dbf' online
*
ERROR at line 1:
ORA-01113: file 6 needs media recovery
ORA-01110: data file 6: '/u01/app/oracle/oradata/dave2/dave01.dbf'
SQL> recover datafile 6;
Media recovery complete.
6.使用alter tablespace dave drop datafile命令
該命令在刪除控制文件和物理文件,所以沒(méi)有可用的意義。
SQL> alter tablespace dave drop datafile'/u01/app/oracle/oradata/dave2/dave02.dbf';
Tablespace altered.
[oracle@db2 dave2]$ pwd
/u01/app/oracle/oradata/dave2
[oracle@db2 dave2]$ ls
control01.ctlcontrol03.ctlexample01.dbfredo01.logredo03.logsystem01.dbfundotbs01.dbf
control02.ctldave01.dbfhuaining01.dbfredo02.logsysaux01.dbftemp01.dbfusers01.dbf
--文件已經(jīng)不存在
https://www.cndba.cn/Dave/article/1140
7.刪除表空間后,在reuse
命令如下:
SQL>drop tablespace dave including contents and datafiles;
該命令也可以指定同時(shí)刪除物理文件,但那樣我們的測(cè)試就沒(méi)辦法完成,所以我們不刪除datafile,僅從控制文件里刪除表空間。
SQL> drop tablespace dave including contents;https://www.cndba.cn/Dave/article/1140https://www.cndba.cn/Dave/article/1140
Tablespace dropped.
SQL> create tablespace dave2 datafile '/u01/app/oracle/oradata/dave2/dave01.dbf' size 50M reuse;
Tablespace created.
--重用成功
看一下數(shù)據(jù)文件大小:
[oracle@db2 dave2]$ ll -h dave01.dbf
-rw-r----- 1 oracle oinstall 51M Jun3 04:31 dave01.dbf
我們之前是100M,現(xiàn)在變成50M了。
-------------------------------------------------------------------------------------------------------
Blog:http://blog.csdn.net/tianlesoftware
Email: dvd.dba@gmail.com
DBA1群:62697716(滿);DBA2群:62697977(滿)DBA3群:62697850(滿)
DBA超級(jí)群:63306533(滿);DBA4群:83829929DBA5群:142216823
DBA6群:158654907聊天 群:40132017聊天2群:69087192
--加群需要在備注說(shuō)明Oracle表空間和數(shù)據(jù)文件的關(guān)系,否則拒絕申請(qǐng)
版權(quán)聲明:本文為博主原創(chuàng)文章,未經(jīng)博主允許不得轉(zhuǎn)載。
oracle 11g
總結(jié)
以上是生活随笔為你收集整理的oracle datafilereuse,Oracle 数据文件 reuse 属性 说明的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 抹茶拿铁热量是多少
- 下一篇: 柿子和鸡蛋能一起吃吗