-
Notifications
You must be signed in to change notification settings - Fork 225
SqlAGReplica
dscbot edited this page Jul 19, 2020
·
11 revisions
Parameter | Attribute | DataType | Description | Allowed Values |
---|---|---|---|---|
Name | Key | String | The name of the availability group replica. For named instances this must be in the following format 'ServerName\InstanceName' . |
|
AvailabilityGroupName | Key | String | The name of the availability group. | |
ServerName | Required | String | Hostname of the SQL Server to be configured. | |
InstanceName | Key | String | Name of the SQL Server instance to be configured. | |
PrimaryReplicaServerName | Write | String | Hostname of the SQL Server where the primary replica is expected to be active. If the primary replica is not found here, the resource will attempt to find the host that holds the primary replica and connect to it. | |
PrimaryReplicaInstanceName | Write | String | Name of the SQL Server Database Engine instance where the primary replica lives. | |
Ensure | Write | String | Specifies if the availability group replica should be present or absent. Default value is 'Present' . |
Present, Absent |
AvailabilityMode | Write | String | Specifies the replica availability mode. When creating a replica the default is 'AsynchronousCommit' . |
AsynchronousCommit, SynchronousCommit |
BackupPriority | Write | UInt32 | Specifies the desired priority of the replicas in performing backups. The acceptable values for this parameter are: integers from 0 through 100 . Of the set of replicas which are online and available, the replica that has the highest priority performs the backup. When creating a replica the default is 50 . |
|
ConnectionModeInPrimaryRole | Write | String | Specifies how the availability replica handles connections when in the primary role. | AllowAllConnections, AllowReadWriteConnections |
ConnectionModeInSecondaryRole | Write | String | Specifies how the availability replica handles connections when in the secondary role. | AllowNoConnections, AllowReadIntentConnectionsOnly, AllowAllConnections |
EndpointHostName | Write | String | Specifies the hostname or IP address of the availability group replica endpoint. When creating a group the default is the instance network name which is set in the code because the value can only be determined when connected to the SQL Server instance. | |
FailoverMode | Write | String | Specifies the failover mode. When creating a replica the default value is 'Manual' . |
Automatic, Manual |
ReadOnlyRoutingConnectionUrl | Write | String | Specifies the fully qualified domain name (FQDN) and port to use when routing to the replica for read only connections. | |
ReadOnlyRoutingList | Write | StringArray[] | Specifies an ordered list of replica server names that represent the probe sequence for connection director to use when redirecting read-only connections through this availability replica. This parameter applies if the availability replica is the current primary replica of the availability group. | |
ProcessOnlyOnActiveNode | Write | Boolean | Specifies that the resource will only determine if a change is needed if the target node is the active host of the SQL Server instance. | |
EndpointPort | Read | UInt16 | Returns the network port the endpoint is listening on. | |
EndpointUrl | Read | String | Returns the URL of the availability group replica endpoint. | |
IsActiveNode | Read | Boolean | Returns if the current node is actively hosting the SQL Server Database Engine instance. |
The SqlAGReplica
DSC resource is used to create, remove, and update an
Always On Availability Group Replica.
- Target machine must be running Windows Server 2012 or later.
- Target machine must be running SQL Server Database Engine 2012 or later.
- 'NT SERVICE\ClusSvc' or 'NT AUTHORITY\SYSTEM' must have the 'Connect SQL', 'Alter Any Availability Group', and 'View Server State' permissions.
- There are circumstances where the PowerShell module SQLPS that is install
together with SQL Server does not work with all features of this resource.
The solution is to install the PowerShell module SqlServer
from the PowerShell Gallery. The module must be installed in a machine-wide
path of
env:PSModulePath
so it is found when LCM runs the DSC resource. This will also make all SqlServerDsc DSC resources use the PowerShell module SqlServer instead of the PowerShell module SQLPS.
All issues are not listed here, see here for all open issues.
This example shows how to ensure that the Availability Group Replica 'SQL2' exists in the Availability Group 'TestAG'.
In the event this is applied to a Failover Cluster Instance (FCI), the ProcessOnlyOnActiveNode property will tell the Test-TargetResource function to evaluate if any changes are needed if the node is actively hosting the SQL Server Instance.
Configuration Example
{
param
(
[Parameter(Mandatory = $true)]
[System.Management.Automation.PSCredential]
$SqlAdministratorCredential
)
Import-DscResource -ModuleName 'SqlServerDsc'
Node $AllNodes.NodeName
{
# Adding the required service account to allow the cluster to log into SQL
SqlLogin 'AddNTServiceClusSvc'
{
Ensure = 'Present'
Name = 'NT SERVICE\ClusSvc'
LoginType = 'WindowsUser'
ServerName = $Node.NodeName
InstanceName = 'MSSQLSERVER'
PsDscRunAsCredential = $SqlAdministratorCredential
}
# Add the required permissions to the cluster service login
SqlPermission 'AddNTServiceClusSvcPermissions'
{
DependsOn = '[SqlLogin]AddNTServiceClusSvc'
Ensure = 'Present'
ServerName = $Node.NodeName
InstanceName = 'MSSQLSERVER'
Principal = 'NT SERVICE\ClusSvc'
Permission = 'AlterAnyAvailabilityGroup', 'ViewServerState'
PsDscRunAsCredential = $SqlAdministratorCredential
}
# Create a DatabaseMirroring endpoint
SqlEndpoint 'HADREndpoint'
{
EndPointName = 'HADR'
EndpointType = 'DatabaseMirroring'
Ensure = 'Present'
Port = 5022
ServerName = $Node.NodeName
InstanceName = 'MSSQLSERVER'
PsDscRunAsCredential = $SqlAdministratorCredential
}
SqlAlwaysOnService EnableHADR
{
Ensure = 'Present'
InstanceName = 'MSSQLSERVER'
ServerName = $Node.NodeName
PsDscRunAsCredential = $SqlAdministratorCredential
}
# Add the availability group replica to the availability group
SqlAGReplica 'AddReplica'
{
Ensure = 'Present'
Name = $Node.NodeName
AvailabilityGroupName = 'TestAG'
ServerName = $Node.NodeName
InstanceName = 'MSSQLSERVER'
PrimaryReplicaServerName = 'SQL1'
PrimaryReplicaInstanceName = 'MSSQLSERVER'
ProcessOnlyOnActiveNode = $true
DependsOn = '[SqlAlwaysOnService]EnableHADR'
PsDscRunAsCredential = $SqlAdministratorCredential
}
}
}
This example shows how to ensure that the Availability Group Replica 'SQL2' does not exist in the Availability Group 'TestAG'.
Configuration Example
{
param
(
[Parameter(Mandatory = $true)]
[System.Management.Automation.PSCredential]
$SqlAdministratorCredential
)
Import-DscResource -ModuleName 'SqlServerDsc'
Node $AllNodes.NodeName
{
# Add the availability group replica to the availability group
SqlAGReplica 'RemoveReplica'
{
Ensure = 'Absent'
Name = $Node.NodeName
AvailabilityGroupName = 'TestAG'
ServerName = $Node.NodeName
InstanceName = 'MSSQLSERVER'
PrimaryReplicaServerName = 'SQL1'
PrimaryReplicaInstanceName = 'MSSQLSERVER'
PsDscRunAsCredential = $SqlAdministratorCredential
}
}
}
- Add-SqlDscNode
- Add-SqlDscTraceFlag
- Complete-SqlDscFailoverCluster
- Complete-SqlDscImage
- Connect-SqlDscDatabaseEngine
- ConvertFrom-SqlDscDatabasePermission
- ConvertFrom-SqlDscServerPermission
- ConvertTo-SqlDscDatabasePermission
- ConvertTo-SqlDscServerPermission
- Disable-SqlDscAudit
- Disconnect-SqlDscDatabaseEngine
- Enable-SqlDscAudit
- Get-SqlDscAudit
- Get-SqlDscConfigurationOption
- Get-SqlDscDatabasePermission
- Get-SqlDscManagedComputer
- Get-SqlDscManagedComputerService
- Get-SqlDscPreferredModule
- Get-SqlDscServerPermission
- Get-SqlDscStartupParameter
- Get-SqlDscTraceFlag
- Import-SqlDscPreferredModule
- Initialize-SqlDscRebuildDatabase
- Install-SqlDscServer
- Invoke-SqlDscQuery
- New-SqlDscAudit
- Remove-SqlDscAudit
- Remove-SqlDscNode
- Remove-SqlDscTraceFlag
- Repair-SqlDscServer
- Save-SqlDscSqlServerMediaFile
- Set-SqlDscAudit
- Set-SqlDscDatabasePermission
- Set-SqlDscServerPermission
- Set-SqlDscStartupParameter
- Set-SqlDscTraceFlag
- Test-SqlDscIsDatabasePrincipal
- Test-SqlDscIsLogin
- Test-SqlDscIsSupportedFeature
- Uninstall-SqlDscServer
- SqlAG
- SqlAGDatabase
- SqlAgentAlert
- SqlAgentFailsafe
- SqlAgentOperator
- SqlAGListener
- SqlAGReplica
- SqlAlias
- SqlAlwaysOnService
- SqlAudit
- SqlConfiguration
- SqlDatabase
- SqlDatabaseDefaultLocation
- SqlDatabaseMail
- SqlDatabaseObjectPermission
- SqlDatabasePermission
- SqlDatabaseRole
- SqlDatabaseUser
- SqlEndpoint
- SqlEndpointPermission
- SqlLogin
- SqlMaxDop
- SqlMemory
- SqlPermission
- SqlProtocol
- SqlProtocolTcpIp
- SqlReplication
- SqlRole
- SqlRS
- SqlRSSetup
- SqlScript
- SqlScriptQuery
- SqlSecureConnection
- SqlServiceAccount
- SqlSetup
- SqlTraceFlag
- SqlWaitForAG
- SqlWindowsFirewall