Showing posts with label compression. Show all posts
Showing posts with label compression. Show all posts

Thursday, November 1, 2018

Verifying Redo Transport Compression in 11.2, 12.1 and 12.2 Data Guard Configuraitons

Redo shipped to standby could be compressed for transport in two ways. One is external to the database and uses SSH tunnelling. Other method is enabling compression for the remote log archive destination. Second option requires advance compression license. Once redo transport compression (RTC) is enabled it could verified by enabling log archive tracing. However, there's a difference as to level of tracing and information for DB versions 11.2, 12.1 and 12.2. This posts explore these variations.

Verifying RTC in 11.2.0.4
The DG configuration for 11.2 is as follows
DGMGRL> show configuration

Configuration - db_dg

  Protection Mode: MaxAvailability
  Databases:
    prod  - Primary database
    stdby - Physical standby database

Fast-Start Failover: DISABLED

Configuration Status:
SUCCESS
Enable RTC on the standby database. This updates the log archive destination setting on the primary by adding compression=enable option.
DGMGRL> edit database stdby set property RedoCompression='enable';
Property "redocompression" updated
On the alert log of the primary following could be seen.
Tue Aug 14 14:29:41 2018
ALTER SYSTEM SET log_archive_dest_3='service="stdbytns"','LGWR SYNC AFFIRM delay=0 optional compression=enable max_failure=10 max_connections=5 reopen=180 db_unique_name="stdby" net_timeout=30','valid_for=(all_logfiles,primary_role)' SCOPE=BOTH;
Enabling log archive tracing level of 1 for primary database
DGMGRL>  edit database prod set property LogArchiveTrace='1';
Property "logarchivetrace" updated
Enable log archive tracing level of 16 for standby
DGMGRL> edit database stdby set property LogArchiveTrace='16';
Property "logarchivetrace" updated
With these setting in place on the primary *nss*.trc files will contain entries similar to following to show that RTC is enabled.
RTC: Compression ratio for this I/O is 81%
RTC: Compression ratio for this I/O is 81%
RTC: Compression ratio for this I/O is 81%
RTC: Compression ratio for this I/O is 80%
On the standby the decompression information is shown in *rsf*.trc files as follows
RTC: decompressed 94 bytes to 512 bytes
RTC: decompressed 93 bytes to 512 bytes
RTC: decompressed 99 bytes to 512 bytes
RTC: decompressed 88 bytes to 512 bytes
RTC: decompressed 5221 bytes to 24576 bytes
If the tracing on the primary is increased to 16 (which Oracle document says as "Track detailed ARCHIVELOG destination activity") only limited RTC information is given out.
edit database prod set property LogArchiveTrace='16';
Both *arc*.trc and *lgwr*.trc files will have entries similar to following.
cat prod_arc7_3372.trc | grep RTC
RTC enabled.
cat prod_lgwr_3297.trc | grep RTC
RTC enabled.
RTC enabled.
Verifying RTC in 12.1.0.2
The 12.1.0.2 DG configuration is as follows
DGMGRL> show configuration;

Configuration - ent12c1_dgb

  Protection Mode: MaxAvailability
  Members:
  ent12c1  - Primary database
    fs12c1   - Far sync instance
      ent12c1s - Physical standby database

  Members Not Receiving Redo:
  fs12c1s  - Far sync instance

Fast-Start Failover: DISABLED

Configuration Status:
SUCCESS
On 12.1 setting log archive trace to 1 has no effect on tracing RTC. Setting the value to 16 on primary gives descriptive RTC information which indicates if RTC is enabled or not.
DGMGRL>  edit database ent12c1 set property logarchivetrace='16';
Property "logarchivetrace" updated
The RTC related information appear in *arc*.trc files and *tt*.trc files
cat ent12c1_arc3_15498.trc | grep RTC
RTC enabled.
RTC: Allocating 11534336 buffer bytes for compression.
RTC: header-batch write block 1, count 1 - RTC disabled
RTC: Enable compression for subsequent batches
RTC: actual compressed bytes# 1295

cat ent12c1_tt01_15532.trc | grep RTC
RTC enabled.
Re-enabling RTC following backoff interval 1.
RTC: actual compressed bytes# 10270
RTC: actual compressed bytes# 536
RTC: actual compressed bytes# 1697
RTC: actual compressed bytes# 508
Redo compression could be enabled on far sync instances as well. Setting trace level to 16 on far sync instance will also generate RTC information on far sync trace files.
DGMGRL> edit far_sync fs12c1 set property RedoCompression='enable';
Property "redocompression" updated

