Você está na página 1de 11

Oracle Compression

The Oracle Database 11g Advanced Compression Option introduces a comprehensive set of compression capabilities to help customers maximize resource utilization and reduce costs. It allows IT administrators to significantly reduce their overall database storage footprint by enabling compression for all types of data be it relational (table), unstructured (file), or backup data. Although storage cost savings are often seen as the most tangible benefit of compre ssion, innovative technologies included in the Advanced Compression Option are designed to reduce resource requirements and technology costs for all components of your IT infrastructure, including memory and network bandwidth.

Note: The Oracle 11g Advanced Compression Option is licensed separately from the RDBMS Enterprise Edition. Please see the licensing documentation referenced at the end of this note.

Overview : The oracle compression feature compresses data by eliminating duplicate values in a database block. Compressed data stored in a database block (also known as disk page) is self-contained. That is, all the information needed to re create the uncompressed data in a block is available within that block. Duplicate values in all the rows and columns in a block are stored once at the beginning of the block, in what is called a symbol table for that block. All occurrences of such values are replaced with a short reference to the symbol table. With the exception of a symbol table at the beginning, compressed database blocks look very much like regular database blocks. All database features and functions that work on regular database blocks also work on compressed database blocks . Existing data in the database can also be compressed by moving it int o compressed form through ALTER TABLE and MOVE statements. This operation takes an exclusive lock on the table, and therefore prevents any updates and loads until it completes.

Compression Operation:

what would happen when inserting into block that is part of a compressed table, the cycle would be like :
The block is empty and available for inserts. When you start inserting into this block, data is stored in an uncompressed format (like for uncompressed tables). However, as soon as you reach the PCTFREE of that block, the data is automatically compressed, potentially reducing the space it originally occupied.

This allows for new uncompressed inserts to take place in the same block, until PCTFREE is reached again. At that point compression is triggered again to reduce space occupation in the block.

Note: Compression eliminates holes created due to deletions and maximizes contiguous free space in blocks.

Compression Method:
Database objects that can be compressed include tables, materialized views, partitioned tables( some or all partitions can be compressed) .

Compression clause can be specified with following options: { COMPRESS [ BASIC | FOR { OLTP | { QUERY | ARCHIVE } [ LOW | HIGH] } ] | NOCOMPRESS }

1)NOCOMPRESS - The table, partition or materialized view is not compressed. This is the default action when no compression clause is specified. 2)COMPRESS - This option is considered suitable for data warehouse systems. Compression is enabled on the table or partition during direct -path inserts only. 3)COMPRESS FOR DIRECT_LOAD OPERATIONS - This option has the same affect as the simple COMPRESS keyword. 4)COMPRESS FOR OLTP - This option is considered suitable for OLTP systems. As the name implies, this option enables compression for all operations, including regular DML statements.

This option requires the COMPATIBLE initialization parameter to be set to 11.1.0 or higher 5) COMPRESS FOR OLTP - When you enable table compression by specifying COMPRESS FOR OLTP, you enable OLTP table compression. Oracle Database compresses data during all DML operations on the table. This form of compression is recommended for OLTP environments. In earlier releases, OLTP table compression was enabled using COMPRESS FOR ALL OPERATIONS. This syntax has been deprecated. Advanced Compression feature for OLTP compression in 11.1 is specified as "FOR ALL OPERATIONS" and in 11.2 it is spec ified as "FOR OLTP". Now we are going to see how to enable the basic and OLTP Compression.

Basic Compression:
This type of compression will enable only when the direct path insertion is in place. If you want to enable full compression then you have to use the MOVE command.

Ex: Create a table with basic compression. SQL> create tables test(id int , name varchar2(24)) COMPRESS BASIC; in this type of compression only Direct -path inserts are compressed. insert /*+ APPEND */ into test select id, ename from employees; Rows which are inserted without using direct path insert and updated rows are uncompressed. To Compress the Subsequent insertion of the table , SQL> alter table test compress; The above command will only compress subsequent insertions.

To Compress all the existing and future DML Operation, SQL> alter table test move compress;
NOTE: This command will make the table unavailable for

some time until the compression of the whole table is complete. To turn off compression for subsequent insertions, SQL> alter table test nocompress; Above command will result in noncompression of subsequent insertions, existing data will not be uncompressed.

To completely remove compression. SQL> alter table test move nocompress;

OLTP Compression: OLTP compression feature is available at the DML level. That means all DML changes are compressed.

Create a table with OLTP compression. SQL> create tables test(id int,name varchar2(24)) COMPRESS FOR OLTP;

To compress the exisiting table: SQL> alter table employees move compress for OLTP; NOTE: This command will make the table unavailable for some time until the compression of the whole table is complete.

To Turn off the table compression: SQL> alter table employees move nocompress;

