Oracle 快速創建 N 個表空間數據文件
oracle 數據庫是由無數個表空間組成,表空間是由無數個數據文件組成,數據文件存放在磁盤中。

隨著時間和業務量的增長,數據文件會不斷的增長,默認的數據文件一個為 32G,因此,需要不斷的新增數據文件!
那么,問題來了!
需要新增很多數據文件怎么辦?
以下示例以 LUCIFER 表空間進行演示!默認開啟 OMF!
?? 如何開啟 OMF 請參考:oracle OMF參數
1、新增一個數據文件,小意思,一行命令搞定!
alter tablespace LUCIFER add datafile size 30G autoextend off;
1
2、新增 10 個數據文件,麻煩點,復制 10 行也能搞定!
alter tablespace LUCIFER add datafile size 30G autoextend off; alter tablespace LUCIFER add datafile size 30G autoextend off; alter tablespace LUCIFER add datafile size 30G autoextend off; alter tablespace LUCIFER add datafile size 30G autoextend off; alter tablespace LUCIFER add datafile size 30G autoextend off; alter tablespace LUCIFER add datafile size 30G autoextend off; alter tablespace LUCIFER add datafile size 30G autoextend off; alter tablespace LUCIFER add datafile size 30G autoextend off; alter tablespace LUCIFER add datafile size 30G autoextend off; alter tablespace LUCIFER add datafile size 30G autoextend off;
1
2
3
4
5
6
7
8
9
10
3、新增 100 個數據文件,頭疼,復制 100 行?那 1000 個呢?10000個呢?
當然,只是打個比方,無需較真,只是為了說明一個理念!
像這種需要一次性增加多個表空間數據文件的,可以直接通過循環語句,短短幾行代碼就可以搞定:
begin for i in 1 .. 100 loop execute immediate 'alter tablespace LUCIFER add datafile size 30G autoextend off'; end loop; end; /
1
2
3
4
5
6
通過以上短短的代碼,就可以實現創建 100 個數據文件,如果需要 10000 個,就把 100 改成 10000 就行了!
如果你說你不使用 OMF 參數,當然可以,稍微改一下就行:
begin for i in 1 .. 100 loop execute immediate 'alter tablespace LUCIFER add datafile ''/oradata/orcl/lucifer'||i||'.dbf'' size 30G autoextend off'; end loop; end; /
1
2
3
4
5
6
只需要將數據文件路徑 /oradata/orcl/ 和 數據文件名稱 lucifer 拼接以下,然后傳入 i 作為編號即可!
?? 記住,本文講的是一個技巧,也是一個理念,不要鉆牛角尖!
本次分享到此結束啦~
如果覺得文章對你有幫助,
、、關注、評論
,一鍵四連支持,你的支持就是我創作最大的動力。
Oracle
版權聲明:本文內容由網絡用戶投稿,版權歸原作者所有,本站不擁有其著作權,亦不承擔相應法律責任。如果您發現本站中有涉嫌抄襲或描述失實的內容,請聯系我們jiasou666@gmail.com 處理,核實后本網站將在24小時內刪除侵權內容。
版權聲明:本文內容由網絡用戶投稿,版權歸原作者所有,本站不擁有其著作權,亦不承擔相應法律責任。如果您發現本站中有涉嫌抄襲或描述失實的內容,請聯系我們jiasou666@gmail.com 處理,核實后本網站將在24小時內刪除侵權內容。