1. 程式人生 > >SAP SQL 壓縮 Database compression for SQL Server

SAP SQL 壓縮 Database compression for SQL Server

Note 1488135 - Database compression for SQL Server

Symptom

Depending on the SAP and SQL Server release, there are different compression types which can be used to save disk space with SAP NetWeaver running on SQL Server. This note describes how to implement ROW and PAGE compression for SQL Server 2008 (and newer) for SAP products based on Application Server ABAP. It does not cover older SQL Server releases or other SAP products like SAP Application Server JAVA, SAP CRM Mobile Client or SAP Business Objects products.

The attached SDN article "Using SQL Server Database Compression with SAP NetWeaver" contains a more detailed description and also covers compression types of older SQL Server releases. The SDN article is also available at http://www.sdn.sap.com/irj/sdn/sqlserver


Other terms


Reason and Prerequisites

In order to benefit from ROW or PAGE compression you have to run a supported SQL Server release as well as a supported SAP NetWeaver release.


Supported SQL Server releases

SQL Server 2008
As of SQL Server 2008, a table or index has one of the following compression types:
NONE: The table or index is not compressed.
ROW:All rows are stored in variable length. This compression type has no CPU overhead, but saves disk space and reduces disk I/O.
PAGE:Page compression is always performed on top of row compression. It even saves more disk space, but there might be a higher CPU load on the database server. However, customer experience showed an improved overall system performance with PAGE compression due to disk I/O reduction and higher cache hit ratio.
SQL Server 2008 R2
SQL Server 2008 R2 stores row or page compressed UCS-2 characters more efficient than SQL Server 2008. The space usage of a UCS-2 character is roughly the same as a UTF-8 character would need, once a table is row or page compressed. This feature is called UCS-2 Compression or Unicode Compression. However, it is completely transparent for a database administrator.


Supported compression types by SAP

Row compression for tables (heap or clustered index)
Before September 2010, the SAP Data Dictionary created new tables on SQL Server 2008 with compression type ROW and all new non-clustered indexes with compression type NONE. When converting an existing table manually in SAP transaction SE14 or during an SAP upgrade, the compression type of a table was not changed (it stayed NONE, ROW, or PAGE). However, non-clustered indexes were always created with compression type NONE.
Row compression for (non-clustered) indexes
In September 2010, SAP released correction instructions in SAP note 1459005 for SAP Basis 7.00 and all newer releases. These corrections are included in future SAP BASIS support packages. The corrected SAP data dictionary supports row and page compression for tables (with row compression as default). All new indexes are created with the same compression type as their table. SAP calls the new feature to compress indexes (as row- or page-compressed) index compression. This is actually not a SQL Server compression type. It is simply the name of an SAP feature.
Page compression for tables and indexes
In May 2011, SAP changed the default compression for new installations to page compression.

Solution

To fully benefit from row or page compression you have to perform the following steps:

1. Upgrade to SQL Server 2008 or higher
2. Update the SAP Data Dictionary
3. Configure SQL Server data compression within SAP
4. Compress existing tables using report MSSCOMPRESS


The following sections describe all needed activities in detail:


Upgrade to SQL Server 2008 or higher

As of SQL Server 2008 you can use ROW or PAGE compression. In order to benefit from UCS-2 compression you need at least SQL Server 2008 R2. For more information, see SAP note 1152240 "Setting Up Microsoft SQL Server 2008 (R2)".

The space used for already compressed rows does not change when upgrading from SQL Server 2008 to SQL Server 2008 R2. To benefit from the UCS-2 compression, you have to re-compress existing tables using the report MSSCOMPRESS with the options "Force Data Rebuild" and "Force Index Rebuild"


Update the SAP Data Dictionary

Install the SAP_BASIS support packages or correction instructions as described in SAP note 1459005 "Enabling Index Compression for SQL Server".


Configure SQL Server data compression within SAP

The compression type for new tables depends on the SAP profile parameter dbs/mss/compression and the SAP Data Dictonary version. If the profile parameter dbs/mss/compression is set to PAGE, ROW or NONE then new tables will be created with this compression type. If dbs/mss/compression is set to DEFAULT or not set at all then the compression type of new tables depends on the default in the SAP Data Dictonary. The default compression type is:

ROW compression as of September 2010 (with the correction of SAP note 1459005)
PAGE compression as of May 2011 (with the correction of SAP note 1581700)

