Troubleshooting Guide: Error 5249 – Page Could Not Be Moved Because Shrink Could Not Lock the Page
Why This Error Happens
This error occurs when SQL Server’s DBCC SHRINKFILE or DBCC SHRINKDATABASE operation attempts to relocate a page during the shrink process, but another session is holding a lock on that page at the same moment. This is typically caused by concurrent transactions, active queries, or replication/CDC processes accessing the same data pages being targeted for deallocation. It can also surface more frequently under heavy OLTP workloads where shrink operations compete with normal transactional activity for page-level locks.
Step-by-Step Resolution Guide
Step 1: Identify Blocking Sessions and Active Transactions
- Open SQL Server Management Studio (SSMS) and run
sp_who2or querysys.dm_exec_requeststo identify sessions holding locks on the target database. - Check
sys.dm_tran_locksfiltered byresource_database_idto pinpoint which session IDs (SPIDs) are locking pages in the file being shrunk. - Note down any long-running transactions, open CDC/replication jobs, or index maintenance tasks running concurrently.
Step 2: Pause Conflicting Operations Before Retrying Shrink
- Temporarily disable or pause SQL Server Agent jobs, replication, or Change Data Capture (CDC) processes that may be touching the same tables.
- Navigate to SQL Server Agent > Jobs in SSMS and disable any jobs scheduled to run during the shrink window.
- Ensure no index rebuild/reorganize operations are active by checking
sys.dm_exec_requestsforcommand = 'DBCC'or'ALTER INDEX'.
Step 3: Run Shrink During a Low-Activity Window
- Schedule the shrink operation during off-peak hours using Windows Task Scheduler or SQL Server Agent to minimize lock contention.
- Use a smaller, incremental shrink approach instead of a single large operation:
DBCC SHRINKFILE (N'YourDataFile', 1024);
- Repeat the command in small batches rather than shrinking the entire file at once, allowing SQL Server to retry page moves with less contention.
Step 4: Rebuild Indexes After Shrink to Reduce Fragmentation Conflicts
- Since shrink operations can cause significant fragmentation, run an index rebuild immediately after the shrink completes.
- Use the following command, replacing with your actual table/index name:
ALTER INDEX ALL ON YourTableName REBUILD;
- This reduces the chance of repeated page-lock conflicts on subsequent shrink attempts.
Step 5: Verify Database and File Health
- Run
DBCC CHECKDBto ensure no underlying corruption is contributing to abnormal locking behavior. - Confirm the database is not in an unexpected state (e.g.,
SINGLE_USERorEMERGENCY) using:
SELECT state_desc FROM sys.databases WHERE name = 'YourDatabaseName';
Alternative or Verification Steps
- Re-run
DBCC SHRINKFILEafter completing the steps above and confirm no Error 5249 messages appear in the SQL Server Error Log or Windows Event Viewer (Event ID 5249). - If the issue persists, consider setting the database to
SINGLE_USERmode temporarily (during a maintenance window) to eliminate all concurrent access before retrying the shrink operation.