A little more about compression

Happy Monday folks!  Ready to talk some more about compression?

Unicode Compression

Another type of compression new in SQL Server 2008 is Unicode compression.  This is basically row compression for nchar and nvarchar datatypes.  Per BOL, SQL Server uses the Standard Compression Scheme for Unicode (SCSU) algorithm to achieve up to 50% space savings on some european languages, less so with Asian languages but still respectable.  If you really want to know more about what goes on behind the scenes in unicode compression, start with the wiki for the SCSU algorithm and go from there.

Backup Compression

The compression feature that I, personally, have made the most use of thus far would have to be backup compression.  Not only has this greatly reduced the size of my database backups, but it has also increased backup speed (less I/O).  The actual compression ratio is dependent on the data being backed up, whether that data is encrypted (this will not compress as much), and whether the database itself is already compressed.

Like the other types of compression, backup compression does use more CPU, but since we’re usually taking backups during quieter hours, I’ve not noticed any impact on performance.  If performance is a concern, you can always use resource governor to throttle how much CPU the backup process can use.

Backup compression can be used on an ad-hoc basis using the WITH COMPRESSION option of the BACKUP DATABASE command or it can be set globally using sp_configure (“EXEC sp_configure ‘backup compression default’, ‘1’;”).  If you set the compression default at the server level, this can always be overridden at the time of the backup.

Compression Considerations

Now before you run off and start compressing everything, there are some things you might want to keep in mind.

  • Performance – Nothing in life is free and this is no exception.  As I’ve mentioned before, the trade-off for disk savings is increased CPU usage.  If you’re already processor-bound, you might want to think twice before implementing data compression.
  • Version – Compression is currently only available in the Enterprise and Developer editions.  A compressed database cannot be restored to a Standard Edition instance.
  • Partitioning – You can compress (or not compress) each partition individually, and each partition can use a different type of compression.
  • Indexes – Clustered indexes inherit the compression property of the table, non-clustered indexes do not.  If you change the compression settings on a heap, all non-clustered indexes will be rebuilt.
  • Replication – By default, the initial snapshot will contain the same compression settings as the published object(s).  You can change the replication defaults to control whether compression settings are replicated.  If you try to replicate a compressed table to a Standard edition database, replication will fail.
  • Monitoring – You can monitor compression via the Page compression attempts/sec and Pages compressed/sec counters in the Access Methods object of Perfmon.

Also recommended:

Leave a comment

Your email address will not be published.