共用方式為


New-SqlAvailabilityReplica

Creates an availability replica.

語法

ByPath (預設值)

New-SqlAvailabilityReplica
    [-Name] <String>
    [[-Path] <String>]
    -AvailabilityMode <AvailabilityReplicaAvailabilityMode>
    -FailoverMode <AvailabilityReplicaFailoverMode>
    -EndpointUrl <String>
    [-SessionTimeout <Int32>]
    [-ConnectionModeInPrimaryRole <AvailabilityReplicaConnectionModeInPrimaryRole>]
    [-ConnectionModeInSecondaryRole <AvailabilityReplicaConnectionModeInSecondaryRole>]
    [-BackupPriority <Int32>]
    [-ReadOnlyRoutingList <String[]>]
    [-ReadonlyRoutingConnectionUrl <String>]
    [-Script]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

AsTemplate

New-SqlAvailabilityReplica
    [-Name] <String>
    -AvailabilityMode <AvailabilityReplicaAvailabilityMode>
    -FailoverMode <AvailabilityReplicaFailoverMode>
    -EndpointUrl <String>
    [-SessionTimeout <Int32>]
    [-ConnectionModeInPrimaryRole <AvailabilityReplicaConnectionModeInPrimaryRole>]
    [-ConnectionModeInSecondaryRole <AvailabilityReplicaConnectionModeInSecondaryRole>]
    [-BackupPriority <Int32>]
    [-ReadOnlyRoutingList <String[]>]
    [-ReadonlyRoutingConnectionUrl <String>]
    [-AsTemplate]
    [-Version <ServerVersion>]
    [-Script]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

ByObject

New-SqlAvailabilityReplica
    [-Name] <String>
    [-InputObject] <AvailabilityGroup>
    -AvailabilityMode <AvailabilityReplicaAvailabilityMode>
    -FailoverMode <AvailabilityReplicaFailoverMode>
    -EndpointUrl <String>
    [-SessionTimeout <Int32>]
    [-ConnectionModeInPrimaryRole <AvailabilityReplicaConnectionModeInPrimaryRole>]
    [-ConnectionModeInSecondaryRole <AvailabilityReplicaConnectionModeInSecondaryRole>]
    [-BackupPriority <Int32>]
    [-ReadOnlyRoutingList <String[]>]
    [-ReadonlyRoutingConnectionUrl <String>]
    [-Script]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

Description

The New-SqlAvailabilityReplica cmdlet creates an availability replica. Run this cmdlet on the instance of SQL Server that hosts the primary replica.

To create an availability replica before you create an availability group, specify the AsTemplate parameter. To add a replica to an existing availability group, either the InputObject or Path parameter specifies the availability group.

範例

Example 1: Creates a representation of an availability replica

PS C:\> $ServerObject = Get-Item "SQLSERVER:\Sql\PrimaryServer\InstanceName"
PS C:\> New-SqlAvailabilityReplica -Name "PrimaryServer\Instance" -EndpointUrl "TCP://PrimaryServerName.domain.com:5022" -FailoverMode Automatic -AvailabilityMode SynchronousCommit -AsTemplate -Version $ServerObject.Version

This example creates an in-memory representation of an availability replica. No changes are committed to the server. You can use this replica as a value for the AvailabilityReplica parameter of New-SqlAvailabilityGroup

The first command gets an instance of the primary server.

The second command creates the availability replica. This replica uses the database mirroring endpoint located at the specified URL to communicate with other replicas in the availability group. This replica supports automatic failover and the synchronous-commit availability mode. The Version parameter specifies the version of the server instance that will host this new replica.

Example 2: Creates an availability replica that supports manual failover and the asynchronous-commit

PS C:\> $ServerObject = Get-Item "SQLSERVER:\Sql\PrimaryServer\InstanceName"
PS C:\> New-SqlAvailabilityReplica -Name "SecondaryServer\Instance" -EndpointUrl "TCP://PrimaryServerName.domain.com:5022" -FailoverMode Manual -AvailabilityMode AsynchronousCommit -AsTemplate -Version $ServerObject.Version

This example creates an in-memory representation of an availability replica. No changes are committed to the server.

The first command gets an instance of the primary server.

The second command creates the availability replica. This replica uses the database mirroring endpoint located at the specified URL to communicate with other replicas in the availability group. This replica supports manual failover and the asynchronous-commit availability mode. The Version parameter specifies the version of the server instance that will host this new replica.

Example 3: Add an availability replica to an availability group

PS C:\> New-SqlAvailabilityReplica -Name "SecondaryServer\Instance" -EndpointUrl "TCP://PrimaryServerName.domain.com:5022" -FailoverMode Manual -AvailabilityMode AsynchronousCommit -ConnectionModeInSecondaryRole AllowAllConnections -Path "SQLSERVER:\Sql\PrimaryServer\InstanceName\AvailabilityGroups\MainAG"

This command adds an availability replica to an existing availability group named MainAG. This replica supports manual failover and asynchronous-commit availability mode. In the secondary role, this replica supports read access connections. This configuration lets you offload read-only processing to this replica.

參數

-AsTemplate

Indicates that this cmdlet creates a temporary AvailabilityReplica object in memory. Specify this parameter to create an availability group before you create an availability replica. Create an availability group by using the New-SqlAvailabilityGroup cmdlet. Specify the temporary availability replica as the value of the AvailabilityReplica parameter.