You can overwrite the default compression type by adding one of the following lines in the SAP Default Profile. It does not work for the SAP Instance Profile to ensure the same setting for all SAP application servers):

dbs/mss/compression = page
dbs/mss/compression = row
dbs/mss/compression = none

The name of the profile parameter "dbs/mss/compression" must be in lower case. You may edit the default profile manually or use SAP transaction RZ10. The parameter dbs/mss/compression is not known in RZ10. Nevertheless, the parameter will work (once you have activated it and restarted your SAP system).
Keep in mind that the compression type of already existing tables is not changed. The compression type of indexes always depends on the compression type of the table.


Compress existing tables

Use SAP report MSSCOMPRESS to compress existing tables using the same compression type as configured in the last step. Since the compression of a huge SAP database can take several days, you can perform the compression in chunks using SAP batch jobs.

A transport of the report MSSCOMPRESS is attached to this note. A detailed description is also attached as a PDF file (SDN article "Using SQL Server Database Compression with SAP NetWeaver")

The transport is only intended for the following SAP Basis releases:

SAP_BASIS Release  Support Package
NetWeaver 7.0  SP22 and older
EHP1 for SAP NetWeaver 7.0 SP07 and older
EHP2 for SAP NetWeaver 7.0 SP04 and older
NetWeaver 7.1  SP10 and older
EHP1 for NetWeaver 7.1 SP05 and older
NetWeaver 7.3  SP00


All newer SAP NetWeaver releases already contain the report MSSCOMPRESS. Do not import this transport there!

This note also contains a correction instruction, which extents report MSSCOMPRESS for using SQL Server 2012 Column-Store. See SAP note 1771177 for details.

SAP Installation, Migration and Upgrade

SAP uses the executable r3load for creating new tables during installation, migration and upgrade. R3load does not take care of SAP profile parameters. Since there is no way to keep the compression type of the SAP Data Dictionary in sync with the compression type of r3load, the compression type of new (and even existing) tables may change during an SAP upgrade. Therefore you should re-compress these tables using report MSSCOMPRESS after an SAP upgrade.

You may change the default compression type of r3load to PAGE by modifying the file DDLMSS.TPL, which is located in the SAPINST directory and on the exports DVDs. The modified lines are printed bold:

prikey: BEFORE_LOAD ORDER_BY_PKEY
seckey: AFTER_LOAD

# cretab and creind: compression supported with SQL 2008 and higher
# see note 1505884 for the supported compression types

cretab: CREATE TABLE &tab_name&
        ( /{ &fld_name& &fld_desc& /-, /} ) &compression_page&

drptab: DROP TABLE &tab_name&

crepky: ALTER TABLE &tab_name&
        ADD CONSTRAINT &pri_key&
        PRIMARY KEY &clustered& ( /{ &key_fld& /-, /} )

drppky: ALTER TABLE &tab_name&
        DROP CONSTRAINT &pri_key&

creind: CREATE &unique& INDEX &ind_name&
        ON &tab_name&
        ( /{ &fld_name& /-, /} ) &compression_page&

drpind: DROP INDEX &tab_name&.&ind_name&

crevie: CREATE VIEW &view_name&
        ( /{ &fld_name& /-, /} )
        AS &query&

drpvie: DROP VIEW &view_name&

trcdat: TRUNCATE TABLE &tab_name&

deldat: DELETE FROM &tab_name& &where&

negtab: LICHECK MLICHECK

negdat: LICHECK MLICHECK
negind: LICHECK~0 MLICHECK~0 LICHECK^0 MLICHECK^0

negvie:


Configure Page Compression for System Copies and Migrations

Always read SAP note 888210 before starting a Homogeneous or Heterogeneous System Copy. In order to benefit from page compression, you have to perform the following steps:

1. Apply SAP note 1581700 on the source system
The correction instruction in this SAP note updates the default compression type of the SAP data dictionary to page compression. This will later affect the target system, too.
2. Use the newest SAP kernel including r3load and r3ldctl
for export and import. The newest r3ldctl creates a correct DDLMSS.TPL file during the export on the source system. R3load will then create all tables page compressed during the import into the target system.
3. Remove the profile parameter dbs/mss/compression
on the target system. Since the default in the SAP data dictionary is already page compression, there is no need any more to override the default.