게시 및 배포 해제

적용 대상:SQL ServerAzure SQL Managed Instance

이 항목에서는 SQL Server Management Studio, Transact-SQL 또는 RMO(복제 관리 개체)를 사용하여 SQL Server에서 게시 및 배포를 사용하지 않도록 설정하는 방법을 설명합니다.

다음을 수행할 수 있습니다.

  • 배포자의 모든 배포 데이터베이스를 삭제합니다.

  • 배포자를 사용하는 모든 게시자를 사용하지 않도록 설정하고 해당 게시자의 모든 게시를 삭제합니다.

  • 게시에 대한 구독을 모두 삭제합니다. 게시 및 구독 데이터베이스의 데이터는 삭제되지 않습니다. 그러나 게시 데이터베이스와의 동기화 관계는 손실됩니다. 구독자의 데이터는 수동으로만 삭제할 수 있습니다.

항목 내용

시작하기 전에

필수 조건

  • 게시 및 배포를 사용하지 않도록 설정하려면 모든 배포 및 게시 데이터베이스가 온라인이어야 합니다. 배포 또는 게시 데이터베이스에 대한 데이터베이스 스냅샷 있는 경우 게시 및 배포를 사용하지 않도록 설정하기 전에 삭제해야 합니다. 데이터베이스 스냅샷 데이터베이스의 읽기 전용 오프라인 복사본이며 복제본(replica)tion 스냅샷 관련이 없습니다. 자세한 내용은 데이터베이스 스냅샷(SQL Serve)을 참조하세요.

SQL Server Management Studio 사용

게시 및 배포 사용 안 함 마법사를 사용하여 게시 및 배포를 사용하지 않도록 설정합니다.

게시 및 배포를 사용하지 않도록 설정하려면

  1. Microsoft SQL Server Management Studio에서 사용하지 않도록 설정하려는 게시자 또는 배포자에 커넥트 서버 노드를 확장합니다.

  2. 복제 폴더를 마우스 오른쪽 단추로 클릭한 다음 게시 및 배포 사용 안 함을 클릭합니다.

  3. 게시 및 배포 사용 안 함 마법사의 단계를 완료합니다.

Transact-SQL 사용

복제본(replica)tion 저장 프로시저를 사용하여 프로그래밍 방식으로 게시 및 배포를 사용하지 않도록 설정할 수 있습니다.

게시 및 배포를 사용하지 않도록 설정하려면

  1. 모든 복제 관련 작업을 중지합니다. 작업 이름 목록은 복제 에이전트 보안 모델의 "SQL Server 에이전트 에이전트 보안" 섹션을 참조하세요.

  2. 구독 데이터베이스의 각 구독자에서 sp_removedb복제본(replica) 실행 하여 데이터베이스에서 복제본(replica)tion 개체를 제거합니다. 이 저장 프로시저는 배포자에서 복제본(replica) 작업을 제거하지 않습니다.

  3. 게시 데이터베이스의 게시자에서 sp_removedbreplication 을 실행하여 데이터베이스에서 복제 개체를 제거합니다.

  4. 게시자가 원격 배포자를 사용하는 경우 sp_dropdistributor를 실행합니다.

  5. 배포자에서 sp_dropdistpublisher를 실행합니다. 이 저장 프로시저는 배포자에 등록된 각 게시자에 대해 한 번 실행해야 합니다.

  6. 배포자에서 sp_dropdistributiondb 를 실행하여 배포 데이터베이스를 삭제합니다. 이 저장 프로시저는 배포자의 각 배포 데이터베이스에 대해 한 번 실행해야 합니다. 또한 배포 데이터베이스와 연결된 큐 판독기 에이전트 작업도 제거됩니다.

  7. 배포자에서 sp_dropdistributor 를 실행하여 서버에서 배포자 지정을 제거합니다.

    참고 항목

    sp_dropdistpublisher 실행하고 sp_dropdistributor 전에 모든 복제본(replica)tion 게시 및 배포 개체가 삭제되지 않으면 이러한 프로시저는 오류를 반환합니다. 게시자 또는 배포자를 삭제할 때 모든 복제본(replica)tion 관련 개체를 삭제하려면 매개 변수를 @no_checks 1설정해야 합니다. 게시자 또는 배포자가 오프라인이거나 연결할 수 없는 경우에는 @ignore_distributor 매개 변수를 1로 설정하여 삭제할 수 있습니다. 그러나 삭제되지 않고 남은 모든 게시 및 배포 개체는 수동으로 제거해야 합니다.