DGMGRL> edit far_sync fs12c1 set property LogArchiveTrace='16';
Property "logarchivetrace" updated

cat fs12c1_tt00_2515.trc | grep RTC
RTC: actual compressed bytes# 97
RTC: actual compressed bytes# 79
To get decompression related information from standby set log archive trace value to 1024 (1024: Tracks RFS physical client).
DGMGRL> edit database ent12c1s set property logarchivetrace='1024';
Property "logarchivetrace" updated
Decompression related information is shown in *rfs*.trc files.
cat ent12c1s_rfs_8859.trc | grep RTC
RTC: decompressed 79 bytes to 512 bytes
RTC: decompressed 81 bytes to 512 bytes
RTC: decompressed 97 bytes to 512 bytes
RTC: decompressed 79 bytes to 512 bytes


Verifying RTC in 12.2.0.1 (and 18.3.0.0)
The 12.2 DG configuration is as follows
DGMGRL> show configuration

Configuration - dg12c2

  Protection Mode: MaxAvailability
  Members:
  prodcdb - Primary database
    stbycdb - Physical standby database

Fast-Start Failover: DISABLED

Configuration Status:
SUCCESS   (status updated 35 seconds ago)
On 12.2 setting log archive trace to 16 on primary generates the RTC information.
DGMGRL> edit database prodcdb set property LogArchiveTrace='16';
Property "logarchivetrace" updated
The RTC information is available on *lgwr*.trc and *nss*.trc files.
cat prodcdb_lgwr_2616.trc | grep RTC
RTC enabled.
RTC enabled.
RTC enabled.

cat prodcdb_nss2_2708.trc | grep RTC
RTC: Enable compression following header-only I/O
RTC: Enable compression following header-only I/O
RTC: Enable compression following header-only I/O
No other values such as 512 (512: Tracks LGWR redo shipping network activity) or combination of values seems to give more descriptive information such as compression ratio or compressed bytes as in the case with previous versions. However, decompression information on standby could be traced with 1024.
DGMGRL> edit database stbycdb set property LogArchiveTrace='1024';
Property "logarchivetrace" updated
Decompression information available in *rfs*.trc file.
cat stbycdb_rfs_2243.trc
krsr_rfs_wda: RTC: decompressed 82 bytes to 512 bytes
krsr_rfs_wda: RTC: decompressed 81 bytes to 512 bytes
krsr_rfs_wda: RTC: decompressed 675 bytes to 1536 bytes
krsr_rfs_wda: RTC: decompressed 1167 bytes to 3072 bytes
krsr_rfs_wda: RTC: decompressed 76 bytes to 512 bytes
Useful Metalink Notes
How to confirm if Redo Transport Compression is used In Oracle Data Guard? [ID 1927057.1]
Redo Transport Compression in a Data Guard Environment [ID 729551.1]
LOG_ARCHIVE_TRACE=16 DOES NOT SHOW REDO COMPRESSION DETAIL IN LOG TRANSPORT in 11gr2 [ID 2193605.1]
How to find out the compression rate of Redo Transport Compression ? [ID 1490751.1]

Tuesday, October 20, 2015

12c Compression Comparison

OLTP Table compression introduced during 11g is called Advanced Row Compression in 12c. However the old syntax still works on 12c as well. Advance row compression maintains compression during all types of data manipulation operations, including conventional DML such as INSERT and UPDATE. Oracle's claim is that this minimizes the overhead for write operation of and making it suitable for OLTP and Data Warehouses. Advanced Row Compression requires purchasing Oracle Advanced Compression option while basic table compression is a feature of Oracle Database 12c Enterprise Edition (EE).
This post compares the reduction of storage usage, overhead of CPU and redo generated for advance vs basic vs no compression options. It is not an extensive test, how useful the compression depends on data being compressed.
As said earlier compress for OLTP creates the table with advance row compression.
create table x (a number, b varchar2(100)) compress for oltp;
select table_name,COMPRESSION,COMPRESS_FOR from  user_tables where table_name='X';

TABLE_NAME COMPRESS COMPRESS_FOR
---------- -------- ------------------------------
X          ENABLED  ADVANCED

create table x (a number, b varchar2(100)) ROW STORE COMPRESS ADVANCED;
select table_name,COMPRESSION,COMPRESS_FOR from  user_tables where table_name='X';

