http://www.mssqltips.com/sqlservertip/2464/configure-sql-server-database-mirroring-using-ssms/
Below are the two files in the file system:
Problem
I have a need to setup SQL Server Database Mirroring in my environment. I understand it can be complicated to setup. Can you provide an example on setting up SQL Server Database Mirroring? Check out this tip for a basic look at how to setup this SQL Server feature.
Solution
In this tip I am going to outline my environment and then walk through the process of setting up Database Mirroring. This will include the configurations, backups, restores and verification process. Let's jump in.
My test environment consists of two separate VM's running VM Workstation with Windows 2008 R2 Datacenter Edition and SQL Server 2008 R2 Enterprise named appropriately Principal and Mirror. The SQL Server and SQL Server Agent Services accounts are running as domain users (DOMAIN\User). Windows Firewall is OFF for the sake of this example.
I created a database on the Principal SQL Server instance and named it TestMirror. The recovery model is set to FULL RECOVERY.
1st step: Issue a full backup of the database.
Below are the two files in the file system:
3rd step: Assuming you have the backup folder shared on the Principal Server and you can access it from the Mirror Server, you will need to restore the full backup to the Mirror server with the NORECOVERY option.
Now it's time to dig down and configure Database Mirroring. From the Principal server, right click the database and choose "Tasks" | "Mirror" or choose "Properties" | "Mirroring".
Click the "Configure Security" button and click "Next >" if the Configure Database Mirroring Security Wizard intro screen appears. The next screen should be the Include Witness Server screen:
This is where you would configure a witness server for your mirroring, but since we're just configuring a basic mirror we will skip this part. However, if you are configuring mirroring in an Enterprise environment it is recommended you configure a witness server because without one you will not have synchronous automatic failover option.
Select "No", then click "Next >" to continue the process.
The next screen will give you options to configure the Principal Server Instance:
Here we will be creating our endpoint, which is a SQL Server object that allows SQL Server to communicate over the network. We will name it Mirroring with a Listener Port of 5022.
Click the "Next >" button to continue.
The next screen will give you options to configure the Mirror Server Instance:
To connect to the Mirror server instance we will need to click the "Connect..." button then select the mirror server and provide the correct credentials:
Once connected, we also notice our endpoint name is Mirroring and we are listening on port 5022.
Click "Next >" and you'll see the Service Accounts screen.
When using Windows Authentication, if the server instances use different accounts, specify the service accounts for SQL Server. These service accounts must all be domain accounts (in the same or trusted domains).
If all the server instances use the same domain account or use certificate-based authentication, leave the fields blank.
Since my service accounts are using the same domain account, I'll leave this blank.
Click "Finish" and you'll see a Complete the Wizard screen that summarizes what we just configured. Click "Finish" one more time.
If you see the big green check mark that means Database Mirroring has been configured correctly. However, just because it is configured correctly doesn't mean that database mirroring is going to start...
Next screen that pops up should be the Start/Do Not Start Mirroring screen:
We're going to click Do Not Start Mirroring just so we can look at the Operating Modes we can use:
Since we didn't specify a witness server we will not get the High Safety with automatic failover option, but we still get the High Performance and High Safety without automatic failover options.
For this example, we'll stick with synchronous high safety without automatic failover so changes on both servers will be synchronized.
Next, click "Start Mirroring" as shown below.
If everything turned out right, Database Mirroring has been started successfully and we are fully synchronized.
If Database mirroring did not start successfully or you received an error here are a few scripts to troubleshoot the situation:
Both servers should be listening on the same port. To verify this, run the following command:
We are listening on port 5022. This should be the same on the Principal and Mirror servers:
Database mirroring should be started on both servers. To verify this, run the following command:
The state_desc column on both the Principal and Mirror server should be started:
To start an Endpoint, run the following:
ROLES should be the same on both the Principal and Mirror Server, to verify this run:
To verify the login from the other server has CONNECT permissions run the following:
You can see here from the State and Permissions column that the user has been Granted Connect permissions.
Next Steps
- To learn more about the three different operating modes involved in database mirroring check out this previous tip
- Before implementing database mirroring make sure this is the high availability option you need for you company. Log shipping, replication, and clustering are also high availability options that may bring more benefit than mirroring depending on the needs.
- Check out all of the Database Mirroring tips.
No comments:
Post a Comment