Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
COMPRESS :
By DEFAULT COMPRESS=Y COMPRESS(Y) - Parameter in EXP doesn't compress the contents of the exported data. If extent sizes are large (for example, because of the PCTINCREASE parameter), the allocated space will be larger than the space required to hold the data. COMPRESS(Y) during export , at the time of table creation while importing, the INITIAL extent of the table would be as large as the sum of all the extents. SQL> create table test(no number , text varchar(100)); Table created. SQL> select EXTENTS , blocks from user_segments;
EXTENTS BLOCKS
Inserting values into TEST table , USER is ROSE SQL> begin 2 for i in 1..100000 loop 3 insert into test values(i, ORCL DATABASE'); 4 commit; 5 loop; 6 end loop; 7 / PL/SQL procedure successfully completed. EXPLORING the Oracle Technology by Thiyagu Gunasekaran Page 1 of 9
10g Compress Parameter in EXPORT/IMPORT SQL> select extents , bytes from user_segments;
EXTENTS BYTES
42
28311552
Calculating TEST table size as MB SQL>select sum(bytes)/1024/1024 "MB" from user_segments where segment_name='TEST';
MB
27 Now i want to update and delete some of the rows from the table and check the size from USER_SEGMENTS. SQL> update test set name='ORACLE'; 1000000 rows updated. SQL> commit; Commit complete. SQL> update test set name='ORCL'; 1000000 rows updated. SQL> commit; Commit complete. SQL> delete from test where no between 1 and 500000; 500000 rows deleted. SQL> commit; Commit complete. EXPLORING the Oracle Technology by Thiyagu Gunasekaran Page 2 of 9 I
27 Million records updated twice , and 5 lakh records deleted from TEST table but size is still 27 MB as Oracle has not freed the allocated extents. Exporting TEST table from user ROSE as COMPRESS=Y ** Compress=y from user ROSE ** SQL> host exp rose/rose file=1.dmp tables=test compress=y About to export specified tables via Conventional Path ... . . exporting table TEST 500000 rows exported
Exporting TEST table from user ROSE as COMPRESS=N ** Compress=n from user ROSE ** SQL> host exp rose/rose file=2.dmp tables=test compress=n About to export specified tables via Conventional Path ... . . exporting table TEST 500000 rows exported
10g Compress Parameter in EXPORT/IMPORT ** IMPORTING 1.dmp to user U1 ** SQL> conn u1 Enter password: Connected. SQL> host imp u1/u1 file=1.dmp tables=test fromuser=rose touser=u1 Warning: the objects were exported by ROSE, not by you import done in US7ASCII character set and AL16UTF16 NCHAR character set import server uses WE8ISO8859P1 character set (possible charset conversion) . importing ROSE's objects into U1 . . importing table "TEST" 500000 rows imported
27
28311552
TEST
28311552
10g Compress Parameter in EXPORT/IMPORT SQL> select extent_id, bytes/1024 " SIZE AS Kb" from user_extents where segment_name='TEST'; EXTENT_ID 0 .. .. 26 27 rows selected. SQL> conn Connected. dbms_stats.gather_table_stats is used to analyze a single table /as sysdba SIZE AS Kb 1024 .... .... 1024
SQL> select table_name, round((num_rows *avg_row_len/1024),2) || 'kb' "ACTUAL SIZE" from dba_tables where table_name='TEST' and owner='U1';
TABLE_NAME Actual SIZE
TEST
POINTS TO NOTE
4391.43kb
** So table actual size is just 4.28 MB , but it occupies 27 MB ** ** Total no of Extents are 27 from 42 ** EXPLORING the Oracle Technology by Thiyagu Gunasekaran Page 5 of 9
10g Compress Parameter in EXPORT/IMPORT ** IMPORTING 2.dmp to user U2 ** SQL> conn u2 Enter password: Connected. SQL> host imp u2/u2 file=2.dmp tables=test fromuser=rose touser=u2 Warning: the objects were exported by ROSE, not by you import done in US7ASCII character set and AL16UTF16 NCHAR character set import server uses WE8ISO8859P1 character set (possible charset conversion) . importing ROSE's objects into U2 . . importing table "TEST" 500000 rows imported
9437184
24
TEST
65536
SQL> select sum(bytes)/1024/1024 " SIZE AS MB " from user_extents where segment_name='TEST'; SIZE AS MB 9 EXPLORING the Oracle Technology by Thiyagu Gunasekaran Page 6 of 9
10g Compress Parameter in EXPORT/IMPORT SQL> select extent_id , bytes/1024 " SIZE AS Kb " from user_extents where segment_name='TEST';
EXTENT_ID SIZE AS Kb
0 .. 15 16 23
64 .. 64 1024 1024
24 rows selected. SQL> conn / as sysdba Connected. dbms_stats.gather_table_stats is used to analyze a single table SQL> exec dbms_stats.gather_table_stats('u2', 'test'); PL/SQL procedure successfully completed.
CALCULATING ACTUAL SIZE OF THE TABLE
SQL> select table_name,round ((num_rows*avg_row_len/1024),2)||'kb' "SIZE" From dba_tables where table_name='TEST' and owner='U2';
TABLE_NAME SIZE
TEST
4370.95kb
** So table actual size is just 4.26 MB , but it occupies just 9 MB ** ** Total no of Extents are 24 from 42 ** EXPLORING the Oracle Technology by Thiyagu Gunasekaran Page 7 of 9
10g Compress Parameter in EXPORT/IMPORT FINAL REVIEW When COMPRESS = Y SQL> show user; USER is "U1" SQL> select EXTENTS , BYTES , BLOCKS from user_segments;
EXTENTS BYTES BLOCKS
27
28311552
3456
When COMPRESS = N SQL> show user; USER is "U2" SQL> select EXTENTS , BYTES , BLOCKS from user_segments;
EXTENTS BYTES BLOCKS
24
9437184
1152
When using COMPRESS=N during export then while creating table in the import, it will use the same values of INITIAL extent as in the original database. Additional Reference learn : Automatic Segment Space Management EXPLORING the Oracle Technology by Thiyagu Gunasekaran Page 8 of 9