Download DataCompression_Scripts and Steps

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Microsoft SQL Server wikipedia , lookup

Clusterpoint wikipedia , lookup

Extensible Storage Engine wikipedia , lookup

Entity–attribute–value model wikipedia , lookup

Relational model wikipedia , lookup

Versant Object Database wikipedia , lookup

Database model wikipedia , lookup

Transcript
DATA COMPRESSION
Data compression uses the following 3 main procedures. These procedures need to be created on the
user database on which we are going to implement the compression.
1. sp_estimate_data_compression_savings [will be existing - just verification- MS inbuilt Procedure]
2. SP_CompressDatabase_OnlyPage [This has both ROW and PAGE- Modified for Page level
Compression; this will call procedure 1 and 3 internally]
3. db_compression_estimate [Procedure estimates ROW and PAGE Compression, Created by Paul
Nielsen ]
Step By Step Procedure:1. Create the following procedure in the database on which we are going to implement data
compression.
DB_Compress_onlyPage.SQL
2. Now create Data Compression estimate Procedure
db_compression_estimate.SQL
3. Verify the compression status before starting the compression, usually this will result 0 rows.
SELECT
SCHEMA_NAME(sys.objects.schema_id) AS [SchemaName]
,OBJECT_NAME(sys.objects.object_id) AS [ObjectName]
,[rows]
,[data_compression_desc]
,[index_id] as [IndexID_on_Table]
FROM sys.partitions
INNER JOIN sys.objects
ON sys.partitions.object_id = sys.objects.object_id
WHERE data_compression > 0
AND SCHEMA_NAME(sys.objects.schema_id) <> 'SYS'
ORDER BY SchemaName, ObjectName
4. Use PERFMON and set user defined counter to capture the usage of tempdb and user database
growth along with the file size.
5. Once the above steps are done, execute the below command to implement the compression.
Please start perfmon to capture intial sizes of tempdb and user database sizes and continue to
capture till complete.
Query :master.dbo.xp_cmdshell 'SQLCMD -S qtc-app149P\DBSQL2008R2 -d ManagerResearchPortal -E
-m 1 -Q "exec [dbo].[SP_CompressDatabase_OnlyPage] @minCompression = 0.0,
@MaxRunTimeInMinutes = 60,@ExecuteCompressCommand = 1, @DBToScan =
''ManagerResearchPortal''" -o "C:\compression_output1.txt"'
This will run 60Min and stops, once we re-ran this it will start from the tables which are pending
for compression, not from the beginning.
The above uses Server Name , DBName and OutputFile.
Sample Screens:1. SP Execution
2. Output File
compression_output1.txt
3. Compression Status
4. Compression Report
5. Temdb and UserDB Growth using PERFMON.
6. Output file can be verified in the destination mentioned above. Using query we can verify the
tables/objects which are completed.
select * from dbo.dbCompressionEstimates
Above query will give the estimation on all objects
select * from dbo.CompressionReport
Using above report we can find how much size saved by comparing before and after
compression.
7. Below query will results the total space saved
select table_name,total_size as SizeBeforeCompression into #t1 from
CompressionReport where comments='Beforecompression'
go
select table_name,total_size as SizeAfterCompression into #t2 from
CompressionReport where comments='Aftercompression'
go
select t.table_name, (t.SizeBeforeCompression-tt.SizeAfterCompression) as
SpaceSavedMB, ((t.SizeBeforeCompression-tt.SizeAfterCompression)/1024) as
SpaceSavedSIZEinGB from #t1 t join #t2 tt on t.table_name=tt.table_name order
by 2 desc
go
drop table #t1
go
drop table #t2
8.
9.
Verify the compression from Step 3 query.
Query to monitor tempdb user objects reserved space growth. Run this every 5 mins and
capture the growth. (Not required as we are using PERMON)
select convert(numeric(10,2),round(sum(data_pages)*8/1024.,2)) as
user_object_reserved_MB
from tempdb.sys.allocation_units a
inner join tempdb.sys.partitions b on a.container_id = b.partition_id
inner join tempdb.sys.objects c on b.object_id = c.object_id
Reverting Compression
1. Run the below query to undo the compression.
EXEC sp_MSforeachtable @command1 = 'alter table ? REBUILD WITH
(DATA_COMPRESSION = NONE);'
2. For a Particular Object.
ALTER TABLE [dbo].[tblLarge1] REBUILD PARTITION = ALL WITH (DATA_COMPRESSION =
NONE)
3. Truncate the below tables to capture fresh data.
truncate table dbo.dbCompressionEstimates
truncate table dbo.CompressionReport
4. Verify the using below query, should be zero rows.
SELECT
SCHEMA_NAME(sys.objects.schema_id) AS [SchemaName]
,OBJECT_NAME(sys.objects.object_id) AS [ObjectName]
,[rows]
,[data_compression_desc]
,[index_id] as [IndexID_on_Table]
FROM sys.partitions
INNER JOIN sys.objects
ON sys.partitions.object_id = sys.objects.object_id
WHERE data_compression > 0
AND SCHEMA_NAME(sys.objects.schema_id) <> 'SYS'
ORDER BY SchemaName, ObjectName