`
流浪鱼
  • 浏览: 1632951 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

表空间和数据文件创建

 
阅读更多

oracle物理结构:

数据文件: .dbf

日志文件: .log

控制文件:  .ctl

在oracle_base   oradata\instancename\

数据文件的管理由表空间管理

逻辑结构:  由表空间管理数据文件

一个数据库可有多个表空间,至少要有system表空间,一个表空间可有多个数据文件,至少要有一个数据文件

控制文件:select name from v$controlfile; 

日志文件: select * from v$logfile;

数据文件: select name from v$datafile;

表空间: select name from v$tablespace; 

创建表空间:

create tablespace user01
datafile 'e:\oracle\oradata\orcl\user01.dbf' size 10m;

表中的数据录入到表的所有者的默认表空间上


新建的用户默认表空间:users表空间

查询表空间和数据文件的对应关系:

select h1.name, h2.name from v$tablespace h1 join v$datafile h2 on h1.ts# = h2.ts#;

查询表属于某个表空间;

selct table_name, tablespace_name from user_tables where table_name = 'T3';

 

 create undo tablespace undo01
 datafile 'e:\oracle\oradata\orcl\undo01.dbf' size 10m;

create temporary tablespace temp1
tempfile 'e:\oracle\oradata\orcl\temp01.dbf' size 10m;


alter tablespace user01 offline;  online  read only

drop tablespace user01;只删除表空间而不回删除数据文件,也就是说e:\oracle\oradata\orcl\user01.dbf
                        文件还在了!

 

drop tablespace user01 including contents and datafiles;这样的话数据表也没有了!


 alter database datafile 'e:\oracle\oradata\orcl\user02.dbf' resize 20m;

SQL> select h1.name, h2.name from v$tablespace h1 join v$datafile h2 on h1.ts#=
h2.ts# where h1.name=upper('user01');


SQL> alter tablespace user01 add datafile 'e:\oracle\oradata\orcl\user03.dbf' si
ze 20m;这做方法是用来给user01表空间再添加一个数据文件当上一个数据文件用完了以后,再用这个文件。

 

查看表空间的使用情况

select a.file_id "FileNo",
       a.tablespace_name "Tablespace_name", round(a.bytes/1024/1024,4) "Total MB",
       round((a.bytes-sum(nvl(b.bytes,0)))/1024/1024,4) "Used MB",
       round(sum(nvl(b.bytes,0))/1024/1024,4) "Free MB",
       round(sum(nvl(b.bytes,0))/a.bytes*100,4) "%Free"
            from dba_data_files a, dba_free_space b
            where a.file_id=b.file_id(+)
            group by a.tablespace_name,
            a.file_id,a.bytes order by a.tablespace_name

 

 

 

 

 

 

 

 

 

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics