ディストリビューターとパブリッシャーのプロパティの表示および変更

適用対象: SQL ServerAzure SQL Managed Instance

このトピックでは、SQL Server Management Studio、Transact-SQL、またはレプリケーション管理オブジェクト (RMO) を使用して SQL Server のディストリビューターおよびパブリッシャーのプロパティを表示および変更する方法について説明します。

このトピックの内容

始める前に

推奨事項

  • Microsoft SQL Server 2005 (9.x) より前のバージョンを実行しているパブリッシャーでは、固定サーバー ロール sysadmin のユーザーが、[サブスクライバー] ページでサブスクライバーを登録できます。 SQL Server 2005 (9.x) 以降では、サブスクライバーをレプリケーションに明示的に登録する必要はありません。

セキュリティ

可能であれば、実行時、ユーザーに対してセキュリティ資格情報の入力を要求します。

SQL Server Management Studio を使用する

ディストリビューターのプロパティを表示および変更するには

  1. SQL Server Management Studio でディストリビューターに接続し、サーバー ノードを展開します。

  2. [レプリケーション] フォルダーを右クリックし、 [ディストリビューターのプロパティ]をクリックします。

  3. [ディストリビューターのプロパティ - <Distributor>] ダイアログ ボックスで、プロパティを表示および変更します。

    • ディストリビューション データベースのプロパティを表示および変更するには、ダイアログ ボックスの [全般] ページにあるデータベースのプロパティ ボタン ([...]) をクリックします。

    • ディストリビューターと関連付けられたパブリッシャーのプロパティを表示および変更するには、ダイアログ ボックスの[パブリッシャー]ページでパブリッシャーのプロパティ ボタン ( [...] ) をクリックします。

    • レプリケーション エージェントのプロファイルにアクセスするには、ダイアログ ボックスの [全般] ページの [プロファイルの既定値] をクリックします。 詳しくは、「 レプリケーション エージェント プロファイル」をご覧ください。

    • パブリッシャーで管理用のストアド プロシージャを実行したり、ディストリビューターで情報を更新したりするときに使用するアカウントのパスワードを変更するには、ダイアログ ボックスの [パブリッシャー] ページで [パスワード] ボックスおよび [パスワードの確認入力] ボックスに新しいパスワードを入力します。 詳細については、「ディストリビューターのセキュリティ保護」を参照してください。

  4. 必要に応じてプロパティを変更し、 [OK]をクリックします。

パブリッシャーのプロパティを表示および変更するには

  1. SQL Server Management Studio でパブリッシャーに接続し、サーバー ノードを展開します。

  2. [レプリケーション] フォルダーを右クリックし、 [パブリッシャーのプロパティ]をクリックします。

  3. [パブリッシャーのプロパティ - < Publisher >] ダイアログ ボックスで、プロパティを表示および変更します。

    • 固定サーバー ロール sysadmin のユーザーは、 [パブリケーション データベース] のページでデータベースのレプリケーションを有効化できます。 データベースを有効化しても、そのデータベースがパブリッシュされるわけではありません。固定データベース ロール db_owner の任意のユーザーが、1 つ以上のパブリケーションをデータベースに作成できるようになります。
  4. 必要に応じてプロパティを変更し、 [OK]をクリックします。

Transact-SQL の使用

パブリッシャーとディストリビューターのプロパティは、プログラムからレプリケーション ストアド プロシージャを使用して表示できます。

ディストリビューターとディストリビューション データベースのプロパティを表示するには

  1. sp_helpdistributor を実行すると、ディストリビューター、ディストリビューション データベース、作業ディレクトリに関する情報が返されます。

  2. sp_helpdistributiondb を実行すると、指定されたディストリビューション データベースのプロパティが返されます。

ディストリビューターとディストリビューション データベースのプロパティを変更するには

  1. ディストリビューターのプロパティを変更するには、ディストリビューターで sp_changedistributor_property を実行します。

  2. ディストリビューション データベースのプロパティを変更するには、ディストリビューターで sp_changedistributiondb を実行します。

  3. ディストリビューターのパスワードを変更するには、ディストリビューターで sp_changedistributor_password を実行します。

    重要

    可能であれば、実行時、ユーザーに対してセキュリティ資格情報の入力を要求します。 資格情報をスクリプト ファイルに含める必要がある場合は、不正なアクセスが行われないようにファイルをセキュリティで保護してください。

  4. ディストリビューターを使用しているパブリッシャーのプロパティを変更するには、ディストリビューターで sp_changedistpublisher を実行します。

例 (Transact-SQL)

次の Transact-SQL サンプルスクリプトは、ディストリビューターおよびディストリビューション データベースに関する情報を返します。