TABLE_NAME COMPRESS COMPRESS_FOR
---------- -------- ------------------------------
X          ENABLED  ADVANCED
If no option is specified this would create basic compression or it could be explicitly specified.
create table x (a number, b varchar2(100)) compress;
SQL> select table_name,COMPRESSION,COMPRESS_FOR from  user_tables where table_name='X';

TABLE_NAME COMPRESS COMPRESS_FOR
---------- -------- ------------------------------
X          ENABLED  BASIC

create table x (a number, b varchar2(100)) ROW STORE COMPRESS basic;
select table_name,COMPRESSION,COMPRESS_FOR from  user_tables where table_name='X';

TABLE_NAME COMPRESS COMPRESS_FOR
---------- -------- ------------------------------
X          ENABLED  BASIC
For the test case three tables were created with no compression, advance and basic compression. The database is 12.1.0.2.
create table NOCOMPRESSTABLE(a number, b varchar2(100));
create table ADVCOMPRESSTABLE(a number, b varchar2(100)) ROW STORE COMPRESS ADVANCED;
create table BASICVCOMPRESSTABLE(a number, b varchar2(100)) ROW STORE COMPRESS basic;

SQL> select table_name,COMPRESSION,COMPRESS_FOR from  user_tables where table_name like '%COMPRESSTABLE';

TABLE_NAME           COMPRESS COMPRESS_FOR
-------------------- -------- -------------
NOCOMPRESSTABLE      DISABLED
BASICVCOMPRESSTABLE  ENABLED  BASIC
ADVCOMPRESSTABLE     ENABLED  ADVANCED
Each table consists of two columns and was populated using the following anonymous PL/SQL block. It inserts a unique value to first column while second column get the same value inserted with each row.
begin
    for i in 1 .. 1000000
    loop
    insert into NOCOMPRESSTABLE values (i,'asdfghjkllqwertyuiopzxcvbnm134567890');
    insert into ADVCOMPRESSTABLE values(i,'asdfghjkllqwertyuiopzxcvbnm134567890');
    insert into BASICVCOMPRESSTABLE values(i,'asdfghjkllqwertyuiopzxcvbnm134567890');
    commit;
    end loop;
end;
/
At the end of the insert the segment size of each table was measured
select segment_name,bytes/1024/1024 as MB from user_segments where segment_name like '%COMPRESS%';

SEGMENT_NAME          MB
--------------------- ---
ADVCOMPRESSTABLE      14
BASICVCOMPRESSTABLE   47
NOCOMPRESSTABLE       52
Results are no surprise as the segment of the table created with advance compression is the smallest and table with no compression is the largest. However this test is the most optimistic of cases where one column consists of only a single value.





Therefore the test was rerun after recreating the tables and inserts were modified as below where some of the values inserted to second column are duplicates but not all of them
begin
    for i in 1 .. 1000000
    loop
--    insert into NOCOMPRESSTABLE values (i,'asdfghjkllqwertyuiopzxcvbnm134567890'||mod(i,500));
    insert into ADVCOMPRESSTABLE values(i,'asdfghjkllqwertyuiopzxcvbnm134567890'||mod(i,500));
--    insert into BASICVCOMPRESSTABLE values(i,'asdfghjkllqwertyuiopzxcvbnm134567890'||mod(i,500));
    commit;
    end loop;
    end;
    /
Only one table was inserted at a time and CPU used by session and redo size were measured for each test, shown on the graphs below.
Strangely the inserts done with compress options used less CPU than when inserted without any compression (test were repeated 3 times and same pattern was observed). However the difference wasn't huge. On the other hand use of advance compression option resulted in more redo being created than basic compression or no compression.
Comparing the segment size revealed the following.
select segment_name,bytes/1024/1024 as MB from user_segments where segment_name like '%COMPRESS%';

SEGMENT_NAME          MB
--------------------- ---
ADVCOMPRESSTABLE      55
BASICVCOMPRESSTABLE   50
NOCOMPRESSTABLE       55
It seems basic compression is slightly better than no compression option but advance compression didn't yield any benefit at all. Reason could be that advance compression didn't encounter enough duplicate values inside a block to make any significant reduction. It's important to remember that compression happens at block level.
Test was rerun this time however the tables were created on a tablespace with a block size of 32k. The segment size at the end of the test are as below
select segment_name,bytes/1024/1024 as MB from user_segments where segment_name like '%COMPRESS%';

SEGMENT_NAME          MB
--------------------- ---
ADVCOMPRESSTABLE      49
BASICVCOMPRESSTABLE   49
NOCOMPRESSTABLE       54
This time there's difference between segment size whose tables were created with a compression options and table created without any compression. However the reduction in segment size is not same as when all the values were duplicates.
From this simple test case it seems, to benefit from a compression strategy, the nature of the data is more important than the compression option being used. The reduction in space is dictated by how many duplicate values are found inside a block.

Friday, November 27, 2009

11g Compression and Segment Space Reuse

An interesting behavior could be observed when rows are deleted and re-inserted to compressed and uncompressed table.

First the uncompressed table.
create table insertdml as select * from all_objects where 1 = 2;
alter table insertdml add constraint insert_pk primary key (object_id);

Use the pl/sql code sinppet to find the space usage.
full_blocks 0
full_bytes 0

total_blocks 8
total_bytes 65536
unused_blocks 5
unused_bytes 40960
last_used_extent_file_id 6
last_used_extent_block_id 34416

Add rows to the table to expand it
declare

type insertrow_type is table of all_objects%rowtype index by pls_integer;
insertrow insertrow_type;
begin
select * bulk collect into insertrow from all_objects;

forall row in insertrow.first .. insertrow.last
insert into insertdml values insertrow(row);
end;
/

Check the space usage after the insert
full_blocks 1002
full_bytes 8208384

total_blocks 1152
total_bytes 9437184
unused_blocks 0
unused_bytes 0
last_used_extent_file_id 6
last_used_extent_block_id 36096
Note the last used extent block id and delete the rows from the table and check the space usage

delete from insertdml;
commit;

full_blocks 0
full_bytes 0

total_blocks 1152
total_bytes 9437184
unused_blocks 0
unused_bytes 0
last_used_extent_file_id 6
last_used_extent_block_id 36096
No more full blocks. Again insert the rows and check the space usage

full_blocks 999
full_bytes 8183808

total_blocks 1152
total_bytes 9437184
unused_blocks 0
unused_bytes 0
last_used_extent_file_id 6
last_used_extent_block_id 36096
Total number of blocks hasn't changed and last used extent block is still the same which means no new extents were added to the segment and old extents are reused.

Now the compressed table

drop table insertdml purge;
create table insertdml compress for all operations as select * from all_objects where 1 = 2;
alter table insertdml add constraint insert_pk primary key (object_id);

check the initial space usage as before
full_blocks 0
full_bytes 0

total_blocks 8
total_bytes 65536
unused_blocks 5
unused_bytes 40960
last_used_extent_file_id 6
last_used_extent_block_id 34416

insert rows to extend the table
declare

type insertrow_type is table of all_objects%rowtype index by pls_integer;
insertrow insertrow_type;
begin
select * bulk collect into insertrow from all_objects;

forall row in insertrow.first .. insertrow.last
insert into insertdml values insertrow(row);
end;
/
and check the space usage
full_blocks 401
full_bytes 3284992

total_blocks 640
total_bytes 5242880
unused_blocks 0
unused_bytes 0
last_used_extent_file_id 6
last_used_extent_block_id 35584

delete rows and check the space usage again
delete from insertdml;
commit;

full_blocks 0
full_bytes 0

total_blocks 640
total_bytes 5242880
unused_blocks 0
unused_bytes 0
last_used_extent_file_id 6
last_used_extent_block_id 35584

insert rows again and check the space usage
full_blocks 645
full_bytes 5283840

total_blocks 768
total_bytes 6291456
unused_blocks 0
unused_bytes 0
last_used_extent_file_id 6
last_used_extent_block_id 35712

Total number of blocks has changed and also the last used extent block id which indicates new extents are being added instead of old extents being reused.

Instead of the pl/sql code sinppet quering the user_segments view would also reveal this fact

select segment_name,bytes from user_segments where segment_name='INSERTDML';


This behavior was not observed in Oracle 11g R2.



--after initial insert

full_blocks 326
full_bytes 2670592

total_blocks 512
total_bytes 4194304
unused_blocks 0
unused_bytes 0
last_used_extent_file_id 4
last_used_extent_block_id 135296

--delete the rows

full_blocks 0
full_bytes 0

total_blocks 512
total_bytes 4194304
unused_blocks 0
unused_bytes 0
last_used_extent_file_id 4
last_used_extent_block_id 135296


--insert again

full_blocks 327
full_bytes 2678784

total_blocks 512
total_bytes 4194304
unused_blocks 0
unused_bytes 0
last_used_extent_file_id 4
last_used_extent_block_id 135296


