セカンダリ データベースの Always On 可用性グループへの参加Join a secondary database to an Always On availability group
適用対象:Applies to: SQL ServerSQL Server (サポートされているすべてのバージョン)
SQL ServerSQL Server (all supported versions)
SQL ServerSQL Server (サポートされているすべてのバージョン)
SQL ServerSQL Server (all supported versions)
このトピックでは、 SQL Server Management StudioSQL Server Management Studioで、 Transact-SQLTransact-SQL、 SQL ServerSQL Server、または PowerShell を使用して、AlwaysOn 可用性グループにセカンダリ データベースを参加させる方法について説明します。This topic explains how to join a secondary database to an Always On availability group by using SQL Server Management StudioSQL Server Management Studio, Transact-SQLTransact-SQL, or PowerShell in SQL ServerSQL Server. セカンダリ レプリカのセカンダリ データベースを準備したら、できるだけ早くそのデータベースを可用性グループに参加させる必要があります。After you prepare a secondary database for a secondary replica, you need to join the database to the availability group as soon as possible. これによって、対応するプライマリ データベースからセカンダリ データベースへのデータの移動が開始されます。This will start data movement from the corresponding primary database to the secondary database.
注意
セカンダリ データベースをグループに参加させた後の動作については、「 Always On 可用性グループの概要 (SQL Server)、または PowerShell を使用して、AlwaysOn 可用性グループにセカンダリ データベースを参加させる方法について説明します。For information about what happens after a secondary database joins the group, see Overview of Always On Availability Groups (SQL Server).
前提条件Prerequisites
セカンダリ レプリカをホストするサーバー インスタンスに接続されている必要があります。You must be connected to the server instance that hosts the secondary replica.
セカンダリ レプリカがあらかじめ可用性グループに参加している必要があります。The secondary replica must already be joined to the availability group. 詳細については、「 可用性グループへのセカンダリ レプリカの参加 (SQL Server)、または PowerShell を使用して、既存の AlwaysOn 可用性グループにセカンダリ レプリカを追加する方法について説明します。For more information, see Join a Secondary Replica to an Availability Group (SQL Server).
セカンダリ データベースが最近準備されたものである必要があります。The secondary database must have been prepared recently. 詳細については、「 可用性グループに対するセカンダリ データベースの手動準備 (SQL Server)、または PowerShell を使用して、AlwaysOn 可用性グループにセカンダリ データベースを参加させる方法について説明します。For more information, see Manually Prepare a Secondary Database for an Availability Group (SQL Server).
PermissionsPermissions
可用性グループの ALTER AVAILABILITY GROUP 権限、CONTROL AVAILABILITY GROUP 権限、ALTER ANY AVAILABILITY GROUP 権限、または CONTROL SERVER 権限が必要です。Requires ALTER AVAILABILITY GROUP permission on the availability group, CONTROL AVAILABILITY GROUP permission, ALTER ANY AVAILABILITY GROUP permission, or CONTROL SERVER permission.
SQL Server Management Studio の使用Using SQL Server Management Studio
セカンダリ データベースを可用性グループに参加させるにはTo join a secondary database to an availability group
オブジェクト エクスプローラーで、セカンダリ レプリカをホストするサーバー インスタンスに接続し、サーバー ツリーを展開します。In Object Explorer, connect to the server instance that hosts the secondary replica, and expand the server tree.
[AlwaysOn 高可用性] ノードと [可用性グループ] ノードを展開します。Expand the Always On High Availability node and the Availability Groups node.
変更する可用性グループを展開し、 [可用性データベース] ノードを展開します。Expand the availability group that you want to change, and expand the Availability Databases node.
データベースを右クリックし、 [可用性グループへの参加] をクリックします。Right-click the database, and click Join to Availability Group.
これにより、 [可用性グループへのデータベースの参加] ダイアログ ボックスが開きます。This opens the Join Databases to Availability Group dialog box. タイトル バーに表示される可用性グループ名と、グリッドに表示されるデータベースの名前を確認し、 [OK] をクリックするか、 [キャンセル] をクリックします。Verify the availability group name, which is displayed on the title bar, and database name or names displayed in the grid, and click OK, or click Cancel.
Transact-SQL の使用Using Transact-SQL
セカンダリ データベースを可用性グループに参加させるにはTo join a secondary database to an availability group
セカンダリ レプリカをホストするサーバー インスタンスに接続します。Connect to the server instance that hosts the secondary replica.
ALTER DATABASE ステートメントの SET HADR 句 を使用します。次にその例を示します。Use the SET HADR clause of the ALTER DATABASE statement, as follows:
ALTER DATABASE database_name SET HADR AVAILABILITY GROUP = group_nameALTER DATABASE database_name SET HADR AVAILABILITY GROUP = group_name
ここで、 database_name は参加させるデータベースの名前で、 group_name は可用性グループの名前です。where database_name is the name of a database to be joined and group_name is the name of the availability group.
次の例では、セカンダリ データベース
Db1
を、MyAG
可用性グループのローカル セカンダリ レプリカに参加させます。The following example joins the secondary database,Db1
, to the local secondary replica of theMyAG
availability group.ALTER DATABASE Db1 SET HADR AVAILABILITY GROUP = MyAG;
注意
コンテキストで使用するこの Transact-SQLTransact-SQL ステートメントを確認するには、「可用性グループの作成 (Transact-SQL)」を参照してください。To see this Transact-SQLTransact-SQL statement used in context, see Create an Availability Group (Transact-SQL).
PowerShell の使用Using PowerShell
セカンダリ データベースを可用性グループに参加させるにはTo join a secondary database to an availability group
ディレクトリ変更コマンド (cd) を使用して、セカンダリ レプリカがホストされているサーバー インスタンスに移動します。Change directory (cd) to the server instance that hosts the secondary replica.
Add-SqlAvailabilityDatabase コマンドレットを使用して、セカンダリ データベース (複数可) を可用性グループに参加させます。Use the Add-SqlAvailabilityDatabase cmdlet to join one or more secondary databases to the availability group.
たとえば、次のコマンドでは、セカンダリ レプリカをホストするいずれかのサーバー インスタンスで可用性グループ
Db1
にセカンダリ データベースMyAG
を参加させます。For example, the following command joins a secondary database,Db1
, to the availability groupMyAG
on one of the server instances that hosts a secondary replica.Add-SqlAvailabilityDatabase ` -Path SQLSERVER:\SQL\SecondaryServer\InstanceName\AvailabilityGroups\MyAG ` -Database "Db1"
注意
コマンドレットの構文を表示するには、 PowerShell 環境で Get-Help SQL ServerSQL Server コマンドレットを使用します。To view the syntax of a cmdlet, use the Get-Help cmdlet in the SQL ServerSQL Server PowerShell environment. 詳細については、「 Get Help SQL Server PowerShell」を参照してください。For more information, see Get Help SQL Server PowerShell.
SQL Server PowerShell プロバイダーを設定して使用するにはTo set up and use the SQL Server PowerShell provider
関連タスクRelated Tasks
参照See Also
ALTER AVAILABILITY GROUP (Transact-SQL) ALTER AVAILABILITY GROUP (Transact-SQL)
AlwaysOn 可用性グループの概要 (SQL Server) Overview of Always On Availability Groups (SQL Server)
AlwaysOn 可用性グループの構成のトラブルシューティング (SQL Server)Troubleshoot Always On Availability Groups Configuration (SQL Server)