-- View information about the Distributor, distribution database, 
-- working directory, and SQL Server Agent user account. 
USE master
EXEC sp_helpdistributor;
GO
-- View information about the specified distribution database. 
USE distribution
EXEC sp_helpdistributiondb;
GO

次の例では、ディストリビューターの保有期間、ディストリビューターへの接続時に使用されるパスワード、およびディストリビューターが各種レプリケーション エージェントの状態を確認する間隔 (ハートビート間隔) を変更します。

重要

可能であれば、実行時、ユーザーに対してセキュリティ資格情報の入力を要求します。 資格情報をスクリプト ファイルに含める必要がある場合は、不正なアクセスが行われないようにファイルをセキュリティで保護してください。


-- Change the heartbeat interval at the Distributor to 5 minutes. 
USE master 
exec sp_changedistributor_property 
    @property = N'heartbeat_interval', 
    @value = 5;
GO
DECLARE @distributionDB AS sysname;
SET @distributionDB = N'distribution';

-- Change the history retention period to 24 hours and the
-- maximum retention period to 48 hours.  
USE distribution
EXEC sp_changedistributiondb @distributionDB, N'history_retention', 24
EXEC sp_changedistributiondb @distributionDB, N'max_distretention', 48
GO
-- Change the password on the Distributor. 
-- To avoid storing the password in the script file, the value is passed 
-- into SQLCMD as a scripting variable. For information about how to use 
-- scripting variables on the command line and in SQL Server Management
-- Studio, see the "Executing Replication Scripts" section in the topic
-- "Programming Replication Using System Stored Procedures".
USE master
EXEC sp_changedistributor_password $(Password)
GO

レプリケーション管理オブジェクト (RMO) の使用

ディストリビューターのプロパティを表示および変更するには

  1. ServerConnection クラスを使用して、ディストリビューターへの接続を作成します。

  2. ReplicationServer クラスのインスタンスを作成します。 手順 1 の ServerConnection オブジェクトを渡します。

  3. (省略可) IsDistributor プロパティをチェックして、現在接続されているサーバーがディストリビューターであることを確認します。

  4. Load メソッドを呼び出して、サーバーからプロパティを取得します。

  5. (省略可) プロパティを変更するには、 ReplicationServer オブジェクトの設定可能なディストリビューター プロパティに新しい値を設定します。

  6. (省略可) CachePropertyChanges オブジェクトの ReplicationServer プロパティが trueに設定されている場合は、 CommitPropertyChanges メソッドを呼び出して変更内容をサーバーにコミットします。

ディストリビューション データベースのプロパティを表示および変更するには

  1. ServerConnection クラスを使用して、ディストリビューターへの接続を作成します。

  2. DistributionDatabase クラスのインスタンスを作成します。 name プロパティを指定し、手順 1. の ServerConnection オブジェクトを渡します。

  3. LoadProperties メソッドを呼び出して、サーバーからプロパティを取得します。 このメソッドから falseが返された場合、指定した名前のデータベースはサーバー上に存在しません。

  4. (省略可) プロパティを変更するには、 DistributionDatabase の設定可能なプロパティに新しい値を設定します。

  5. (省略可) CachePropertyChanges オブジェクトの DistributionDatabase プロパティが trueに設定されている場合は、 CommitPropertyChanges メソッドを呼び出して変更内容をサーバーにコミットします。

パブリッシャーのプロパティを表示および変更するには

  1. ServerConnection クラスを使用して、パブリッシャーへの接続を作成します。

  2. DistributionPublisher クラスのインスタンスを作成します。 Name プロパティを指定し、手順 1. の ServerConnection オブジェクトを渡します。

  3. (省略可) プロパティを変更するには、 DistributionPublisher の設定可能なプロパティに新しい値を設定します。

  4. (省略可) CachePropertyChanges オブジェクトの DistributionPublisher プロパティが trueに設定されている場合は、 CommitPropertyChanges メソッドを呼び出して変更内容をサーバーにコミットします。

