Oracle temporary table space to view, add, delete, temporary table space data file, modify the default temporary table space method!

Original link: https://blog.csdn.net/qq_26425583/article/details/87860004

--查表空间使用率情况(含临时表空间)
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. The size of the lookup table space remaining bytes
the SELECT TABLESPACE_NAME, the SUM (BYTES) / 1024/1024 the AS "the FREE the SPACE (M)"
  the FROM DBA_FREE_SPACE
 the WHERE TABLESPACE_NAME = '& tablespace_name'
 the GROUP BY TABLESPACE_NAME;
Note: If the temporary table space, consult DBA_TEMP_FREE_SPACE
the SELECT tABLESPACE_NAME, FREE_SPACE / 1024/1024 the AS "the FREE the SPACE (M)"
  the FROM DBA_TEMP_FREE_SPACE
 the WHERE tABLESPACE_NAME = '& tablespace_name';

2. Query table space for all data file paths
the SELECT TABLESPACE_NAME, FILE_ID, FILE_NAME, BYTES / 1024/1024 the AS "BYTES (M)"
  the FROM the DBA_DATA_FILES
 the WHERE TABLESPACE_NAME = '& tablespace_name';
Note: If the temporary table space, query DBA_TEMP_FILES
the SELECT TABLESPACE_NAME , FILE_ID, FILE_NAME, BYTES / 1024/1024 the AS "the SPACE (M)"
  the FROM DBA_TEMP_FILES
 the WHERE tABLESPACE_NAME = '& tablespace_name';

3. Add a data file is insufficient space table space
ALTER TABLESPACE & tablespace_name ADD DATAFILE '& datafile_name' SIZE 2G;
Note: If you want to temporary table space expansion, use the following statement
ALTER TABLESPACE & tablespace_name ADD TEMPFILE '& datafile_name' SIZE 2G;

4. Check the size of the temporary table space data file path and
the SELECT TABLESPACE_NAME, FILE_ID, FILE_NAME, BYTES / 1024/1024 the AS "the SPACE (M)"
  the FROM DBA_TEMP_FILES
 the WHERE TABLESPACE_NAME = 'the TEMP';
or
select name, bytes / 1024/1024 as "size (M)" from v $ tempfile order by bytes;

5. rebuild and modify the default temporary table space way:
- query the current database default temporary table space name
the SELECT * from DATABASE_PROPERTIES the WHERE property_name = 'DEFAULT_TEMP_TABLESPACE';
- create a new temporary tablespace
create temporary tablespace temp02 tempfile 'E: \ oracle \ oradata \ LIMS \ TEMP02.DBF 'size 1024M AUTOEXTEND ON;
- modify the default table space for just created temporary table space for
the ALTER tABLESPACE temp02 the temporary Database default;
- view the user temporary table space with the situation
SELECT USERNAME, tEMPORARY_TABLESPACE FROM DBA_USERS ;
- delete the original temporary table space
drop the TEMP tABLESPACE Including Contents and the Datafiles;
- see all table space to confirm whether the temporary table space is deleted
the SELECT tablespace_name from 
dba_tablespaces; -------------- -
the Oracle data files deleted

table space alter tablespace drop datafile 'data files path';
If you want to delete the temporary files, you can use the following command

alter tablespace temporary table space name drop tempfile 'temporary file location';
you can also use the following command to delete the temporary files

alter database tempfile 'temporary file path' drop including datafiles;

These free e-book download

"Graphic HTTP"
"You do not know JavaScript,"
"the Java core technology Volume I"

"Oracle11g from the entry to the master."

"Java programming ideas"

Guess you like

Origin blog.csdn.net/zhishijike/article/details/100283788