Invoke-DbaDbShrink - Add WAIT_AT_LOW_PRIORITY support#10307
Invoke-DbaDbShrink - Add WAIT_AT_LOW_PRIORITY support#10307potatoqualitee merged 4 commits intodevelopmentfrom
Conversation
…FILE T-SQL Replaces SMO $file.Shrink() calls with direct DBCC SHRINKFILE T-SQL to enable WAIT_AT_LOW_PRIORITY support (SQL Server 2022+). Adds -WaitAtLowPriority switch and -AbortAfterWait parameter (Self|Blockers). Includes version guard with Stop-Function for older instances. Updates parameter validation tests. Closes #10193 (do Invoke-DbaDbShrink) Co-authored-by: Andreas Jordan <andreasjordan@users.noreply.github.com>
|
Haven't tested, but it looks to be pretty much what I expected. My only nitpicks are:
|
|
@claude Test fail with: Also read the comment from Reece and try to implement his suggestion. |
|
Claude finished @andreasjordan's task in 8m 49s —— View job Fixing test failure and implementing Reece's suggestion
What was doneFix: Test failure ( The New test: Verifies Added a test that:
This verifies that the |
…ock verification - Remove redundant ALTER DATABASE MODIFY FILE calls in WaitAtLowPriority test (BeforeEach already grows files to 16384KB; re-growing to same size caused failure) - Add new test that verifies WAIT_AT_LOW_PRIORITY actually shows LCK_M_SCH_M_LOW_PRIORITY in sys.dm_exec_requests by holding a DDL lock with sp_addextendedproperty in a transaction while the shrink runs (do Invoke-DbaDbShrink) Co-authored-by: Andreas Jordan <andreasjordan@users.noreply.github.com>
|
Maybe my idea was bad? The locks from adding an extended property are <Database name="model">
<Locks>
<Lock request_mode="S" request_status="GRANT" request_count="1" />
</Locks>
<Objects>
<Object name="sysxprops" schema_name="sys">
<Locks>
<Lock resource_type="KEY" index_name="clust" request_mode="X" request_status="GRANT" request_count="1" />
<Lock resource_type="OBJECT" request_mode="IX" request_status="GRANT" request_count="1" />
</Locks>
</Object>
</Objects>
</Database> |
|
Wow. All of my ideas for testing this were bad. Look I what I just got from
Perhaps a better test is to either:
Getting a lock nasty enough for my second idea has proven difficult. I suggest the first idea instead. At this point, I can't even prove to myself that Microsoft's implementation of |
|
@claude can you help? |
|
Claude finished @andreasjordan's task in 4m 39s —— View job Fixing the WAIT_AT_LOW_PRIORITY test
What was changedReplaced the "Verifies WAIT_AT_LOW_PRIORITY shows LCK_M_SCH_M_LOW_PRIORITY in DMV when blocked" test with "Verifies WAIT_AT_LOW_PRIORITY SQL syntax appears in running requests when blocked". The problem with the old test: It checked for The fix (per ReeceGoding's suggestion to "grab the SQL text and see if WAIT_AT_LOW_PRIORITY is in those strings"):
This directly verifies the generated T-SQL contains the |
…tead of lock wait type Replace the DMV lock wait type check (LCK_M_SCH_M_LOW_PRIORITY) with a SQL text check via sys.dm_exec_requests + sys.dm_exec_sql_text. This is per ReeceGoding's suggestion after investigating that the actual wait type during a blocked DBCC SHRINKFILE WITH WAIT_AT_LOW_PRIORITY is LCK_M_X, not LCK_M_SCH_M_LOW_PRIORITY. The blocker now uses TABLOCKX+HOLDLOCK on a table with data to reliably hold a lock that forces the shrink to wait. The test verifies the generated DBCC SHRINKFILE T-SQL contains WAIT_AT_LOW_PRIORITY by querying the DMV SQL text. (do Invoke-DbaDbShrink) Co-authored-by: Andreas Jordan <andreasjordan@users.noreply.github.com>
|
I'm very surprised. I've thrown an unplanned few hours at it and I have not been able to produce a demo showing Regardless, I agree with the approach Claude has now taken. Assuming that the test passes, then I'm happy. |
|
👌🏼 thank you both! |
Adds WAIT_AT_LOW_PRIORITY support to Invoke-DbaDbShrink by replacing the SMO
$file.Shrink()calls with direct DBCC SHRINKFILE T-SQL.New parameters:
-WaitAtLowPriority(switch)-AbortAfterWait(SelforBlockers, default Self) — no None option as DBCC SHRINKFILE does not support itRequires SQL Server 2022+; a version guard via Stop-Function is included for older instances.
Closes #10193
Generated with Claude Code