Oracle表启用压缩会产生日志吗?

Posted dingdingfish

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Oracle表启用压缩会产生日志吗?相关的知识,希望对你有一定的参考价值。

答案是会。如果表设置为nologging,则会产生少许;如果是logging,则会产生很多。

以下我们通过实验证明。LINEORDER是一个40G的大表。

以下是表设置为nologging时的实验,日志增量为796M(4128-3332):

SQL> select name, total_mb, free_mb, total_mb-free_mb as used_mb from V$ASM_DISKGROUP;

NAME                             TOTAL_MB    FREE_MB    USED_MB
------------------------------ ---------- ---------- ----------
DATA                               262144     103028     159116
RECO                               262144     258812       3332

SQL> alter table lineorder move row store compress advanced;

SQL> select logging from user_tables where table_name = 'LINEORDER';

LOG
---
NO

SQL> alter table lineorder move row store compress advanced;

Table altered.

SQL> select name, total_mb, free_mb, total_mb-free_mb as used_mb from V$ASM_DISKGROUP;

NAME                             TOTAL_MB    FREE_MB    USED_MB
------------------------------ ---------- ---------- ----------
DATA                               262144     102996     159148
RECO                               262144     258016       4128

以下是表设置为nologging时的实验,日志增量为26,560M(29892-3332):

SQL> select name, total_mb, free_mb, total_mb-free_mb as used_mb from V$ASM_DISKGROUP;

NAME                             TOTAL_MB    FREE_MB    USED_MB
------------------------------ ---------- ---------- ----------
DATA                               262144     103028     159116
RECO                               262144     258812       3332

SQL> select bytes, blocks from user_segments where segment_name = 'LINEORDER';

     BYTES     BLOCKS
---------- ----------
4.4866E+10    5476752

SQL> alter table lineorder move row store compress advanced;

SQL> select logging from user_tables where table_name = 'LINEORDER';

LOG
---
NO

SQL> alter table lineorder logging;

Table altered.

SQL> set timing on
SQL> alter table lineorder move row store compress advanced;

Table altered.

Elapsed: 00:16:29.25
SQL> set timing off
SQL> select bytes, blocks from user_segments where segment_name = 'LINEORDER';

     BYTES     BLOCKS
---------- ----------
2.6859E+10    3278720

SQL> select name, total_mb, free_mb, total_mb-free_mb as used_mb from V$ASM_DISKGROUP;

NAME                             TOTAL_MB    FREE_MB    USED_MB
------------------------------ ---------- ---------- ----------
DATA                               262144     103028     159116
RECO                               262144     232252      29892

这里还有一个新认知,USER_TABLES视图的信息必须在搜集统计信息后才会准:

To gather statistics for this view, use the DBMS_STATS package.

例如:

SQL> select num_rows, blocks, avg_row_len, tablespace_name from user_tables where table_name = 'LINEORDER';

  NUM_ROWS     BLOCKS AVG_ROW_LEN TABLESPACE_NAME
---------- ---------- ----------- ------------------------------
 384016850    5476752          98 USERS

SQL> select bytes, blocks from user_segments where segment_name = 'LINEORDER';

     BYTES     BLOCKS
---------- ----------
2.6880E+10    3281280

SQL> exec dbms_stats.gather_table_stats(null, 'LINEORDER');

PL/SQL procedure successfully completed.

SQL> select num_rows, blocks, avg_row_len, tablespace_name from user_tables where table_name = 'LINEORDER';

  NUM_ROWS     BLOCKS AVG_ROW_LEN TABLESPACE_NAME
---------- ---------- ----------- ------------------------------
 384016850    3277510          98 USERS

SQL> select bytes, blocks from user_segments where segment_name = 'LINEORDER';

     BYTES     BLOCKS
---------- ----------
2.6880E+10    3281280

以上是关于Oracle表启用压缩会产生日志吗?的主要内容,如果未能解决你的问题,请参考以下文章

oracle的log文件可以全部删除吗

oracle中创建表如何不产生日志

oracle建立表空间时有必要加logging吗?

可以为特定表启用 dse cassandra 审核日志吗?

oracle11g 系统表空间满 会自动增加吗

oracle中,用create table ... as select * from table_a...语句备份或者其他用途会不会产生归档日志,