日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

oracle datafilereuse,Oracle 数据文件 reuse 属性 说明

發布時間:2024/9/18 编程问答 41 豆豆
生活随笔 收集整理的這篇文章主要介紹了 oracle datafilereuse,Oracle 数据文件 reuse 属性 说明 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Oracle表空間創建參數說明

當我們對表空間添加數據文件的時候,有一個reuse屬性。 10g的官網對這個參數的說明如下:

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已經存在,并且在創建時指定了file size,那么就重用原文件,并應用新的size,如果沒有指定file size,則保留原有的大小。

(2)If the file does not exist, then Oracle ignores this clause and creates the file.

--如果file不存在,oracle將忽略該參數。

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使用了已經存在的file,那么之前file里的數據將全部丟失。

From:

在Oracle 11g的官方文檔里沒有搜到相關的信息。 因為手頭還沒有11g的庫,所以也不好測試。 這篇blog里測試的是基于Oracle 10g環境。

下面我們來做一些測試:

1.創建一個表空間Dave

SQL> show user;

USER is "SYS"

SQL> create tablespace dave datafile '/u01/app/oracle/oradata/dave2/dave01.dbf' size 100M;

Tablespace created.

2.創建表anqing,并指定存儲表空間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.對表空間dave添加一個新的數據文件,并使用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

--這種情況下,如果文件存在,會使用原始文件的大小。但dave02.dbf不存在,我們又沒有指定文件大小,所以無法創建。我們指定size就可以創建了。

SQL> alter tablespace dave add datafile '/u01/app/oracle/oradata/dave2/dave02.dbf' size 50M reuse;

Tablespace altered.

SQL>

4.保持表空間的狀態,然后使用reuse來添加數據文件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

--報錯,所以即使我們需要使用reuse,前提也是該數據文件已經不存在該表空間了。

5.先將datafile offline drop,在reuse

offline drop并不會drop datafile,僅僅是將datafile標記為offline,我們online之后還可以recover回來。 具體參考:

alter database datafile offline drop與alter tablespace drop datafile區別

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

--依舊報錯,因為此時數據文件dave01.dbf的信息還記錄在數據字典里。

--將數據文件還原回來

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命令

該命令在刪除控制文件和物理文件,所以沒有可用的意義。

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

--文件已經不存在

https://www.cndba.cn/Dave/article/1140

7.刪除表空間后,在reuse

命令如下:

SQL>drop tablespace dave including contents and datafiles;

該命令也可以指定同時刪除物理文件,但那樣我們的測試就沒辦法完成,所以我們不刪除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.

--重用成功

看一下數據文件大小:

[oracle@db2 dave2]$ ll -h dave01.dbf

-rw-r----- 1 oracle oinstall 51M Jun3 04:31 dave01.dbf

我們之前是100M,現在變成50M了。

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

Blog:http://blog.csdn.net/tianlesoftware

Email: dvd.dba@gmail.com

DBA1群:62697716(滿);DBA2群:62697977(滿)DBA3群:62697850(滿)

DBA超級群:63306533(滿);DBA4群:83829929DBA5群:142216823

DBA6群:158654907聊天 群:40132017聊天2群:69087192

--加群需要在備注說明Oracle表空間和數據文件的關系,否則拒絕申請

版權聲明:本文為博主原創文章,未經博主允許不得轉載。

oracle 11g

總結

以上是生活随笔為你收集整理的oracle datafilereuse,Oracle 数据文件 reuse 属性 说明的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。