예제(Transact-SQL)

이 예제 스크립트는 구독 데이터베이스에서 복제본(replica)tion 개체를 제거합니다.

-- Remove replication objects from the subscription database on MYSUB.
DECLARE @subscriptionDB AS sysname
SET @subscriptionDB = N'AdventureWorks2022Replica'

-- Remove replication objects from a subscription database (if necessary).
USE master
EXEC sp_removedbreplication @subscriptionDB
GO

이 예제 스크립트는 게시자 및 배포자 서버에서 게시 및 배포를 사용하지 않도록 설정하고 배포 데이터베이스를 삭제합니다.

-- This script uses sqlcmd scripting variables. They are in the form
-- $(MyVariable). 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".

-- Disable publishing and distribution.
DECLARE @distributionDB AS sysname;
DECLARE @publisher AS sysname;
DECLARE @publicationDB as sysname;
SET @distributionDB = N'distribution';
SET @publisher = $(DistPubServer);
SET @publicationDB = N'AdventureWorks2022';

-- Disable the publication database.
USE [AdventureWorks2022]
EXEC sp_removedbreplication @publicationDB;

-- Remove the registration of the local Publisher at the Distributor.
USE master
EXEC sp_dropdistpublisher @publisher;

-- Delete the distribution database.
EXEC sp_dropdistributiondb @distributionDB;

-- Remove the local server as a Distributor.
EXEC sp_dropdistributor;
GO

RMO(복제 관리 개체) 사용

게시 및 배포를 사용하지 않도록 설정하려면

  1. 배포자를 사용하는 게시에 대한 모든 구독을 제거합니다. 자세한 내용은 끌어오기 구독 삭제 및 밀어넣기 구독 삭제를 참조하세요.

  2. 배포자를 사용하는 모든 게시를 제거하고 게시자와 배포자가 동일한 서버에 있는 경우 모든 데이터베이스에 대해 게시를 사용하지 않도록 설정합니다. 자세한 내용은 게시 삭제를 참조하세요.

  3. ServerConnection 클래스를 사용하여 배포자 연결을 만듭니다.

  4. DistributionPublisher 클래스의 인스턴스를 만듭니다. Name 속성을 지정하고 3단계에서 개체를 ServerConnection 전달합니다.

  5. (선택 사항) 메서드를 LoadProperties 호출하여 개체의 속성을 가져와 게시자가 있는지 확인합니다. 이 메서드가 false를 반환하는 경우 4단계에서 설정한 게시자 이름이 잘못되었거나 이 배포자가 게시자를 사용하지 않습니다.

  6. Remove 메서드를 호출합니다. 게시자와 배포자가 다른 서버에 있으며 게시자에 게시가 더 이상 존재하지 않는지 먼저 확인하지 않고 배포자에서 게시자를 제거해야 하는 경우 forcetrue 값을 전달합니다.

  7. ReplicationServer 클래스의 인스턴스를 만듭니다. 3단계에서 만든 ServerConnection 개체를 전달합니다.

  8. UninstallDistributor 메서드를 호출합니다. 먼저 모든 로컬 게시 데이터베이스를 사용하지 않도록 설정했고 배포 데이터베이스가 제거되었는지 확인하지 않고 배포자에서 모든 복제본(replica)tion 개체를 강제로 제거하려면 true값을 전달합니다.

예제(RMO)

다음은 배포자에서 게시자 등록을 제거하고 배포 데이터베이스를 삭제한 후 배포자를 제거하는 예제입니다.

// Set the Distributor and publication database names.
// Publisher and Distributor are on the same server instance.
string publisherName = publisherInstance;
string distributorName = publisherInstance;
string distributionDbName = "distribution";
string publicationDbName = "AdventureWorks2022";

