Oracle 数据库是由无数个表空间组成,表空间是由无数个数据文件组成,数据文件存放在磁盘中。
随着时间和业务量的增长,数据文件会不断的增长,默认的数据文件一个为 32G,因此,需要不断的新增数据文件!
那么,问题来了!需要新增很多数据文件怎么办?
以下示例以 LUCIFER 表空间进行演示!默认 开启 OMF!
⭐️ 如何开启 OMF 请参考:Oracle OMF参数
1、新增一个数据文件,小意思,一行命令搞定!
1 2 3 4 5 alter tablespace LUCIFER add datafile size 30 G autoextend off ; AI写代码sql * 1
2、新增 10 个数据文件,麻烦点,复制 10 行也能搞定!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 alter tablespace LUCIFER add datafile size 30 G autoextend off ;alter tablespace LUCIFER add datafile size 30 G autoextend off ;alter tablespace LUCIFER add datafile size 30 G autoextend off ;alter tablespace LUCIFER add datafile size 30 G autoextend off ;alter tablespace LUCIFER add datafile size 30 G autoextend off ;alter tablespace LUCIFER add datafile size 30 G autoextend off ;alter tablespace LUCIFER add datafile size 30 G autoextend off ;alter tablespace LUCIFER add datafile size 30 G autoextend off ;alter tablespace LUCIFER add datafile size 30 G autoextend off ;alter tablespace LUCIFER add datafile size 30 G autoextend off ; AI写代码sql * 1 * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9 * 10
3、新增 100 个数据文件,头疼,复制 100 行?那 1000 个呢?10000个呢❓
当然,只是打个比方,无需较真,只是为了说明一个理念!
像这种需要一次性增加多个表 空间数据 文件的,可以直接通过循环语句,短短几行代码就可以搞定:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 begin for i in 1 .. 100 loop execute immediate 'alter tablespace LUCIFER add datafile size 30G autoextend off'; end loop; end; / AI写代码sql * 1 * 2 * 3 * 4 * 5 * 6
通过以上短短的 代码 ,就可以实现创建 100 个数据文件,如果需要 10000 个,就把 100 改成 10000 就行了!
如果你说你不使用 OMF 参数,当然可以,稍微改一下就行:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 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; / AI写代码sql
只需要将数据文件路径 /oradata/orcl/ 和 数据文件名称 lucifer 拼接以下,然后传入 i 作为编号即可!
❤️ 记住,本文讲的是一个技巧,也是一个理念,不要钻牛角尖!
本次分享到此结束啦~
如果觉得文章对你有帮助,点赞、收藏、关注、评论 ,一键四连支持,你的支持就是我创作最大的动力。
❤️ 技术 交流可以 关注公众号:Lucifer三思而后行 ❤️