If you specify AsTemplate, this cmdlet ignores values for the InputObject and Path parameters.

If you specify this parameter, you must also specify a SQL Server version for the Version parameter, or your current session must have an active connection to an instance.

參數屬性

類型:SwitchParameter
預設值:None
支援萬用字元:False
不要顯示:False

參數集

AsTemplate
Position:Named
必要:False
來自管線的值:False
來自管線按屬性名稱的值:False
來自剩餘引數的值:False

-AvailabilityMode

Specifies the replica availability mode. The acceptable values for this parameter are:

  • SynchronousCommit
  • AsynchronousCommit

You can specify a value of $Null.

參數屬性

類型:AvailabilityReplicaAvailabilityMode
預設值:None
支援萬用字元:False
不要顯示:False

參數集

(All)
Position:Named
必要:True
來自管線的值:False
來自管線按屬性名稱的值:False
來自剩餘引數的值:False

-BackupPriority

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.

參數屬性

類型:Int32
預設值: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

-ConnectionModeInPrimaryRole

Specifies how the availability replica handles connections when in the primary role. The acceptable values for this parameter are:

  • AllowReadWriteConnections. Allow read/write connections
  • AllowAllConnections. Allow all connections

參數屬性

類型:AvailabilityReplicaConnectionModeInPrimaryRole
預設值:None
支援萬用字元:False
不要顯示:False

參數集

(All)
Position:Named
必要:False
來自管線的值:False
來自管線按屬性名稱的值:False
來自剩餘引數的值:False

-ConnectionModeInSecondaryRole

Specifies how the availability replica handles connections when in the secondary role. The acceptable values for this parameter are:

  • AllowNoConnections. Disallows connections
  • AllowReadIntentConnectionsOnly. Allows only read-intent connections
  • AllowAllConnections. Allows all connections

參數屬性

類型:AvailabilityReplicaConnectionModeInSecondaryRole
預設值:None
支援萬用字元:False
不要顯示:False

參數集

(All)
Position:Named
必要:False
來自管線的值:False
來自管線按屬性名稱的值:False
來自剩餘引數的值:False

-EndpointUrl

Specifies the URL of the database mirroring endpoint. This URL is a TCP address in the following form:

TCP://system-address:port

參數屬性

類型:String
預設值:None
支援萬用字元:False
不要顯示:False

參數集

(All)
Position:Named
必要:True
來自管線的值:False
來自管線按屬性名稱的值:False
來自剩餘引數的值:False

-FailoverMode

Specifies the failover mode. The acceptable values for this parameter are:

  • Automatic
  • Manual You can specify a value of $Null.

參數屬性

類型:AvailabilityReplicaFailoverMode
預設值:None
支援萬用字元:False
不要顯示:False

參數集

(All)
Position:Named
必要:True
來自管線的值:False
來自管線按屬性名稱的值:False
來自剩餘引數的值:False

-InputObject

Specifies the availability group, as an AvailabilityGroup object, to which the replica belongs.

參數屬性

類型:AvailabilityGroup
預設值:None
支援萬用字元:False
不要顯示:False

參數集

ByObject
Position:3
必要:True
來自管線的值:True
來自管線按屬性名稱的值:False
來自剩餘引數的值:False

-Name

Specifies a name for the availability replica in the following format:

Computer\Instance

參數屬性

類型:String
預設值:None
支援萬用字元:False
不要顯示:False

參數集

(All)
Position:2
必要:True
來自管線的值:False
來自管線按屬性名稱的值:False
來自剩餘引數的值:False

-Path

Specifies the path of the availability group to which the replica belongs. If you do not specify this parameter, this cmdlet uses current working location.

參數屬性

類型:String
預設值:None
支援萬用字元:False
不要顯示:False

參數集

ByPath
Position:3
必要:False
來自管線的值:False
來自管線按屬性名稱的值:False
來自剩餘引數的值:False

-ReadonlyRoutingConnectionUrl

Specifies the fully-qualified domain name (FQDN) and port to use when routing to the replica for read only connections, as in the following example:

TCP://DBSERVER8.manufacturing.Contoso.com:7024

參數屬性

類型:String
預設值:None
支援萬用字元:False
不要顯示:False

參數集

(All)
Position:Named
必要:False
來自管線的值:False
來自管線按屬性名稱的值:False
來自剩餘引數的值:False

-ReadOnlyRoutingList

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.

參數屬性

類型:

String[]

預設值:None
支援萬用字元:False
不要顯示:False

參數集

(All)
Position:Named
必要: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

-SessionTimeout

Specifies the amount of time, in seconds, to wait for a response between the primary replica and this replica before the connection fails.

參數屬性

類型:Int32
預設值:None
支援萬用字元:False
不要顯示:False

參數集

(All)
Position:Named
必要:False
來自管線的值:False
來自管線按屬性名稱的值:False
來自剩餘引數的值:False

-Version

Specifies a SQL Server version. If you specify the AsTemplate parameter, you must specify a version. The template object is created in design mode on a server that includes this version. You can specify an integer or a string, as in the following examples:

  • 13
  • "13.0.0"

參數屬性

類型:ServerVersion
預設值:None
支援萬用字元:False
不要顯示:False

參數集

AsTemplate
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.

輸出

Microsoft.SqlServer.Management.Smo.AvailabilityReplica

This cmdlet returns an availability replica.