// Create connections to the Publisher and Distributor
// using Windows Authentication.
ServerConnection publisherConn = new ServerConnection(publisherName);
ServerConnection distributorConn = new ServerConnection(distributorName);

// Create the objects we need.
ReplicationServer distributor =
    new ReplicationServer(distributorConn);
DistributionPublisher publisher;
DistributionDatabase distributionDb =
    new DistributionDatabase(distributionDbName, distributorConn);
ReplicationDatabase publicationDb;
publicationDb = new ReplicationDatabase(publicationDbName, publisherConn);

try
{
    // Connect to the Publisher and Distributor.
    publisherConn.Connect();
    distributorConn.Connect();

    // Disable all publishing on the AdventureWorks2022 database.
    if (publicationDb.LoadProperties())
    {
        if (publicationDb.EnabledMergePublishing)
        {
            publicationDb.EnabledMergePublishing = false;
        }
        else if (publicationDb.EnabledTransPublishing)
        {
            publicationDb.EnabledTransPublishing = false;
        }
    }
    else
    {
        throw new ApplicationException(
            String.Format("The {0} database does not exist.", publicationDbName));
    }

    // We cannot uninstall the Publisher if there are still Subscribers.
    if (distributor.RegisteredSubscribers.Count == 0)
    {
        // Uninstall the Publisher, if it exists.
        publisher = new DistributionPublisher(publisherName, distributorConn);
        if (publisher.LoadProperties())
        {
            publisher.Remove(false);
        }
        else
        {
            // Do something here if the Publisher does not exist.
            throw new ApplicationException(String.Format(
                "{0} is not a Publisher for {1}.", publisherName, distributorName));
        }

        // Drop the distribution database.
        if (distributionDb.LoadProperties())
        {
            distributionDb.Remove();
        }
        else
        {
            // Do something here if the distribition DB does not exist.
            throw new ApplicationException(String.Format(
                "The distribution database '{0}' does not exist on {1}.",
                distributionDbName, distributorName));
        }

        // Uninstall the Distributor, if it exists.
        if (distributor.LoadProperties())
        {
            // Passing a value of false means that the Publisher 
            // and distribution databases must already be uninstalled,
            // and that no local databases be enabled for publishing.
            distributor.UninstallDistributor(false);
        }
        else
        {
            //Do something here if the distributor does not exist.
            throw new ApplicationException(String.Format(
                "The Distributor '{0}' does not exist.", distributorName));
        }
    }
    else
    {
        throw new ApplicationException("You must first delete all subscriptions.");
    }
}
catch (Exception ex)
{
    // Implement appropriate error handling here.
    throw new ApplicationException("The Publisher and Distributor could not be uninstalled", ex);
}
finally
{
    publisherConn.Disconnect();
    distributorConn.Disconnect();
}
' Set the Distributor and publication database names.
' Publisher and Distributor are on the same server instance.
Dim publisherName As String = publisherInstance
Dim distributorName As String = subscriberInstance
Dim distributionDbName As String = "distribution"
Dim publicationDbName As String = "AdventureWorks2022"

' Create connections to the Publisher and Distributor
' using Windows Authentication.
Dim publisherConn As ServerConnection = New ServerConnection(publisherName)
Dim distributorConn As ServerConnection = New ServerConnection(distributorName)

' Create the objects we need.
Dim distributor As ReplicationServer
distributor = New ReplicationServer(distributorConn)
Dim publisher As DistributionPublisher
Dim distributionDb As DistributionDatabase
distributionDb = New DistributionDatabase(distributionDbName, distributorConn)
Dim publicationDb As ReplicationDatabase
publicationDb = New ReplicationDatabase(publicationDbName, publisherConn)

