2013-10-08 9 views
7

Come posso ottenere le informazioni su tutti i tablespace nel mio database nel formato seguente.Come ottenere il nome di tutti i tablespace, Dimensioni allocate, Dimensioni libere, Capacità da una singola query?

TABLESPACE_NAME | FILE_NAME | ALLOCATED_MB | FREE_MB | CAPACITY | 

C'è modo di memorizzare automaticamente le dimensioni giornaliere di tutti gli spazi tabella in un'altra tabella ?. In realtà ho bisogno di preparare la lista di controllo per quanto riguarda lo spazio tavolo su base giornaliera. Così ho wan't per creare front-end che mi e-mail automaticamente i particolari di formato spazio tabella in base a quel tavolo che memorizzare le informazioni sulle dimensioni dello spazio di tabella sulla base quotidiana ..

+0

possibile duplicato di [Come faccio a calcolare dimensioni tabelle in Oracle] (http://stackoverflow.com/questions/264914/how-do-i-calculate-tables-size-in-oracle) – bgs

+0

Non essere confuso, sto cercando spazi tabella non per le dimensioni della tabella. – Regon

risposta

17

Prova la query seguente per ottenere tutti i dettagli dello spazio tabella in Oracle. Supponendo di disporre dei privilegi necessari per accedere alle tabelle dba.

SELECT a.file_name, 
     substr(A.tablespace_name,1,14) tablespace_name, 
     trunc(decode(A.autoextensible,'YES',A.MAXSIZE-A.bytes+b.free,'NO',b.free)/1024/1024) free_mb, 
     trunc(a.bytes/1024/1024) allocated_mb, 
     trunc(A.MAXSIZE/1024/1024) capacity, 
     a.autoextensible ae 
FROM (
    SELECT file_id, file_name, 
      tablespace_name, 
      autoextensible, 
      bytes, 
      decode(autoextensible,'YES',maxbytes,bytes) maxsize 
    FROM dba_data_files 
    GROUP BY file_id, file_name, 
       tablespace_name, 
       autoextensible, 
       bytes, 
       decode(autoextensible,'YES',maxbytes,bytes) 
    ) a, 
    (SELECT file_id, 
      tablespace_name, 
      sum(bytes) free 
     FROM dba_free_space 
     GROUP BY file_id, 
       tablespace_name 
    ) b 
WHERE a.file_id=b.file_id(+) 
AND A.tablespace_name=b.tablespace_name(+) 
ORDER BY A.tablespace_name ASC; 
+0

Con alcune modifiche questa query funziona perfettamente, ma esiste un modo per archiviare automaticamente queste informazioni in un'altra tabella piuttosto che eseguire Insert Query su base giornaliera. – Regon

+0

Attualmente non penso ci sia un'opzione per memorizzare automaticamente le informazioni. – Dba

+0

Invece, è possibile creare una procedura per confrontare la differenza nelle dimensioni del tablespace ed eseguire ogni giorno usando 'dbms_scheduler'. – Dba

1

In Oracle fare riferimento sotto il collegamento:

How do I calculate tables size in Oracle

https://forums.oracle.com/thread/2160787

COLUMN TABLE_NAME FORMAT A32 
COLUMN OBJECT_NAME FORMAT A32 
COLUMN OWNER FORMAT A10 

SELECT 
    owner, table_name, TRUNC(sum(bytes)/1024/1024) Meg 
FROM 
(SELECT segment_name table_name, owner, bytes 
FROM dba_segments 
WHERE segment_type = 'TABLE' 
UNION ALL 
SELECT i.table_name, i.owner, s.bytes 
FROM dba_indexes i, dba_segments s 
WHERE s.segment_name = i.index_name 
AND s.owner = i.owner 
AND s.segment_type = 'INDEX' 
UNION ALL 
SELECT l.table_name, l.owner, s.bytes 
FROM dba_lobs l, dba_segments s 
WHERE s.segment_name = l.segment_name 
AND s.owner = l.owner 
AND s.segment_type = 'LOBSEGMENT' 
UNION ALL 
SELECT l.table_name, l.owner, s.bytes 
FROM dba_lobs l, dba_segments s 
WHERE s.segment_name = l.index_name 
AND s.owner = l.owner 
AND s.segment_type = 'LOBINDEX') 
WHERE owner in UPPER('&owner') 
GROUP BY table_name, owner 
HAVING SUM(bytes)/1024/1024 > 10 /* Ignore really small tables */ 
ORDER BY SUM(bytes) desc 
; 

In SQL riferiscono sotto

012.

Get size of all tables in database

+0

Grazie, questo esattamente sto cercando ma non voglio elencare tutti i tablespace non lo spazio delle tabelle. – Regon

0
Select a.tablespace_name,a.file_name,a.bytes/1024/1024 TABLESPACE_SIZE_MB, 
Sum(b.bytes)/1024/1024 FREE_IN_MB from dba_free_space b,dba_data_files a 
Where a.tablespace_name = b.tablespace_name 
AND a.file_id = b.file_id 
GROUP by a.tablespace_name, a.file_name,a.bytes/1024/1024 
Order by a.tablespace_name, a.file_name; 

è possibile eseguire la query questo può aiutare.

0

Sopra sono utili. Spero che anche questo potrebbe utile qui:

https://ora-data.blogspot.in/2016/12/how-to-find-details-of-tablespace.html

controllare i dettagli Tablespace con comando diverso, al di sopra di comando potrebbe non funzionare:

SQL>select round((bytes/1024)/1024,0) "Used Space(MB)", 
round(total,0) "Allocated size(MB)", 
round(max,0) "Maximum allowable(MB)", 
round(max-(BYTES/1024)/1024,0) "Effective free(MB)", 
round(((max-(BYTES/1024)/1024)/max)*100,2) "FREE(%)" 
from SYS.SM$TS_USED, 
(select sum((BYTES/1024)/1024) total, sum((decode(MAXBYTES,0,bytes,maxbytes)/1024)/1024) max 
from dba_data_files where tablespace_name='&1') where tablespace_name='&1'; 
Problemi correlati