As your database grows in size, consider using table compression. Compression saves disk space, reduces memory use in the database buffer cache, and can significantly speed query execution during reads. Compression has a cost in CPU overhead for data loading and DML. However, this cost might be offset by reduced I/O requirements.
##随着数据的增加,可以斟酌使用表紧缩技术。紧缩能够节省磁盘空间,减少SGA中buffer cache的使用,显著提高查询时读数据的效力。对紧缩过后的表进行数据导入和DML需要消耗更多的cpu资源,但是紧缩的使用减少了I/O的开消,可以抵消掉额外的cpu开消本钱(根据系统的情况,如果你的库本来cpu资源已不足,那末这样做就不适合了)
Table compression is completely transparent to applications. It is useful in decision support systems (DSS), online transaction processing (OLTP) systems, and archival systems.
##紧缩技术对利用来讲完全是透明的。它对dss,oltp,archival system等系统等很有用
You can specify compression for a tablespace, a table, or a partition. If specified at the tablespace level, then all tables created in that tablespace are compressed by default.
##你可以为表空间,表或分区指定紧缩属性。如果你为表空间指定了紧缩属性,那末在该表空间下建的表会默许的继承紧缩属性。
Compression can occur while data is being inserted, updated, or bulk loaded into a table. Operations that permit compression include:
##紧缩在insert,update和批量加载时都可能产生(具体要看你使用的是哪一种紧缩方式)
Single-row or array inserts and updates
The following direct-path INSERT
methods:
Direct path SQL*Loader
CREATE
TABLE
AS
SELECT
statements
Parallel INSERT
statements
INSERT
statements with an APPEND
or
APPEND_VALUES
hint
http://www.wfuyu.com/oracle/ Database supports several methods of table compression. They are summarized in Table 20⑴.
##oraclehttp://www.wfuyu.com/db/支持以下几种紧缩方式(注意,Hybrid Columnar Compression模式的紧缩只有在Exadata上才支持)
Table 20⑴ Table Compression Methods
Table Compression Method | Compression Level | CPU Overhead | Applications | Notes |
---|---|---|---|---|
Basic compression |
High |
Minimal |
DSS |
None. |
OLTP compression |
High |
Minimal |
OLTP, DSS |
None. |
Warehouse compression (Hybrid Columnar Compression) |
Higher |
Higher |
DSS |
The compression level and CPU overhead depend on compression level specified (LOW or HIGH). |
Archive compression (Hybrid Columnar Compression) |
Highest |
Highest |
Archiving |
The compression level and CPU overhead depend on compression level specified (LOW or HIGH). |
When you use basic compression, warehouse compression, or archive compression, compression only occurs when data is bulk loaded into a table.
##当你使用的是basic,warehouse或archive紧缩时,只有批量载入的数据才会被紧缩(此处我觉得有点问题,应当是只有直接路径加载的数据才会被紧缩。不知道官方文档这里说的批量加载是不是指的就是直接路径加载)
When you use OLTP compression, compression occurs while data is being inserted, updated, or bulk loaded into a table. Operations that permit compression include:
##当你使用的是oltp紧缩时,传统路径插入和直接路径插入的数据都会被紧缩
Single-row or array inserts and updates##这里就是指的传统路径插入
The following direct-path INSERT
methods:##这里指的是直接路径插入
Direct path SQL*Loader
CREATE
TABLE
AS
SELECT
statements
Parallel INSERT
statements
INSERT
statements with an APPEND
or
APPEND_VALUES
hint
Basic compression compresses data inserted by direct path load only and supports limited data types and SQL operations. OLTP compression is intended for OLTP applications and compresses data manipulated by any SQL operation.
##Basic紧缩方式仅支持有限的数据类型和sql操作,当数据使用直接路径插入时,这些数据会被紧缩。OLTP紧缩1般用在oltp系统上,能够紧缩各种sql操作产生的数据
Warehouse compression and archive compression achieve the highest compression levels because they use Hybrid Columnar Compression technology. Hybrid Columnar Compression technology uses a modified form of columnar storage instead of row-major storage. This enables the database to store similar data together, which improves the effectiveness of compression algorithms. For data that is updated, Hybrid Columnar Compression uses more CPU and moves the updated rows to row format so that future updates are faster. Because of this optimization, you should use it only for data that is updated infrequently.
##由于使用了混合列模式紧缩技术,Warehouse 和 archive能够提供最高的紧缩等级。混合列模式紧缩技术使用列模式存储代替了之前的行模式存储。列模式存储使用http://www.wfuyu.com/db/能够把相似的数据存储在1起从而提高紧缩的效力。如果混合列模式紧缩的数据被更新,那末会消耗额外的cpu把被更新的行转变成行模式(行的rowid会产生变化),速度也是比较快的(不知道此处的快是跟行模式紧缩相比,还是同非紧缩表的update对照???)。基于混合列模式紧缩的优化原理,我们应当在那些很少被update的表上使用这类紧缩方式。
The higher compression levels of Hybrid Columnar Compression are achieved only with data that is direct-path inserted. Conventional inserts and updates are supported, but cause rows to be moved from columnar to row format, and reduce the compression level.
Table 20⑵ lists characteristics of each table compression method.
Table 20⑵ Table Compression Characteristics
Table Compression Method | CREATE/ALTER TABLE Syntax | Direct-Path INSERT | Notes |
---|---|---|---|
Basic compression |
|
Rows are compressed with basic compression. |
Rows inserted without using direct-path insert and updated rows are uncompressed. |
OLTP compression |
|
Rows are compressed with OLTP compression. |
Rows inserted without using direct-path insert and updated rows are compressed using OLTP compression. |
Warehouse compression (Hybrid Columnar Compression) |
|
Rows are compressed with warehouse compression. |
This compression method can result in high CPU overhead. Updated rows and rows inserted without using direct-path insert are stored in row format instead of column format, and thus have a lower compression level. |
Archive compression (Hybrid Columnar Compression) |
|
Rows are compressed with archive compression. |
This compression method can result in high CPU overhead. Updated rows and rows inserted without using direct-path insert are stored in row format instead of column format, and thus have a lower compression level. |
You specify table compression with the COMPRESS
clause of the
CREATE
TABLE
statement. You can enable compression for an existing table by using these clauses in an
ALTER
TABLE
statement. In this case, only data that is inserted or updated after compression is enabled is compressed. Similarly, you can disable table compression for an existing compressed table with the
ALTER
TABLE
...NOCOMPRESS
statement. In this case, all data that was already compressed remains compressed, and new data is inserted uncompressed.
##你可以在建表的时候指定compress字句,也能够在表创建后使用alter table语句改变表的紧缩属性。如果是后者,那末表中已存在的数据不会被紧缩,只有新插入或update的数据有可能被紧缩。一样的如果你改变1个紧缩表的属性为非紧缩表,表中已存在的被紧缩的数据还是保持紧缩的状态,不会被解压,但新插入的数据将不会再被紧缩。
The COMPRESS
FOR
QUERY
HIGH
option is the default data warehouse compression mode. It provides good compression and performance when using Hybrid Columnar Compression on Exadata storage. The
COMPRESS
FOR
QUERY
LOW
option should be used in environments where load performance is critical. It loads faster than data compressed with the
COMPRESS
FOR
QUERY
HIGH
option.
The COMPRESS FOR ARCHIVE LOW
option is the default archive compression mode. It provides a high compression level and is ideal for infrequently-http://www.wfuyu.com/access/ed data. The
COMPRESS FOR ARCHIVE HIGH
option should be used for data that is rarely http://www.wfuyu.com/access/ed.
A compression advisor, provided by the DBMS_COMPRESSION
package, helps you determine the expected compression level for a particular table with a particular compression method.
Note:
Hybrid Columnar Compression is dependent on the underlying storage system. See http://www.wfuyu.com/oracle/ Database Licensing Information for more information.See Also:
http://www.wfuyu.com/oracle/ Database Concepts for an overview of table compression
"Compressed Tablespaces"
The following examples are related to table compression:
Example 20⑴, "Creating a Table with OLTP Table Compression"
Example 20⑵, "Creating a Table with Basic Table Compression"
Example 20⑶, "Using Direct-Path Insert to Insert Rows Into a Table"
Example 20⑷, "Creating a Table with Warehouse Compression"
Example 20⑸, "Creating a Table with Archive Compression"
Example 20⑴ Creating a Table with OLTP Table Compression
##新建1个oltp类型的紧缩表
The following example enables OLTP table compression on the table orders
:
Data for the orders
table is compressed during both direct-path
INSERT
and conventional DML.
##此种紧缩方式下,直接路径插入和传统路径插入的数据都会被紧缩。
Example 20⑵ Creating a Table with Basic Table Compression
##新建1个basic类型的紧缩表
The following statements, which are equivalent, enable basic table compression on the
sales_history
table, which is a fact table in a data warehouse:
Frequent queries are run against this table, but no DML is expected.
##这类紧缩方式1般被用在频繁查询,但不被dml的表上
Example 20⑶ Using Direct-Path Insert to Insert Rows Into a Table
This example demonstrates using the APPEND
hint to insert rows into the
sales_history
table using direct-path INSERT
.
##使用append提示符激活直接路径插入
Example 20⑷ Creating a Table with Warehouse Compression
This example enables Hybrid Columnar Compression on the table sales_history
:
The table is created with the default COMPRESS FOR QUERY HIGH
option. This option provides a higher level of compression than basic or OLTP compression. It works well when load performance is critical, frequent queries are run against this table,
and no DML is expected.
Example 20⑸ Creating a Table with Archive Compression
The following example enables Hybrid Columnar Compression on the table sales_history
:
The table is created with the default COMPRESS FOR ARCHIVE LOW
option. This option provides the highest level of compression and works well for infrequently-http://www.wfuyu.com/access/ed data.
A table can have both compressed and uncompressed partitions, and different partitions can use different compression methods. If the compression settings for a table and one of its partitions do not match, then the partition setting has precedence for the partition.
##1个分区表可以同时包括紧缩的和非紧缩的分区,并且可以给紧缩分区指定不同的紧缩方式。我们可以给分区表和分区指定不同的分区方式,并且分区上的指定具有较高的优先级。
To change the compression method for a partition, do one of the following:
##改变分区紧缩方式的方法以下:
To change the compression method for new data only, use ALTER
TABLE
... MODIFY
PARTITION
... COMPRESS
...##仅对新数据有效
To change the compression method for both new and existing data, use either
ALTER
TABLE
... MOVE
PARTITION
...
COMPRESS
... or online table redefinition.##使用alter table...move partition...compress或表的在线重定义方式改变表的紧缩方式,对新的数据和旧的数据都是有效的。
In the *_TABLES
data dictionary views, compressed tables have
ENABLED
in the COMPRESSION
column. For partitioned tables, this column is null, and the
COMPRESSION
column of the *_TAB_PARTITIONS
views indicates the partitions that are compressed. In addition, the
COMPRESS_FOR
column indicates the compression method in use for the table or partition.
##在*_TABLES视图中紧缩表的compress列被标记为"ENABLED",固然如果是分区表的话,那末这1列被标记为空。分区表及组合分区表的紧缩情况我们相应的应当查看*_TAB_PARTITIONS及*_TAB_SUBPARTITIONS视图
When Hybrid Columnar Compression tables are updated, the rows change to a lower level of compression, such as from warehouse compression (QUERY
HIGH
) to OLTP compression or no compression. To determine the compression level of a row, use the
GET_COMPRESSION_TYPE
function in the DBMS_COMPRESSION
package.
##当混合列模式紧缩的表被更新,被更新的行的紧缩等级会下降,如从warehouse compression (QUERY
HIGH
)降至oltp或非紧缩。我们可使用DBMS_COMPRESSION宝中的GET_COMPRESSION_TYPE function去查询某1列的紧缩等级。
For example, the following query returns the compression type for a row in the
hr.employees
table:
By sampling the table rows, you can determine the percentage of rows that are no longer at the higher compression level. You can use
ALTER TABLE
or MOVE PARTITION
to specify a higher compression level. For example, if 10 percent of the rows are no longer at the highest compression level, then you might alter the table or move the partition to specify a higher compression
level.
See Also:
GET_COMPRESSION_TYPE
You can change the compression level for a partition, table, or tablespace. For example, suppose a company uses warehouse compression for its sales data, but sales data older than six months is rarely http://www.wfuyu.com/access/ed. If the sales data is stored in a table that is partitioned based on the age of the data, then the compression level for the older data can be changed to archive compression to free disk space.
If a table is partitioned, then the DBMS_REDEFINITION
package can change the compression level of the table. This package performs online redefinition of a table by creating a temporary copy of the table that holds the table data while it is
being redefined. The table being redefined remains available for queries and DML statements during the redefinition. The amount of free space for online table redefinition depends on the relative compression level of the existing table and the new table. Ensure
you have enough hard disk space on your system before using the DBMS_REDEFINITION
package.
If a table is not partitioned, then you can use the ALTER TABLE...MOVE...COMPRESS FOR...
statement to change the compression level. The
ALTER TABLE...MOVE
statement does not permit DML statements against the table while the command is running.
To change the compression level for a partition, use the ALTER TABLE...MODIFY PARTITION
statement. To change the compression level for a tablespace, use the
ALTER TABLESPACE
statement.
##对非分区表我们只能通过ALTER TABLE...MOVE...COMPRESS FOR命令来改变表的紧缩等级,在变更的进程中不允许对表进行DML操作(如果表很大的话,就会长时间的影响利用)。如果是分区表我们可以通过上面的方式来做,也能够通过使用DBMS_REDEFINITION包来改变表的紧缩等级,使用在线重定义的时候会为目标表建1个临时备份来保存表中的数据,在线重定义进程中目标是1直可以访问和dml的。
See Also:
"Moving a Table to a New Segment or Tablespace" for additional information about the
ALTER TABLE
command
http://www.wfuyu.com/oracle/ Database PL/SQL Packages and Types Reference for additional information about the
DBMS_REDEFINITION
package
The following restrictions apply when adding columns to compressed tables:
##向紧缩表中添加列的时候有以下限制:
Basic compression―You cannot specify a default value for an added column.##对basic紧缩方式你不能为添加的列指定默许值
OLTP compression―If a default value is specified for an added column, then the column must be
NOT
NULL
. Added nullable columns with default values are not supported.##
The following restrictions apply when dropping columns in compressed tables:
##从紧缩表中删除列时有以下限制:
Basic compression―Dropping a column is not supported.##对basic紧缩来讲不支持列删除
OLTP compression―DROP
COLUMN
is supported, but internally the database sets the column
UNUSED
to avoid long-running decompression and recompression operations.##对oltp紧缩也是不支持列删除,但是我们可以把列设置为UNUSED的,避免解紧缩和重新紧缩操作队它的影响。
Hybrid Columnar Compression tables can be imported using the impdp
command of the Data Pump Import utility. By default, the
impdp
command preserves the table properties, and the imported table is a Hybrid Columnar Compression table. On tablespaces not supporting Hybrid Columnar Compression, the
impdp
command fails with an error. The tables can also be exported using the
expdp
command.
You can import the Hybrid Columnar Compression table as an uncompressed table using the
TRANSFORM:SEGMENT_ATTRIBUTES=n
option clause of the impdp
command.
An uncompressed or OLTP-compressed table can be converted to Hybrid Columnar Compression format during import. To convert a non-Hybrid Columnar Compression table to a Hybrid Columnar Compression table, do the following:
Specify default compression for the tablespace using the ALTER TABLESPACE ... SET DEFAULT COMPRESS
command.
Override the SEGMENT_ATTRIBUTES
option of the imported table during import.
See Also:
http://www.wfuyu.com/oracle/ Database Utilities for additional information about the Data Pump Import utility
http://www.wfuyu.com/oracle/ Database SQL Language Reference for additional information about the
ALTER TABLESPACE
command
There may be times when a Hybrid Columnar Compression table must be restored from a backup. The table can be restored to a system that supports Hybrid Columnar Compression, or to a system that does not support Hybrid Columnar Compression. When restoring a table with Hybrid Columnar Compression to a system that supports Hybrid Columnar Compression, restore the file using http://www.wfuyu.com/oracle/ Recovery Manager (RMAN) as usual.
When a Hybrid Columnar Compression table is restored to a system that does not support Hybrid Columnar Compression, you must convert the table from Hybrid Columnar Compression to OLTP compression or an uncompressed format. To restore the table, do the following:
Ensure there is sufficient storage in environment to hold the data in uncompressed or OLTP compression format.
Use RMAN to restore the Hybrid Columnar Compression tablespace.
Complete one of the following actions to convert the table from Hybrid Columnar Compression to OLTP compression or an uncompressed format:
Use the following statement to change the data compression from Hybrid Columnar Compression to
COMPRESS FOR OLTP
:
Use the following statement to change the data compression from Hybrid Columnar Compression to
NOCOMPRESS
:
Use the following statement to change each partition to NOCOMPRESS
:
Change each partition separately.
Use the following statement to move the data to NOCOMPRESS
in parallel:
See ALso:
http://www.wfuyu.com/oracle/ Database Backup and Recovery User's Guide for additional information about RMAN
http://www.wfuyu.com/oracle/ Database SQL Language Reference for additional information about the
ALTER TABLE
command
The following are notes and restrictions related to compressed tables:
Online segment shrink is not supported for compressed tables.##紧缩表不支持在线segment shrink操作
The table compression methods described in this section do not apply to SecureFiles large objects (LOBs). SecureFiles LOBs have their own compression methods. See http://www.wfuyu.com/oracle/ Database SecureFiles and Large Objects Developer's Guide for more information.##本节所说的紧缩方式不能再SecureFiles large objects上使用,SecureFiles LOBs有自己的紧缩方式
Compression technology uses CPU. Ensure that you have enough available CPU to handle the additional load.##紧缩操作对cpu的消耗比较高,确保你的cpu资源够用
Tables created with basic compression have the PCT_FREE
parameter automatically set to
0
unless you specify otherwise.##建表时指定basic紧缩方式PCT_FREE值为0,固然你也能够特别指定其他的你认为适合的值。(建表时指定oltp紧缩方式,PCT_FREE
值默许会被设置为10)
If you use conventional DML on a table compressed with basic compression or Hybrid Columnar Compression, then all inserted and updated rows are stored uncompressed or in a less-compressed format. To "pack" the compressed table so that these rows are compressed,
use an ALTER
TABLE
MOVE
statement. This operation takes an exclusive lock on the table, and therefore prevents any updates and loads until it completes. If this is not acceptable, then you can use online table redefinition.
See Also:
http://www.wfuyu.com/oracle/ Database SQL Language Reference for more details on the
CREATE
TABLE
...COMPRESS
, ALTER
TABLE
...COMPRESS
, and ALTER
TABLE
...MOVE
statements, including restrictions
http://www.wfuyu.com/oracle/ Database VLDB and Partitioning Guide for more information on table partitioning
"Improving INSERT Performance with Direct-Path INSERT"
"Redefining Tables Online"