美文网首页数据库
Oracle临时表空间查看、添加临时表空间数据文件、修改默认临时

Oracle临时表空间查看、添加临时表空间数据文件、修改默认临时

作者: 数据与人 | 来源:发表于2021-07-30 09:07 被阅读0次

    --查表空间使用率情况(含临时表空间)
    SELECT d.tablespace_name "Name", d.status "Status",
    TO_CHAR (NVL (a.BYTES / 1024 / 1024, 0), '99,999,990.90') "Size (M)",
    TO_CHAR (NVL (a.BYTES - NVL (f.BYTES, 0), 0) / 1024 / 1024,
    '99999999.99'
    ) USE,
    TO_CHAR (NVL ((a.BYTES - NVL (f.BYTES, 0)) / a.BYTES * 100, 0),
    '990.00'
    ) "Used %"
    FROM SYS.dba_tablespaces d,
    (SELECT tablespace_name, SUM (BYTES) BYTES
    FROM dba_data_files
    GROUP BY tablespace_name) a,
    (SELECT tablespace_name, SUM (BYTES) BYTES
    FROM dba_free_space
    GROUP BY tablespace_name) f
    WHERE d.tablespace_name = a.tablespace_name(+)
    AND d.tablespace_name = f.tablespace_name(+)
    AND NOT (d.extent_management LIKE 'LOCAL' AND d.CONTENTS LIKE 'TEMPORARY')
    UNION ALL
    SELECT d.tablespace_name "Name", d.status "Status",
    TO_CHAR (NVL (a.BYTES / 1024 / 1024, 0), '99,999,990.90') "Size (M)",
    TO_CHAR (NVL (t.BYTES, 0) / 1024 / 1024, '99999999.99') USE,
    TO_CHAR (NVL (t.BYTES / a.BYTES * 100, 0), '990.00') "Used %"
    FROM SYS.dba_tablespaces d,
    (SELECT tablespace_name, SUM (BYTES) BYTES
    FROM dba_temp_files
    GROUP BY tablespace_name) a,
    (SELECT tablespace_name, SUM (bytes_cached) BYTES
    FROM v$temp_extent_pool
    GROUP BY tablespace_name) t
    WHERE d.tablespace_name = a.tablespace_name(+)
    AND d.tablespace_name = t.tablespace_name(+)
    AND d.extent_management LIKE 'LOCAL'
    AND d.CONTENTS LIKE 'TEMPORARY';

    1. 查询表空间剩余字节大小
      SELECT TABLESPACE_NAME, SUM(BYTES)/1024/1024 AS "FREE SPACE(M)"
      FROM DBA_FREE_SPACE
      WHERE TABLESPACE_NAME = '&tablespace_name'
      GROUP BY TABLESPACE_NAME;
      注:如果是临时表空间,请查询DBA_TEMP_FREE_SPACE
      SELECT TABLESPACE_NAME, FREE_SPACE/1024/1024 AS "FREE SPACE(M)"
      FROM DBA_TEMP_FREE_SPACE
      WHERE TABLESPACE_NAME = '&tablespace_name';

    2. 查询表空间所有数据文件路径
      SELECT TABLESPACE_NAME, FILE_ID, FILE_NAME, BYTES/1024/1024 AS "BYTES(M)"
      FROM DBA_DATA_FILES
      WHERE TABLESPACE_NAME = '&tablespace_name';
      注:如果是临时表空间,请查询DBA_TEMP_FILES
      SELECT TABLESPACE_NAME, FILE_ID, FILE_NAME, BYTES/1024/1024 AS "SPACE(M)"
      FROM DBA_TEMP_FILES
      WHERE TABLESPACE_NAME = '&tablespace_name';

    3. 为空间不足的表空间增加数据文件
      ALTER TABLESPACE &tablespace_name ADD DATAFILE '&datafile_name' SIZE 2G;
      注:如果要为临时表空间扩容,使用下面的语句
      ALTER TABLESPACE &tablespace_name ADD TEMPFILE '&datafile_name' SIZE 2G;

    4.查看临时表空间的大小 和 数据文件路径
    SELECT TABLESPACE_NAME, FILE_ID, FILE_NAME, BYTES/1024/1024 AS "SPACE(M)"
    FROM DBA_TEMP_FILES
    WHERE TABLESPACE_NAME = 'TEMP';
    或者
    select name, bytes/1024/1024 as "大小(M)" from v$tempfile order by bytes;

    5.重建并修改默认临时表空间办法:
    --查询当前数据库默认临时表空间名
    select * from database_properties where property_name='DEFAULT_TEMP_TABLESPACE';
    --创建新的临时表空间
    create temporary tablespace temp02 tempfile 'E:\oracle\oradata\lims\TEMP02.DBF' size 1024M autoextend on;
    --修改默认表空间为刚刚建立的临时表空间
    alter database default temporary tablespace temp02;
    --查看用户所用临时表空间的情况
    SELECT USERNAME,TEMPORARY_TABLESPACE FROM DBA_USERS;
    --删除原来的临时表空间
    drop tablespace temp including contents and datafiles;
    --查看所有表空间名确认临时表空间是否已删除
    select tablespace_name from dba_tablespaces;

    相关文章

      网友评论

        本文标题:Oracle临时表空间查看、添加临时表空间数据文件、修改默认临时

        本文链接:https://www.haomeiwen.com/subject/eeyqvltx.html