パブリッシャーからディストリビューターへの管理接続に使用されているパスワードを変更するには

  1. ServerConnection クラスを使用して、ディストリビューターへの接続を作成します。

  2. ReplicationServer クラスのインスタンスを作成します。

  3. ConnectionContext プロパティに、手順 1. の接続を設定します。

  4. Load メソッドを呼び出して、オブジェクトのプロパティを取得します。

  5. ChangeDistributorPassword メソッドを呼び出します。 新しいパスワード値を password パラメーターに渡します。

    重要

    可能であれば、実行時、ユーザーに対してセキュリティ資格情報の入力を要求します。 資格情報を保存する必要がある場合は、Microsoft Windows .NET Framework に用意されている 暗号化サービス を使用します。

  6. (省略可) このディストリビューターを使用している各リモート パブリッシャーでパスワードを変更するには、次の手順に従います。

    1. ServerConnection クラスを使用して、パブリッシャーへの接続を作成します。

    2. ReplicationServer クラスのインスタンスを作成します。

    3. ConnectionContext プロパティに、手順 6a. で作成した接続を設定します。

    4. Load メソッドを呼び出して、オブジェクトのプロパティを取得します。

    5. ChangeDistributorPassword メソッドを呼び出します。 手順 5. の新しいパスワード値を password パラメーターに渡します。

例 (RMO)

次の例に、ディストリビューションのプロパティおよびディストリビューション データベースのプロパティを変更する方法を示します。

重要

資格情報をコードに記述するのを避けるため、新しいディストリビューター パスワードは実行時に指定するようにしています。

// Set the Distributor and distribution database names.
string distributionDbName = "distribution";
string distributorName = publisherInstance;

ReplicationServer distributor;
DistributionDatabase distributionDb;

// Create a connection to the Distributor using Windows Authentication.
ServerConnection conn = new ServerConnection(distributorName);

try
{
    // Open the connection. 
    conn.Connect();

    distributor = new ReplicationServer(conn);

    // Load Distributor properties, if it is installed.
    if (distributor.LoadProperties())
    {
        // Password supplied at runtime.
        distributor.ChangeDistributorPassword(password);
        distributor.AgentCheckupInterval = 5;

        // Save changes to the Distributor properties.
        distributor.CommitPropertyChanges();
    }
    else
    {
        throw new ApplicationException(
            String.Format("{0} is not a Distributor.", publisherInstance));
    }

    // Create an object for the distribution database 
    // using the open Distributor connection.
    distributionDb = new DistributionDatabase(distributionDbName, conn);

    // Change distribution database properties.
    if (distributionDb.LoadProperties())
    {
        // Change maximum retention period to 48 hours and history retention 
        // period to 24 hours.
        distributionDb.MaxDistributionRetention = 48;
        distributionDb.HistoryRetention = 24;

        // Save changes to the distribution database properties.
        distributionDb.CommitPropertyChanges();
    }
    else
    {
        // Do something here if the distribution database does not exist.
    }
}
catch (Exception ex)
{
    // Implement the appropriate error handling here. 
    throw new ApplicationException("An error occurred when changing Distributor " +
        " or distribution database properties.", ex);
}
finally
{
    conn.Disconnect();
}
' Set the Distributor and distribution database names.
Dim distributionDbName As String = "distribution"
Dim distributorName As String = publisherInstance

Dim distributor As ReplicationServer
Dim distributionDb As DistributionDatabase

' Create a connection to the Distributor using Windows Authentication.
Dim conn As ServerConnection = New ServerConnection(distributorName)

Try
    ' Open the connection. 
    conn.Connect()

    distributor = New ReplicationServer(conn)

    ' Load Distributor properties, if it is installed.
    If distributor.LoadProperties() Then
        ' Password supplied at runtime.
        distributor.ChangeDistributorPassword(password)
        distributor.AgentCheckupInterval = 5

        ' Save changes to the Distributor properties.
        distributor.CommitPropertyChanges()
    Else
        Throw New ApplicationException( _
            String.Format("{0} is not a Distributor.", publisherInstance))
    End If

    ' Create an object for the distribution database 
    ' using the open Distributor connection.
    distributionDb = New DistributionDatabase(distributionDbName, conn)

    ' Change distribution database properties.
    If distributionDb.LoadProperties() Then
        ' Change maximum retention period to 48 hours and history retention 
        ' period to 24 hours.
        distributionDb.MaxDistributionRetention = 48
        distributionDb.HistoryRetention = 24

        ' Save changes to the distribution database properties.
        distributionDb.CommitPropertyChanges()
    Else
        ' Do something here if the distribution database does not exist.
    End If
Catch ex As Exception
    ' Implement the appropriate error handling here. 
    Throw New ApplicationException("An error occurred when changing Distributor " + _
        " or distribution database properties.", ex)
Finally
    conn.Disconnect()
End Try

参照

Replication Management Objects Concepts
パブリッシングおよびディストリビューションの無効化
[ディストリビューションの構成]
Replication Management Objects Concepts
ディストリビューターおよびパブリッシャーの情報スクリプト
Replication System Stored Procedures Concepts
パブリッシャーの情報を表示し、タスクを実行する (レプリケーション モニター)