Categories: SQL Tutorials

How to Recover ROW and PAGE Compressed Data in SQL Server?

The page in SQL Server is the fundamental unit to store data. It stores data and indexes. The rows are stored on pages of 8 KB. The pages are numbered and have an ID. The following query shows the page_id of the column, where the CustomerID is equal to 2 in the Sales.Customer table.

Query :
SELECT TOP 100 plc.*, [CustomerID]
FROM [Sales].[Customer] as c (nolock)
CROSS APPLY sys.fn_physLocCracker (%%physloc%%) As plc
WHERE c.CustomerID=2
GO

The pages can get corrupted due to various reasons, like virus attacks, malicious software, or hardware problems.

Row and Page Compression

In SQL Server, it is possible to compress the data at the row or page level. Data compression improves the I/O operation performance but increases the CPU usage. To enable data compression at the page level, the following T-SQL command can be used.


ALTER TABLE sales.customer REBUILD WITH (DATA_COMPRESSION = PAGE);

The above statement will modify the table – sale.customer and rebuild the table to use compression
at the page level. The below example shows how to compress data at the row level:

ALTER TABLE Sales.Customer
REBUILD WITH (DATA_COMPRESSION = ROW);

How to Recover Row and Page Compressed Data using SQL Server Tools?

Using the SQL Server Management Studio (SSMS), you can recover specific pages from a backup. For this, you will require a backup of the SQL database. The following command provides a backup of the database:

BACKUP DATABASE stellar
TO DISK = ‘C:\backup\stellar.bak’;

This command will create a backup of the database, named stellar, in the c:\ drive in the backup
folder and the stellar.bak file.
To restore a page, open Object Explorer, right-click on the database, and select Tasks > Restore >
Page.

You need to enter two things:

  1. The file ID that contains a numeric identifier of the data file.
  2. The page ID. You can get the page ID from the error message when you run the DBCC
    CHECKDB command:
    Msg 8909, Level 16, State 1, Line 1
    Table error: Object ID 13456, index ID 1, partition ID 4567890123, alloc unit
    ID 78901234 (type DATA), page ID 98765432 contains an incorrect page ID in its
    page header. The PageId in the page header = 543210.

To get the file ID, use this query:

SELECT name as FileName, file_id AS FileID
FROM sys.database_files;

You will see the file ID in the file_id column.
Now, press the add button, enter the File ID and the Page ID, and press OK.

After that, you will be able to recover the pages with errors.
Note: SQL Server allows to recover specific compressed pages, but not rows.

How to Recover Row and Page Compressed Data using a Third-Party Tool?

To recover compressed pages or rows, you can use a SQL Recovery tool, such as Stellar Repair for MS SQL. This software can repair the entire database, thus fixing the pages with errors. Once you download the software, you need to find your data file. The data file contains all the data and database pages. To find the data file, press the Find button :

Once you find the database file, take it offline and then make a copy.

Select the copy of the data file and press the Repair button to repair your database.

When the database is repaired, click the Save icon. You can save the repaired data in a new database
or in an existing database.

You can also save the data in other file formats, like Excel, CSV, and HTML. The software will export
the data from the repaired data file to the format of your preference.

Conclusion

In this article, we have discussed what the SQL Server pages are and how to compress data at row and page levels. We also mentioned the process of recovering specific SQL Server pages using tools in SQL Server. As there is no option in SQL Server to recover rows, you can use Stellar Repair for MS SQL to repair the database and recover the row and page compressed data.

Amit S

Oracle Consultant with vast experience in Oracle BI and PL/SQL Development. Amiet is the admin head of this website who contributes by preparing tutorials and articles related to database technologies. He is responsible to manage the content and front-end of the website.

Recent Posts

What is Root Cause Analysis (RCA) With real examples

In my previous article I have given details about application support engineer day to day…

4 weeks ago

Application Support Engineer Day to day responsibilities

In my previous articles I have given the roles and responsibilities of L1,L2 and L3…

1 month ago

What is mean by SLA ( Service Level Agreement) with Examples?

In my previous articles i have given the hierarchy of production support in real company…

1 month ago

What is Production support Hierarchy in organization?

In this article i would like to provide information about production support organization structure or…

1 month ago

What are roles and responsibilities for L3 Support Engineer?

In my previous article I have given roles for L1 and L2 support engineer with…

1 month ago

What are roles and responsibilities of L2 Engineer?

I have started this new series of how to become application support engineer. This article…

1 month ago