24
DATA & BACKUP COMPRESSION IN SQL SERVER 2008 André Kamman Friday November 20 th @ SQLBITS IV

Data & Backup Compression in SQL Server 2008

Embed Size (px)

DESCRIPTION

André Kamman Friday November 20 th @ SQLBITS IV. Data & Backup Compression in SQL Server 2008. About Me. André Kamman > 20 years in IT Main focus on complex SQL Server environments (or a whole lot of less complex ones) Co-founder, current chairman of Dutch PASS Chapter (sqlpass.nl) - PowerPoint PPT Presentation

Citation preview

Page 1: Data & Backup Compression in SQL Server 2008

DATA & BACKUP COMPRESSIONIN SQL SERVER

2008

André Kamman

Friday November 20th @ SQLBITS IV

Page 2: Data & Backup Compression in SQL Server 2008

About Me André Kamman > 20 years in IT

Main focus on complex SQL Server environments (or a whole lot of less complex ones)

Co-founder, current chairman of Dutch PASS Chapter (sqlpass.nl)

Organizing Committee for the PASS European Conference

Page 3: Data & Backup Compression in SQL Server 2008

Agenda

Why compress ? Backup Compression Data Compression

Row, Page, Unicode (R2) How to choose How to implement Maintainability

Page 4: Data & Backup Compression in SQL Server 2008

Why Compress ?

Disk throughput (a lot) slower than memory and CPU

David DeWitt keynote at PASS Summit :Since 1985 CPU x 1000 fasterSince 1985 Disk x 65 (!) fasterMuch larger capacity for disks but bandwith

and seek times not so much result in a 150 x relatively slower disk.

Need less disk space

Page 5: Data & Backup Compression in SQL Server 2008

Backup Compression Enterprise & Developer Edition only

Can restore to Standard Edition Also in Standard Edition starting at R2 ! Closest to the data, generally better than

compressing when copying or deduping on the san for instance.

Lots of competition from Quest, Redgate, Idera, Hyperbac, etc.

Still adds value after implementing Data Compression

Page 6: Data & Backup Compression in SQL Server 2008

Row Compression

Stores fixed length types as variable length. (with improved overhead)

i.e.: int (4 bytes) can be stored in 1 byte if the value is low enough

Makes vardecimal obsolete. Can still be used but is deprecated.

Page 7: Data & Backup Compression in SQL Server 2008

Good to know

Compression also in memory Implications on replication Transaction log, Version store and Non-

leaf pages stored row compressed only Can’t restore to standard edition Fix : KB963658 Compression is

removed after shrink Don’t shrink !

Or at least mind the fragmentation !

Page 8: Data & Backup Compression in SQL Server 2008

Page Compression

Page Header

aaabb aaaab abcd

aaabcc bbbb abcd

aaaccc aaaacc bbbb

4b 4b

3ccc

0bbbb

0bbbb

Pre-Fix Dictionary

0 0

1

1

Page 9: Data & Backup Compression in SQL Server 2008

Unicode Compression in SQL Server 2008 R2 SCSU

Simple Compression Scheme for Unicode Data

Uses 1 byte instead of 2 when it can.

Page 10: Data & Backup Compression in SQL Server 2008

How to Choose - Effectiveness

Good Compression

Numeric or fixed length character fields that don’t use all the allocated bytes

Repeating data or prefix values

Poor or no Compression

Fields using up all the allocated bytes

Not much repeated data Repeated with non-

repeating prefixes Out of row data FILESTREAM data

Page 11: Data & Backup Compression in SQL Server 2008

How to choose

sp_estimate_data_compression_savings Quick Rule of thumb :

ROW is lowcost, generally 10% CPU overhead. Use it on everything on OLTP

PAGE is more expensive, but compresses more. Us it on everything on DWH

Analyze Workload Characteristics(to help decide on Page Compression candidates)

Page 12: Data & Backup Compression in SQL Server 2008

Example of decision matrix

Page 13: Data & Backup Compression in SQL Server 2008

How to Implement

Table, Index, Partition Create, alter …rebuild Can only set ROW or PAGE

Mind tempspace, cpu etc. This is just like an Index Rebuild

Mind cpu even more with ONLINE option

Page 14: Data & Backup Compression in SQL Server 2008

Some code examples

Page 15: Data & Backup Compression in SQL Server 2008

CREATE TABLE T1 (c1 int, c2 nvarchar(50) ) WITH (DATA_COMPRESSION = ROW)

CREATE TABLE PartitionTable1 (col1 int, col2 varchar(max))ON myRangePS1 (col1) WITH ( DATA_COMPRESSION = ROW ON PARTITIONS (1), DATA_COMPRESSION = PAGE ON PARTITIONS (2 TO 4));GO

Page 16: Data & Backup Compression in SQL Server 2008

ALTER TABLE T1 REBUILD WITH (DATA_COMPRESSION = PAGE);GO

ALTER TABLE PartitionTable1 REBUILD PARTITION = ALL WITH (DATA_COMPRESSION = PAGE ON PARTITIONS(1) ) ;GO

ALTER TABLE PartitionTable1 REBUILD PARTITION = ALL WITH(DATA_COMPRESSION = PAGE ON PARTITIONS(1), DATA_COMPRESSION = ROW ON PARTITIONS(2 TO 4) ) ;GO

Page 17: Data & Backup Compression in SQL Server 2008

ALTER INDEX IX_INDEX_1 ON T1REBUILD WITH ( DATA_COMPRESSION = PAGE ) ;GO

ALTER INDEX IX_PartTab2Col1 ON PartitionTable1REBUILD PARTITION = ALL WITH(DATA_COMPRESSION = PAGE ON PARTITIONS(1), DATA_COMPRESSION = ROW ON PARTITIONS(2 TO 4) ) ;GO

Page 18: Data & Backup Compression in SQL Server 2008

Maintainability - Monitor

PerfmonPage compression attempts/secPages compressed/sec

(SQL Server, Access Methods object) Sys.dm_db_index_operational_stats Sys.dm_db_persisted_sku_features Sys.partitions

(column data_compression_desc)

Page 19: Data & Backup Compression in SQL Server 2008

Maintenance

HeapPages are only compressed when bulk inserted, inserted with tablock or rebuild

Table with clustered indexPages are compressed when page is full. (before page split is attempted)

Page 20: Data & Backup Compression in SQL Server 2008

Quiz

Page 21: Data & Backup Compression in SQL Server 2008

Questions ?

Page 22: Data & Backup Compression in SQL Server 2008

Contact me :

Email : [email protected] Twitter : @AndreKamman Blog : http://andrekamman.com

This presentation : http://andrekamman.com/presentations

Or just stop me when you run into me

Page 23: Data & Backup Compression in SQL Server 2008

Thank you !

Don’t forget to fill out the evals please !

Page 24: Data & Backup Compression in SQL Server 2008

Links / Resources SQLCAT.com whitepaper : http://

sqlcat.com/whitepapers/archive/2009/05/29/data-compression-strategy-capacity-planning-and-best-practices.aspx

(Couple of very useful links to blogs etc. inside this whitepaper!)

Storage Engine Team Blog on Compression :

http://blogs.msdn.com/sqlserverstorageengine/archive/tags/Data+Compression/default.aspx

Don’t shrink : http://www.sqlskills.com/BLOGS/PAUL/post/Auto-shrink-e28093-turn-it-OFF!.

aspx http://

www.sqlskills.com/BLOGS/PAUL/post/Why-you-should-not-shrink-your-data-files.aspx