15

我有一个包含三个表的数据库。我需要将历史分区数据移动到其他模式现在我正计划创建新的“历史”表。我不知道如何测量分区和子分区的大小。你能帮我吗?请给我一些建议。

提前致谢。娄

4

4 回答 4

46

以下查询可用于确定表空间和其他参数:

select df.tablespace_name "Tablespace",
       totalusedspace "Used MB",
       (df.totalspace - tu.totalusedspace) "Free MB",
       df.totalspace "Total MB",
       round(100 * ( (df.totalspace - tu.totalusedspace)/ df.totalspace)) "Pct. Free"
  from (select tablespace_name,
               round(sum(bytes) / 1048576) TotalSpace
          from dba_data_files 
         group by tablespace_name) df,
       (select round(sum(bytes)/(1024*1024)) totalusedspace,
               tablespace_name
          from dba_segments 
         group by tablespace_name) tu
 where df.tablespace_name = tu.tablespace_name 
   and df.totalspace <> 0;

来源:https ://community.oracle.com/message/1832920

对于您的情况,如果您想知道分区名称及其大小,只需运行以下查询:

select owner,
       segment_name,
       partition_name,
       segment_type,
       bytes / 1024/1024 "MB" 
  from dba_segments 
 where owner = <owner_name>;
于 2013-02-27T15:01:02.113 回答
17

一种方法是使用下面的 sql 查询

--Size of All Table Space

--1. Used Space
SELECT TABLESPACE_NAME,TO_CHAR(SUM(NVL(BYTES,0))/1024/1024/1024, '99,999,990.99') AS "USED SPACE(IN GB)" FROM USER_SEGMENTS GROUP BY TABLESPACE_NAME
--2. Free Space
SELECT TABLESPACE_NAME,TO_CHAR(SUM(NVL(BYTES,0))/1024/1024/1024, '99,999,990.99') AS "FREE SPACE(IN GB)" FROM   USER_FREE_SPACE GROUP BY TABLESPACE_NAME

--3. Both Free & Used
SELECT USED.TABLESPACE_NAME, USED.USED_BYTES AS "USED SPACE(IN GB)",  FREE.FREE_BYTES AS "FREE SPACE(IN GB)"
FROM
(SELECT TABLESPACE_NAME,TO_CHAR(SUM(NVL(BYTES,0))/1024/1024/1024, '99,999,990.99') AS USED_BYTES FROM USER_SEGMENTS GROUP BY TABLESPACE_NAME) USED
INNER JOIN
(SELECT TABLESPACE_NAME,TO_CHAR(SUM(NVL(BYTES,0))/1024/1024/1024, '99,999,990.99') AS FREE_BYTES FROM  USER_FREE_SPACE GROUP BY TABLESPACE_NAME) FREE
ON (USED.TABLESPACE_NAME = FREE.TABLESPACE_NAME);
于 2014-12-04T06:35:47.940 回答
0

SELECT b.tablespace_name, tbs_size SizeGb, a.free_space FreeGb FROM ( SELECT tablespace_name, ROUND (SUM (bytes) / 1024 / 1024 / 1024, 2) AS free_space FROM dba_free_space GROUP BY tablespace_name) a, ( SELECT tablespace_name, SUM (bytes) / 1024 / 1024 / 1024 AS tbs_size FROM dba_data_files GROUP BY tablespace_name) b WHERE a.tablespace_name(+) = b.tablespace_name ORDER BY 1

于 2021-04-13T18:36:52.093 回答
0

在 oracle 中检查表空间大小的一种方法是运行此查询

SELECT   TABLESPACE_NAME, ROUND (SUM (BYTES) / 1048576) "Total Size MB"
    FROM     DBA_DATA_FILES
    GROUP BY TABLESPACE_NAME
于 2021-04-05T22:19:03.957 回答