@@ -31,6 +31,8 @@ function Install-DbaMaintenanceSolution {
31
31
. PARAMETER ReplaceExisting
32
32
If this switch is enabled, objects already present in the target database will be dropped and recreated.
33
33
34
+ Note - The tables for `LogToTable` and `InstallParallel` will only be dropped if those options are also specified.
35
+
34
36
. PARAMETER LogToTable
35
37
If this switch is enabled, the Maintenance Solution will be configured to log commands to a table.
36
38
@@ -90,7 +92,7 @@ function Install-DbaMaintenanceSolution {
90
92
https://ola.hallengren.com
91
93
92
94
. LINK
93
- https://dbatools.io/Install-DbaMaintenanceSolution
95
+ https://dbatools.io/Install-DbaMaintenanceSolution
94
96
95
97
. EXAMPLE
96
98
PS C:\> Install-DbaMaintenanceSolution -SqlInstance RES14224 -Database DBA -InstallJobs -CleanupTime 72
@@ -119,17 +121,33 @@ function Install-DbaMaintenanceSolution {
119
121
120
122
Installs Maintenance Solution to myserver in database. Adds Agent Jobs, and if any currently exist, they'll be replaced.
121
123
124
+ Since the `LogToTable` switch is enabled, the CommandLog table will be dropped and recreated also.
125
+
126
+ If the tables relating to `InstallParallel` are present, they will not be dropped.
127
+
122
128
. EXAMPLE
123
- PS C:\> Install-DbaMaintenanceSolution -SqlInstance RES14224 -Database DBA -InstallJobs -BackupLocation "Z:\SQLBackup" -CleanupTime 72 -ReplaceExisting
129
+ PS C:\> $params = @{
130
+ >> SqlInstance = 'RES14224'
131
+ >> Database = 'DBA'
132
+ >> InstallJobs = $true
133
+ >> BackupLocation = 'Z:\SQLBackup'
134
+ >> CleanupTime = 72
135
+ >> ReplaceExisting = $true
136
+ >> }
137
+ PS C:\> Install-DbaMaintenanceSolution @params
124
138
125
139
This will drop and then recreate the Ola Hallengren's Solution objects
126
140
The cleanup script will drop and recreate:
127
- - TABLE [dbo].[CommandLog]
128
141
- STORED PROCEDURE [dbo].[CommandExecute]
129
142
- STORED PROCEDURE [dbo].[DatabaseBackup]
130
143
- STORED PROCEDURE [dbo].[DatabaseIntegrityCheck]
131
144
- STORED PROCEDURE [dbo].[IndexOptimize]
132
145
146
+ The tables will not be dropped as the `LogToTable` and `InstallParallel` switches are not enabled.
147
+ - [dbo].[CommandLog]
148
+ - [dbo].[Queue]
149
+ - [dbo].[QueueDatabase]
150
+
133
151
The following SQL Agent jobs will be deleted:
134
152
- 'Output File Cleanup'
135
153
- 'IndexOptimize - USER_DATABASES'
@@ -402,12 +420,6 @@ function Install-DbaMaintenanceSolution {
402
420
$cleanupQuery = $null
403
421
if ($ReplaceExisting ) {
404
422
[string ]$cleanupQuery = $ ("
405
- IF OBJECT_ID('[dbo].[CommandLog]', 'U') IS NOT NULL
406
- DROP TABLE [dbo].[CommandLog];
407
- IF OBJECT_ID('[dbo].[QueueDatabase]', 'U') IS NOT NULL
408
- DROP TABLE [dbo].[QueueDatabase];
409
- IF OBJECT_ID('[dbo].[Queue]', 'U') IS NOT NULL
410
- DROP TABLE [dbo].[Queue];
411
423
IF OBJECT_ID('[dbo].[CommandExecute]', 'P') IS NOT NULL
412
424
DROP PROCEDURE [dbo].[CommandExecute];
413
425
IF OBJECT_ID('[dbo].[DatabaseBackup]', 'P') IS NOT NULL
@@ -418,6 +430,22 @@ function Install-DbaMaintenanceSolution {
418
430
DROP PROCEDURE [dbo].[IndexOptimize];
419
431
" )
420
432
433
+ if ($LogToTable ) {
434
+ $cleanupQuery += $ ("
435
+ IF OBJECT_ID('[dbo].[CommandLog]', 'U') IS NOT NULL
436
+ DROP TABLE [dbo].[CommandLog];
437
+ " )
438
+ }
439
+
440
+ if ($InstallParallel ) {
441
+ $cleanupQuery += $ ("
442
+ IF OBJECT_ID('[dbo].[QueueDatabase]', 'U') IS NOT NULL
443
+ DROP TABLE [dbo].[QueueDatabase];
444
+ IF OBJECT_ID('[dbo].[Queue]', 'U') IS NOT NULL
445
+ DROP TABLE [dbo].[Queue];
446
+ " )
447
+ }
448
+
421
449
if ($Pscmdlet.ShouldProcess ($instance , " Dropping all objects created by Ola's Maintenance Solution" )) {
422
450
Write-ProgressHelper - ExcludePercent - Message " Dropping objects created by Ola's Maintenance Solution"
423
451
$null = $db.Invoke ($cleanupQuery )
0 commit comments