logo
Mirror Database
GiacKhongDaiSu Offline
#1 Đã gửi : 09/05/2023 lúc 12:14:30(UTC)

Danh hiệu: Kê Vương

Gia nhập: 23-01-2011(UTC)
Bài viết: 2,113
Man
Đến từ: HCM

Thanks: 4 times
Được cảm ơn: 300 lần trong 220 bài viết
Script

USE MASTER;
GO
ALTER DATABASE DBTest SET PARTNER = 'TCP://192.168.1.29:5022'
GiacKhongDaiSu Offline
#2 Đã gửi : 09/05/2023 lúc 12:50:01(UTC)

Danh hiệu: Kê Vương

Gia nhập: 23-01-2011(UTC)
Bài viết: 2,113
Man
Đến từ: HCM

Thanks: 4 times
Được cảm ơn: 300 lần trong 220 bài viết
Prerequisite
The example uses the AdventureWorks sample database, which uses the simple recovery model by default. To use database mirroring with this database, you must alter it to use the full recovery model. To do this in Transact-SQL, use the ALTER DATABASE statement, as follows:
Mã:

USE master; 
GO 
ALTER DATABASE AdventureWorks   
SET RECOVERY FULL; 
GO 


For information on changing the recovery model in SQL Server Management Studio, see View or Change the Recovery Model of a Database (SQL Server).

Permissions
Requires ALTER permission on the database and CREATE ENDPOINT permission, or membership in the sysadmin fixed server role.

xample
In this example, the two partners and the witness are the default server instances on three computer systems. The three server instances run the same Windows domain, but the user account (used as the startup service account) is different for the example's witness server instance.

The following table summarizes the values used in this example.
itial mirroring role Host system Domain user account
Principal PARTNERHOST1 <Mydomain>\<dbousername>
Mirror PARTNERHOST5 <Mydomain>\<dbousername>
Witness WITNESSHOST4 <Somedomain>\<witnessuser>

1. Create an endpoint on the principal server instance (default instance on PARTNERHOST1).
Mã:

CREATE ENDPOINT Endpoint_Mirroring 
    STATE=STARTED   
    AS TCP (LISTENER_PORT=7022)   
    FOR DATABASE_MIRRORING (ROLE=PARTNER) 
GO 
--Partners under same domain user; login already exists in master. 
--Create a login for the witness server instance, 
--which is running as Somedomain\witnessuser: 
USE master ; 
GO 
CREATE LOGIN [Somedomain\witnessuser] FROM WINDOWS ; 
GO 
-- Grant connect permissions on endpoint to login account of witness. 
GRANT CONNECT ON ENDPOINT::Endpoint_Mirroring TO [Somedomain\witnessuser]; 
--Grant connect permissions on endpoint to login account of partners. 
GRANT CONNECT ON ENDPOINT::Endpoint_Mirroring TO [Mydomain\dbousername]; 
GO 


2. Create an endpoint on the mirror server instance (default instance on PARTNERHOST5).
Mã:

CREATE ENDPOINT Endpoint_Mirroring 
    STATE=STARTED   
    AS TCP (LISTENER_PORT=7022)   
    FOR DATABASE_MIRRORING (ROLE=ALL) 
GO 
--Partners under same domain user; login already exists in master. 
--Create a login for the witness server instance, 
--which is running as Somedomain\witnessuser: 
USE master ; 
GO 
CREATE LOGIN [Somedomain\witnessuser] FROM WINDOWS ; 
GO 
--Grant connect permissions on endpoint to login account of witness. 
GRANT CONNECT ON ENDPOINT::Endpoint_Mirroring TO [Somedomain\witnessuser]; 
--Grant connect permissions on endpoint to login account of partners. 
GRANT CONNECT ON ENDPOINT::Endpoint_Mirroring TO [Mydomain\dbousername]; 
GO 


3. Create an endpoint on the witness server instance (default instance on WITNESSHOST4).
Mã:

CREATE ENDPOINT Endpoint_Mirroring 
    STATE=STARTED   
    AS TCP (LISTENER_PORT=7022)   
    FOR DATABASE_MIRRORING (ROLE=WITNESS) 
GO 
--Create a login for the partner server instances, 
--which are both running as Mydomain\dbousername: 
USE master ; 
GO 
CREATE LOGIN [Mydomain\dbousername] FROM WINDOWS ; 
GO 
--Grant connect permissions on endpoint to login account of partners. 
GRANT CONNECT ON ENDPOINT::Endpoint_Mirroring TO [Mydomain\dbousername]; 
GO 


4. Create the mirror database. For more information, see Prepare a Mirror Database for Mirroring (SQL Server).

5. On the mirror server instance on PARTNERHOST5, set the server instance on PARTNERHOST1 as the partner (making it the initial principal server instance).
Mã:

ALTER DATABASE AdventureWorks   
    SET PARTNER =   
    'TCP://PARTNERHOST1.COM:7022' 
GO 


6. On the principal server instance on PARTNERHOST1, set the server instance on PARTNERHOST5 as the partner (making it the initial mirror server instance).
Mã:

ALTER DATABASE AdventureWorks   
    SET PARTNER = 'TCP://PARTNERHOST5.COM:7022' 
GO 


7. On the principal server, set the witness (which is on WITNESSHOST4)
Mã:

ALTER DATABASE AdventureWorks   
    SET WITNESS =   
    'TCP://WITNESSHOST4.COM:7022' 
GO 



GiacKhongDaiSu Offline
#3 Đã gửi : 25/02/2024 lúc 01:38:18(UTC)

Danh hiệu: Kê Vương

Gia nhập: 23-01-2011(UTC)
Bài viết: 2,113
Man
Đến từ: HCM

Thanks: 4 times
Được cảm ơn: 300 lần trong 220 bài viết
When starting the synchronization for database mirroring, you may get the above error, mirroring requires a full restore and at least one tlog restore, the error is dur to the mirror database has insufficient transaction log data
To start the synchronization successfully, you can do following steps:

Principal Instance - - Take a full backup and a log backup as well, Copy the full/log backups from Principal Instance to Mirror instance
Mirror Instance - - Restore with NORECOVERY option the full backup
Mirror Instance - - Apply the log backup
Principal Instance - - Start synchronization
Ai đang xem chủ đề này?
Guest (2)
Bạn không thể tạo chủ đề mới trong diễn đàn này.
Bạn không thể trả lời chủ đề trong diễn đàn này.
Bạn không thể xóa bài của bạn trong diễn đàn này.
Bạn không thể sửa bài của bạn trong diễn đàn này.
Bạn không thể tạo bình chọn trong diễn đàn này.
Bạn không thể bỏ phiếu bình chọn trong diễn đàn này.

Green-Grey Theme Created by Ingo Herbote (WatchersNET.de)
Powered by YAF | YAF © 2003-2010, Yet Another Forum.NET
Thời gian xử lý trang này hết 0.061 giây.