zoukankan      html  css  js  c++  java
  • Oracle基础 01 表空间 tablespace

    --查看表空间

    select * from dba_tablespaces; 
    select * from v$tablespace;

    select * from dba_data_files; --查看数据文件
    select * from v$datafile;

    select * from dba_temp_files; --查看临时文件
    select * from v$tempfile;


    --查默认表空间和临时表空间

    select * from database_properties
    where property_name like '%TABLESPACE';

    alter user scott default tablespace emp;    --修改soctt默认表空间为emp
    grant unlimited tablespace to scott;        --授予scott表空间操纵权限


    --创建表空间emp

    create tablespace emp                     
    datafile '/u01/app/oracle/db/emp01.dbf' size 50m autoextend on next 10m maxsize unlimited;  
     

    --表空间组

    select * from dba_tablespace_groups;             --查看表空间组

    alter tablespace tmp01 tablespace group group1;  --将临时表空间tmp01添加到表空间组group1
    alter tablespace tmp02 tablespace group '';      --将临时表空间tmp02从表空间组group1中删除


    --表空间离线、在线

    alter tablespace emp offline normal;         --表空间归档模式离线
    alter tablespace emp offline normal for drop;   --表空间非归档模式离线(慎用)

    alter tablespace emp online;           --表空间在线


    --重命名表空间

    alter tablespace tsname1 rename to tsname2;    --表空间重命名tsname1 成tsname2


    --删除表空间

    drop tablespace emp including contents and datafiles;   --删除表空间和数据文件


    --数据文件的移动 

    alter tablespace emp offline normal;                                               --先将表空间离线

    mv /u01/app/oracle/oradata/dbtest/emp_data.dbf /u01/app/oracle/datafile/           --再移动数据文件到指定目录(linux下) 

    alter tablespace emp rename datafile'/u01/app/oracle/oradata/dbtest/emp_data.dbf'   
    to '/u01/app/oracle/datafile/yd03_data.dbf';                                       --修改控制文件信息                                  
    alter tablespace emp online;                                                       --再将表空间上线                                                


    --增加数据文件

    alter tablespace emp add datafile '/u01/app/oracle/oradata/emp02.dbf'
    size 10m;


    --增大数据文件

    alter database datafile '/u01/app/oracle/oradata/emp01.dbf' resize 50m;


    --删除数据文件

    alter tablespace emp drop datafile '/u01/app/oracle/emp02.dbf';


    --关闭数据文件自动扩展

    alter database datafile '/u01/app/oracle/emp01.dbf' autoextend off;

     
    --查看表空间使用情况语句

    select upper(f.tablespace_name) "ts-name",
           d.tot_grootte_mb "ts-bytes(m)",
           d.tot_grootte_mb - f.total_bytes "ts-used (m)",
           f.total_bytes "ts-free(m)",
           to_char(round((d.tot_grootte_mb - f.total_bytes) / d.tot_grootte_mb * 100,
                         2),
                   '990.99') "ts-per"
             from (select tablespace_name,
                   round(sum(bytes) / (1024 * 1024), 2) total_bytes,
                   round(max(bytes) / (1024 * 1024), 2) max_bytes
              from sys.dba_free_space
             group by tablespace_name) f,
           (select dd.tablespace_name,
                   round(sum(dd.bytes) / (1024 * 1024), 2) tot_grootte_mb
              from sys.dba_data_files dd
             group by dd.tablespace_name) d
    where d.tablespace_name = f.tablespace_name
    order by 5 desc;

    SYS@ test11g> select tablespace_name,sum(bytes)/1024/1024 free_m
      2  from dba_free_space
      3  group by tablespace_name;

    TABLESPACE_NAME      FREE_M
    ---------------- ----------
    SYSAUX               35.125
    UNDOTBS1                 82
    USERS                  .875
    SYSTEM               9.8125
    EXAMPLE               21.25

  • 相关阅读:
    how to pass a Javabean to server In Model2 architecture.
    What is the Web Appliation Archive, abbreviation is "WAR"
    Understaning Javascript OO
    Genetic Fraud
    poj 3211 Washing Clothes
    poj 2385 Apple Catching
    Magic Star
    关于memset的用法几点
    c++ 函数
    zoj 2972 Hurdles of 110m
  • 原文地址:https://www.cnblogs.com/john2017/p/6364421.html
Copyright © 2011-2022 走看看