Try
    ' Connect to the Publisher and Distributor.
    publisherConn.Connect()
    distributorConn.Connect()

    ' Disable all publishing on the AdventureWorks2022 database.
    If publicationDb.LoadProperties() Then
        If publicationDb.EnabledMergePublishing Then
            publicationDb.EnabledMergePublishing = False
        ElseIf publicationDb.EnabledTransPublishing Then
            publicationDb.EnabledTransPublishing = False
        End If
    Else
        Throw New ApplicationException( _
            String.Format("The {0} database does not exist.", publicationDbName))
    End If

    ' We cannot uninstall the Publisher if there are still Subscribers.
    If distributor.RegisteredSubscribers.Count = 0 Then
        ' Uninstall the Publisher, if it exists.
        publisher = New DistributionPublisher(publisherName, distributorConn)
        If publisher.LoadProperties() Then
            publisher.Remove(False)
        Else
            ' Do something here if the Publisher does not exist.
            Throw New ApplicationException(String.Format( _
                "{0} is not a Publisher for {1}.", publisherName, distributorName))
        End If

        ' Drop the distribution database.
        If distributionDb.LoadProperties() Then
            distributionDb.Remove()
        Else
            ' Do something here if the distribition DB does not exist.
            Throw New ApplicationException(String.Format( _
             "The distribution database '{0}' does not exist on {1}.", _
             distributionDbName, distributorName))
        End If

        ' Uninstall the Distributor, if it exists.
        If distributor.LoadProperties() Then
            ' Passing a value of false means that the Publisher 
            ' and distribution databases must already be uninstalled,
            ' and that no local databases be enabled for publishing.
            distributor.UninstallDistributor(False)
        Else
            'Do something here if the distributor does not exist.
            Throw New ApplicationException(String.Format( _
                "The Distributor '{0}' does not exist.", distributorName))
        End If
    Else
        Throw New ApplicationException("You must first delete all subscriptions.")
    End If

Catch ex As Exception
    ' Implement appropriate error handling here.
    Throw New ApplicationException("The Publisher and Distributor could not be uninstalled", ex)

Finally
    publisherConn.Disconnect()
    distributorConn.Disconnect()

End Try

이 예제에서는 먼저 로컬 게시 데이터베이스를 사용하지 않도록 설정하거나 배포 데이터베이스를 삭제하지 않고 배포자를 제거합니다.

// Set the Distributor and publication database names.
// Publisher and Distributor are on the same server instance.
string distributorName = publisherInstance;

// Create connections to the Distributor
// using Windows Authentication.
ServerConnection conn = new ServerConnection(distributorName);
conn.DatabaseName = "master";

// Create the objects we need.
ReplicationServer distributor = new ReplicationServer(conn);

try
{
    // Connect to the Publisher and Distributor.
    conn.Connect();


    // Uninstall the Distributor, if it exists.
    // Use the force parameter to remove everthing.  
    if (distributor.IsDistributor && distributor.LoadProperties())
    {
        // Passing a value of true means that the Distributor 
        // is uninstalled even when publishing objects, subscriptions,
        // and distribution databases exist on the server.
        distributor.UninstallDistributor(true);
    }
    else
    {
        //Do something here if the distributor does not exist.
    }
}
catch (Exception ex)
{
    // Implement appropriate error handling here.
    throw new ApplicationException("The Publisher and Distributor could not be uninstalled", ex);
}
finally
{
    conn.Disconnect();
}
' Set the Distributor and publication database names.
' Publisher and Distributor are on the same server instance.
Dim distributorName As String = publisherInstance

' Create connections to the Distributor
' using Windows Authentication.
Dim conn As ServerConnection = New ServerConnection(distributorName)
conn.DatabaseName = "master"

' Create the objects we need.
Dim distributor As ReplicationServer = New ReplicationServer(conn)

Try
    ' Connect to the Publisher and Distributor.
    conn.Connect()


    ' Uninstall the Distributor, if it exists.
    ' Use the force parameter to remove everthing.  
    If distributor.IsDistributor And distributor.LoadProperties() Then
        ' Passing a value of true means that the Distributor 
        ' is uninstalled even when publishing objects, subscriptions,
        ' and distribution databases exist on the server.
        distributor.UninstallDistributor(True)
    Else
        'Do something here if the distributor does not exist.
    End If

Catch ex As Exception
    ' Implement appropriate error handling here.
    Throw New ApplicationException("The Publisher and Distributor could not be uninstalled", ex)

Finally
    conn.Disconnect()

End Try

참고 항목

Replication Management Objects Concepts
Replication System Stored Procedures Concepts