Last used extent block id hasn't changed.

11g Compression and Segment Size

An easy way to observer the compresson in action is to query the user_segments view.

select segment_name,sum(bytes)
from user_extents where segment_type='TABLE'
group by segment_name order by 2 desc;

SEGMENT_NAME SUM(BYTES)
------------------------------ ----------
AIRLINE 196608

Compress the table with
alter table airline move compress for all operations;

But the reduction is always not visible in the user_segments view as the segment is not shrunk beyond the initial storage parameter.

select segment_name,sum(bytes)
from user_extents where segment_type='TABLE'
group by segment_name order by 2 desc;

SEGMENT_NAME SUM(BYTES)
------------------------------ ----------
AIRLINE 196608

It could be observed that compression is being enabled

select table_name,compression,compress_for from user_tables;

TABLE_NAME COMPRESS COMPRESS_FOR
------------------------------ -------- ------------------
AIRLINE ENABLED FOR ALL OPERATIONS

Looking at the storage parameters

... STORAGE(INITIAL 196608 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL KEEP)

But the actual compression could be observed with the dbms_space package.

Before compression

full_blocks 3
full_bytes 24576

total_blocks 24
total_bytes 196608
unused_blocks 18
unused_bytes 147456
last_used_extent_file_id 6
last_used_extent_block_id 1544

After compression

full_blocks 2
full_bytes 16384

total_blocks 24
total_bytes 196608
unused_blocks 19
unused_bytes 155648
last_used_extent_file_id 6
last_used_extent_block_id 128

There's a reduction in the total number of blocks and increase in the number of unused blocks.

The PL/SQL code is listed below

DECLARE
unformatted_blocks NUMBER;
unformatted_bytes NUMBER;
fs1_blocks NUMBER;
fs1_bytes NUMBER;
fs2_blocks NUMBER;
fs2_bytes NUMBER;
fs3_blocks NUMBER;
fs3_bytes NUMBER;
fs4_blocks NUMBER;
fs4_bytes NUMBER;
full_blocks NUMBER;
full_bytes NUMBER;

total_blocks NUMBER;
total_bytes NUMBER;
unused_blocks NUMBER;
unused_bytes NUMBER;
last_used_extent_file_id NUMBER;
last_used_extent_block_id NUMBER;
last_used_block NUMBER;

-- cursor t is select table_name from user_tables order by 1;
-- tname user_tables.table_name%type;
BEGIN
--open t;
--loop
--fetch t into tname;
--exit when t%notfound;

DBMS_SPACE.SPACE_USAGE('TX',
'AIRLINE',
'TABLE',
unformatted_blocks,
unformatted_bytes,
fs1_blocks,
fs1_bytes,
fs2_blocks,
fs2_bytes,
fs3_blocks,
fs3_bytes,
fs4_blocks,
fs4_bytes,
full_blocks,
full_bytes,
NULL);

-- dbms_output.put_line('table name '|| tname);
-- dbms_output.put_line('fs1_blocks ' || fs1_blocks );
-- dbms_output.put_line('fs1_bytes ' || fs1_bytes );
-- dbms_output.put_line('fs2_blocks '||fs2_blocks );
-- dbms_output.put_line('fs2_bytes '||fs2_bytes );
-- dbms_output.put_line('fs3_blocks '||fs3_blocks );
-- dbms_output.put_line('fs3_bytes '|| fs3_bytes );
-- dbms_output.put_line('fs4_blocks '|| fs4_blocks );
-- dbms_output.put_line('fs4_bytes '|| fs4_bytes );
dbms_output.put_line('full_blocks '|| full_blocks);
dbms_output.put_line('full_bytes '|| full_bytes );
dbms_output.put_line('');
--end loop;
--close t;

dbms_space.unused_space('TX',
'AIRLINE',
'TABLE',
total_blocks ,
total_bytes ,
unused_blocks ,
unused_bytes ,
last_used_extent_file_id ,
last_used_extent_block_id ,
last_used_block ,
NULL);

dbms_output.put_line('total_blocks '|| total_blocks);
dbms_output.put_line('total_bytes '|| total_bytes );
dbms_output.put_line('unused_blocks '|| unused_blocks);
dbms_output.put_line('unused_bytes '|| unused_bytes );
dbms_output.put_line('last_used_extent_file_id '|| last_used_extent_file_id);
dbms_output.put_line('last_used_extent_block_id '|| last_used_extent_block_id );
dbms_output.put_line('');


end;
/