To Turn off the compression for subsequent DML statements. SQL> alter table employees nocompress; The below example explain you the step to perform the compression for the exising table in OLTP Env.

Ex: SQL> alter user hr identified by hr account unlock; SQL> conn hr/hr Connected. SQL> create table test as select * from all_obj ects; Table created. SQL> select bytes/1024/1024 from user_segments where segment_name = 'TEST'; BYTES/1024/1024 --------------7 SQL> insert into test select * from test; 55666 rows created. SQL> / 111332 rows created. SQL> / 222664 rows created. Lets check the size of the table. SQL> select bytes/1024/1024 from user_segments where segment_name = 'TEST'; BYTES/1024/1024 --------------1666 SQL> alter table test move compress for OLTP; Table altered. SQL> select bytes/1024/1024 from user_segments where segment_name = 'TEST';

BYTES/1024/1024 --------------504 Other Compression Technology: Dump File Compression: Oracle 11g now supports compression of Dump file sets. Compression of dump file sets is part of a new licensed product called the Advanced Compression option, which is available for both standard and enterprise editions of Oracle. If you need compression check with Oracle about the current license requirements. To compress a Data Pump dump file use the compression parameter of the expdp command, as seen in this example: expdp quest/quest DIRECTORY= quest_pump_dir DUMPFILE=quest_comp.dmp COMPRESSION=ALL There are four options available for the compression parameter: ALL - Enables compression for the entire operation. metadata_only - The default setting. Causes only the metadata to be compressed. data_only - Only the data being written to the dum p file set will be compressed. None - No compression will take place.

Compression advisor Compression advisor is a new advisor added in 11gR2.It is shipped with Segment Advisor, and will be executed whenever Segment Advisor task run. It can also be invoked manually. We can't disable it separately at this point of time, but an enhancement request has been submitted to separate it from Segment Advisor. Currently we can disable Segment Advisor to disable Compression Advisor.

Segments that are at least 10MB in size and with at least 3 indexes will be evaluated for compressibility (but not all the tables which meet the requirements will be evaluated, an internal algorithm will decide which segment should be evaluated). Dbms_compression package will be invoked to estimate how much space can be saved. It will create two internal tables (DBMS_TABCOMP_TEMP_UNCMP, DBMS_TABCOMP_TEMP_CMP) in the tablespace which hosts the segment. DBMS_TABCOMP_TEMP_UNCMP is created with 99% sample bl ocks by default. DBMS_TABCOMP_TEMP_CMP is created with compress option based on DBMS_TABCOMP_TEMP_UNCMP. COMPRESSION_ RATIO is generated by comparing DBMS_TABCOMP_TEMP_UNCMP and DBMS_TABCOMP_TEMP_CMP. These two tables will be dropped immediately after the estimation.

Please create a tablespace before running compression advisor as it creates two temporary tables and will do significant amount of I/O traffic against them. I would further recommend that you run the compression advisor during less busy periods for the database. I have used a scratch tablespace called USERS and the compression advisory was run against DEPT table. Further, the advisory was run against a sample of 1 million rows by defualt, which can be changed by providing specific values for num_rows.

sql> set serveroutput on sql> declare v_blkcnt_cmp pls_integer; v_blkcnt_uncmp pls_integer; v_row_cmp pls_integer; v_row_uncmp pls_integer; v_cmp_ratio number; v_comptype_str varchar2(60); begin dbms_compression.get_compression_ratio( scratchtbsname => upper('&ScratchTBS'), ownname => user,

tabname => upper('&TableName'), partname => NULL, comptype => dbms_compression.comp_for_query_high, blkcnt_cmp => v_blkcnt_cmp, blkcnt_uncmp => v_blkcnt_uncmp, row_cmp => v_row_cmp, row_uncmp => v_row_uncmp, cmp_ratio => v_cmp_ratio, comptype_str => v_comptype_str, substr_numrows=>&num_rows ); dbms_output.put_line('Estimated Compression Ratio: '||to_char(v_cmp_ratio)); dbms_output.put_line('Blocks used by compressed sample: '||to_char(v_blkcnt_cmp)); dbms_output.put_line('Blocks used by uncompressed sample: '||to_char(v_blkcnt_uncmp)); end; /

Example Output

Enter value for scratchtbs: USERS old 10: scratchtbsname => upper('&ScratchTBS'), new 10: scratchtbsname => upper('USERS'), Enter value for tablename: DEPT old 12: tabname => upper('&TableName'), new 12: tabname => upper('DEPT'), Compression Advisor self-check validation successful. select count(*) on both Uncompressed and EHCC Compressed format = 1000001 rows Estimated Compression Ratio: 1161.4 Blocks used by compressed sample: 123 Blocks used by uncompressed sample: 142858

The output above indicates that the number of uncompressed blocks 122858 will be compressed to 123, which is as shown an estimated compression ratio of 1161.4:1.

Você também pode gostar