Switch-SqlAvailabilityGroup
Starts a failover of an availability group to a secondary replica.
语法
ByPath (默认值)
Switch-SqlAvailabilityGroup
[[-Path] <String[]>]
[-AllowDataLoss]
[-Force]
[-Script]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
ByObject
Switch-SqlAvailabilityGroup
[-InputObject] <AvailabilityGroup[]>
[-AllowDataLoss]
[-Force]
[-Script]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
说明
The Switch-SqlAvailabilityGroup cmdlet starts a failover of an availability group to a specified secondary replica. Run this cmdlet on the target secondary replica. After the failover, the secondary replica becomes the primary replica.
示例
Example 1: Fail over an availability group
PS C:\> Switch-SqlAvailabilityGroup -Path "SQLSERVER:\Sql\SecondaryServer\InstanceName\AvailabilityGroups\MainAG"
This command performs a manual failover of the availability group MainAG to the server instance named SecondaryServer\InstanceName. This command does not allow data loss. Run this command on the server instance that hosts the secondary replica to which to fail over.
Example 2: Force an availability group to fail over
PS C:\> Switch-SqlAvailabilityGroup -Path "SQLSERVER:\Sql\SecondaryServer\InstanceName\AvailabilityGroups\MainAG" -AllowDataLoss
This command performs a manual failover of the availability group MainAG to the server instance named SecondaryServer\InstanceName. The command specifies the AllowDataLoss parameter. Therefore, the failover has the potential of data loss, and the command prompts you for confirmation. Specify the Force parameter to skip the confirmation.
Example 3: Create a script to fail over an availability group
PS C:\>Switch-SqlAvailabilityGroup -Path "SQLSERVER:\Sql\SecondaryServer\InstanceName\AvailabilityGroups\MainAG" -Script
This command creates a Transact-SQL script that performs a manual failover of the availability group MainAG to the server instance named SecondaryServer\InstanceName. The script does not allow data loss. The command does not cause failover.
参数
-AllowDataLoss
Indicates that this cmdlet starts a forced failover to the target secondary replica. Data loss is possible. Unless you specify the Force or Script parameter, the cmdlet prompts you for confirmation.
参数属性
类型: | SwitchParameter |
默认值: | None |
支持通配符: | False |
不显示: | False |
参数集
(All)
Position: | Named |
必需: | False |
来自管道的值: | False |
来自管道的值(按属性名称): | False |
来自剩余参数的值: | False |
-Confirm
Prompts you for confirmation before running the cmdlet.
参数属性
类型: | SwitchParameter |
默认值: | False |
支持通配符: | False |
不显示: | False |
别名: | cf |
参数集
(All)
Position: | Named |
必需: | False |
来自管道的值: | False |
来自管道的值(按属性名称): | False |
来自剩余参数的值: | False |
-Force
Forces the command to run without asking for user confirmation. This cmdlet prompts you for confirmation only if you specify the AllowDataLoss parameter.
参数属性
类型: | SwitchParameter |
默认值: | None |
支持通配符: | False |
不显示: | False |
参数集
(All)
Position: | Named |
必需: | False |
来自管道的值: | False |
来自管道的值(按属性名称): | False |
来自剩余参数的值: | False |
-InputObject
Specifies availability group that this cmdlet fails over.
参数属性
类型: | AvailabilityGroup[] |
默认值: | None |
支持通配符: | False |
不显示: | False |
参数集
ByObject
Position: | 2 |
必需: | True |
来自管道的值: | True |
来自管道的值(按属性名称): | False |
来自剩余参数的值: | False |
-Path
Specifies the path of the availability group that this cmdlet fails over. If you do not specify this parameter, this cmdlet uses current working location.
参数属性
类型: | String[] |
默认值: | None |
支持通配符: | False |
不显示: | False |
参数集
ByPath
Position: | 2 |
必需: | False |
来自管道的值: | False |
来自管道的值(按属性名称): | False |
来自剩余参数的值: | False |
-Script
Indicates that this cmdlet returns a Transact-SQL script that performs the task that this cmdlet performs.
参数属性
类型: | SwitchParameter |
默认值: | None |
支持通配符: | False |
不显示: | False |
参数集
(All)
Position: | Named |
必需: | False |
来自管道的值: | False |
来自管道的值(按属性名称): | False |
来自剩余参数的值: | False |
-WhatIf
Shows what would happen if the cmdlet runs. The cmdlet is not run.
参数属性
类型: | SwitchParameter |
默认值: | False |
支持通配符: | False |
不显示: | False |
别名: | wi |
参数集
(All)
Position: | Named |
必需: | False |
来自管道的值: | False |
来自管道的值(按属性名称): | False |
来自剩余参数的值: | False |
CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.
输入
Microsoft.SqlServer.Management.Smo.AvailabilityGroup
You can pass an availability group to this cmdlet.