How table rows are spread in datafiles

Summary 

One table is stored in one tablespace. But one tablespace can have one or more datafiles. How many records of the table are stored in each datafile. 

Example 

1. Create a tablespace with 3 datafiles

CREATE TABLESPACE EXAMPLES DATAFILE 
  '/oraprom1/datafiles/entoles01.dbf' SIZE 100M AUTOEXTEND OFF,
  '/oraprom2/datafiles/entoles02.dbf' SIZE 100M AUTOEXTEND OFF, 
  '/oraprom3/datafiles/entoles03.dbf' SIZE 100M AUTOEXTEND OFF LOGGING
ONLINE
PERMANENT
EXTENT MANAGEMENT LOCAL UNIFORM SIZE 1M
BLOCKSIZE 8K
SEGMENT SPACE MANAGEMENT MANUAL;
2. Create table ATHINA.ENTOLES stored in EXAMPLES tablespace.
CREATE TABLE ATHINA.ENTOLES TABLESPACE EXAMPLES 
AS SELECT * FROM ALL_OBJECTS;
3. How many records from table ATHINA.ENTOLES is stored in every datafile?
SELECT NAME FILENAME, COUNT "ROWS", ROUND((RATIO_TO_REPORT(COUNT) OVER ())*100, 2)|| '%' PERC_ROWS 
FROM (SELECT NAME ,t.COUNT FROM
v$datafile d, (SELECT COUNT(*) COUNT ,Dbms_Rowid.rowid_relative_fno(ROWID) FILE#
FROM athina.entoles GROUP BY Dbms_Rowid.rowid_relative_fno(ROWID)) t
WHERE t.FILE#=d.FILE#);


Output

FILENAME                                                  ROWS          PERC_ROWS
-----------------------------------------------------------------------------------
/oraprom1/datafiles/entoles01.dbf                               146581     42.26%
/oraprom2/datafiles/entoles02.dbf                               100499     28.98%
/oraprom3/datafiles/entoles03.dbf                                99763     28.76%

Comments

Popular posts from this blog

Reboot Exadata Machine

ORA-01565: error in identifying file '?/dbs/spfile@.ora'

STEPS TO troubleshoot long running concurrent request in R12.2.x