oracle表空间相关语句

1、查看表空间文件

        select * from dba_data_files;

2、查看用户的默认表空间

        select username,default_tablespace from dba_users;

3、查看表空间大小

select t.tablespace_name, round(SUM(bytes / (1024 * 1024)), 0) ts_size
  from dba_tablespaces t, dba_data_files d
 where t.tablespace_name = d.tablespace_name
 group by t.tablespace_name;

4、查看表空间使用情况

SELECT a.tablespace_name "表空间名",
       total / (1024 * 1024 * 1024) "表空间大小(G)",
       free / (1024 * 1024 * 1024) "表空间剩余大小(G)",
       (total - free) / (1024 * 1024 * 1024) "表空间使用大小(G)",
       round((total - free) / total, 4) * 100 "使用率 %"
  FROM (SELECT tablespace_name, SUM(bytes) free
          FROM dba_free_space
         GROUP BY tablespace_name) a,
       (SELECT tablespace_name, SUM(bytes) total
          FROM dba_data_files
         GROUP BY tablespace_name) b
 WHERE a.tablespace_name = b.tablespace_name;

5、创建表空间

create tablespace TSI_HSPS datafile :\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\TSI_HSPS_1.DAT' size 1g;

create tablespace dmusertbs
datafile 'i:\oracle\oradata\dmusertbs01.dbf' size 50M,
         'i:\oracle\oradata\dmusertbs02.dbf' size 50M,
         'i:\oracle\oradata\dmusertbs03.dbf' size 50M

    注意:Oracle 数据文件的扩展名没有任何限制,你可以使用任意扩展名,或者不用扩展名。

5. 扩展表空间

alter tablespace tablespace_name
            add datafile '表空间文件名' size 500M
            autoextend on
            next 50M
            maxsize 2000M;
增加了一个500M的数据文件,并且可以自动扩展到2000M,每次扩展50M。
增加当前数据文件的大小

alter database datafile '表空间文件' resize 500M;

猜你喜欢

转载自blog.csdn.net/u011955525/article/details/102712052
今日推荐