HOW TO CHECK YOUR SQL SERVER MIRROING IS RUNNING OR NOT ?


HOW TO CHECK YOUR MIRROING IS RUNNING OR NOT ?

you can Check :

1-  port number listener : open CMD and write this Command  ” netstat -an ” you will see the 3 port for the 3 Servers Principle – mirroring – Witness also I see the 3 port because I setup the 3 SQL Server Instance in the same  Windows Server

Check port

2-  Event Viewer for Windows Server

Event Viewr

3-  SQL Server Database Log

SQl Server Log

4-  Check Endpoint Status

Check Endpoint

 

What is the Stander listener port in Database Mirroring Configuration?


If you Create the 3 SQL Servers in the same PC

Begin

you must use difference port

Principle Server use the Stander port number 5021

Mirroring Server use the Stander port number 5022

Witness Server use the Stander port number 5023

End

Else The 3 SQL in 3 different PC

You can use one port like 5021

Don’t Forget to Disable Firewall or must be open this ports on the Firewall

Mirroring SQL Server Part 3


in this part we will learn how to make resume and pasue to the mirroring session how to check the status to your database mirroring then how to make remove to the Mirroring Session

Suspend\Resume Database Mirroring Session

  • Why we need to Pass [suspend] database mirroring session ?
  1. For rolling upgrade [if I want to upgrade my mirroring server must be pass mirroring then upgrade then resume it again]
  2. Fix problem hardware or software problem
  3. Automatic page repair
  4. Forced Services [you can use it when the principle server down and the mirroring server is online you will >>>Connect to the mirror server >>>>Issue the following statement >>>>>ALTER DATABASE <database_name> SET PARTNER FORCE_SERVICE_ALLOW_DATA_LOSS where <database_name> is the mirrored database. >>>> The mirror server immediately transitions to principal server, and mirroring is suspended. >>>> then you will go to fix the problem in principle server and when it return to work you will make resume to the mirroring server ]

How you can make suspend \Resume Mirroring session?

Go to Principle Server [Elmasry-PC\Principle]

1-    Check your Mirroring mode [Right Click on Mirrorin_DB >>>> Tasks >>>> Mirror >>>> you will see the mode is high performance mode because the last example make in this mode ]

2-    Now pause the mirroring DB the SQL will ask you Are you want to pass mirroring of this database? Answer YES

Paused mirroring Session

3-    Now Check the status to your database

4-    Now Right click on Mirroring_DB >>>> Tasks >>>> Launch Database mirroring monitor  you will see the database is suspended in the principle server and the mirroring server and you can check this by the time from the history this toll is very good to make check your mirroring session from time to another time

5- Now I will make some transaction on my database Mirroring_Db in principle server to the unsent log 
CREATE TABLE test_unsent_after_suspend
(ID INT , NAME NVARCHAR(50))
GO
DECLARE @id INT
SET @id = 1
 WHILE @id < 1000
 BEGIN
 INSERT INTO test_unsent_after_suspend VALUES(@id , ‘Mostafa Elmasry SQL DBA’)
 SET @id = @id +1
 END
 6- Let’s go to check the unsent log from the mirroring monitor

unsent Log

 7- i will go now to return the priciple server to work by make resume to the Mirroring_DB [same stsps like pause]

 

Remove Mirroring Session

1-      In principle server  right click on Mirrorin_DB >>> tasks >>> mirror >>> Remove Mirror

2-      Delete Endpoint from 3 Servers [principle-Mirroring-Witness] >>>Serrver objects >>>Endpoints>>>Database Mirroring >>>>Select your Endpoint .

3-      Refresh the Mirroring server you will see the Mirroring_Db status is restoring if you want to open it and use it you can make it by this Code

Wait me My friend in the Mirroring Part 4 (How to Create mirroring by Code)

Good Luck

Mirroring in SQL Server Part 2


Mirroring Setup Step by Step

  • Let’s start to setup mirroring server in SQL server 2008 R2 in the first I setup SQL Server 2008R2 and 3 instance in SQL Server 2008

1- Principle instance (Elmasry-PC\Principle)

2- Mirroring instance (Elmasry-PC\Mirroring)

3- Witness Instance (Elmasry-PC\Principle)

  • In my example I will make mirroring type high availability (Synchronize mode)
  • In principle server I will create database Mirroring_DB
  • Take full backup Mirroring_DB.bak
  • then take log Transaction backup Mirroring_DB.trn
  • Make restore to this backup full mirroring server with No recovery option
  • Then right click on Mirroring_DB >>Tasks>>Restore>>Transaction Log
  • Then Select your transaction log backup (Mirroring_DB.trn )
  • Don’t forget restore with no recovery option

 

High Availability Mode [Automatic Failover]

Principle Server

  • Right click on database Mirroring_Db >> tasks >> Mirror >> Configure Security
  • You will ask if you want to setup witness server or not? select yes.
  • Then you will ask to select your principle server [connect to Elmasry-PC\Principle] and make the port is 5021 and the endpoint name is Principle then Click next
  • You will ask again to select your Mirroring server [connect to Elmasry-PC\Mirroring] and make the port is 5022 and the endpoint name is mirroring then click next.
  • You will ask again to select your witness server [connect to Elmasry-PC] and make the port is 5023 and the endpoint name is Witness then click next .
  • In this step he will ask you to put your user name in your windows and this user must be add in the SQL Server so I write my username is [my pc name\windows username] [Elmasry-PC\Elmasry] .then click finish
  • SQL server after you click finish it will make configuration to the Principle Server , Mirroring Server , Witness Server
  • After this configuration is finish SQL server will give you massage if you want to Start mirroring or not select start and Waite few mints then mirroring will start and you see the status is [Synchronized: the databases are fully synchronized]

  • Now go to make refresh to the servers [principle – mirroring]

Principle Server [Elmasry-PC\Principle]

1- Create Table Name Employee

CREATE TABLE Employee
(Emp_Id INT NOT NULL PRIMARY KEY IDENTITY,
Emp_Name NVARCHAR(50) NOT NULL,
Tel NVARCHAR(12) NULL)

2- Insert data in this table

INSERT INTO dbo.Employee
( Emp_Name, Tel )
VALUES ( N’Mostafa’, — Emp_Name – nvarchar(50)
N’0172788327′ — Tel – nvarchar(12)
) , (‘Mohamed’ , ‘015876565645’)

3- Now if you select data from Employee Table you will see 2 rows

4- Right click on the principle server and make stop to the server

Mirroring Server [Elmasry-PC\Mirroring]

1- Refresh the server (you will see the database change from mirroring to principle database and if you open the database you will see the Employee table and the 2 rows

2- Now try to insert in this table another 2 rows

INSERT INTO dbo.Employee
( Emp_Name, Tel )
VALUES ( N’Omar’, — Emp_Name – nvarchar(50)
N’0172788327′ — Tel – nvarchar(12)
) , (‘Kemo’ , ‘015876565645’)

3- Stop the server and start the principle server [Elmasry-PC\Principle] you will see the database is mirroring make stop to the Mirroring server [Elmasry-PC\Mirroring] you will see the difference the mirroring database in the principle server will change to Principle sever and if you open the Employee table you will see 4 rows not 2 because the 2 rows you insert into database in mirroring server transfer automatically to another server

Mnaual Failover

Before I start to explain Mirroring High Safety mode I will explain something is very good that’s is manual Failover Yes you can make manual failover in the previous Example I make Failover (meaning change the server principle will be the mirroring and the mirroring will be the principle) I make this operation but Automatically when I make stop to the server and this operation make  Automatically because I make mirroring [High Availability] but in the manual failover you can make the same operation by your hand :

1-    Go to principle server then right click and select tasks >>>>> Mirror

2-    Then Click on Failover you will see the massage Click yes

3-    Then make refresh to the server you will see the change 

See Mirroring Part 3 https://mostafaelmasry.wordpress.com/2011/12/25/mirroring-sql-server-part-3/

Good Luck

Mirroring in SQL Server 2008 Part 1


Introduction to mirroring

  • Database mirroring is ( log shipping + replication ) – some of issues in log shipping and replication.
  • In database mirroring section you have 3 servers (principle, mirroring, and witness).
  • The database will be in the principle server and the application will be connect to the principle server then you will take backup (Full + log) from the database in the principle server the make restore to this backup with no recovery option in the mirroring. server so the record will copy from the principle server to the mirror server.
  • Witness server will be monitoring to the principle and the mirroring server.
  • You can setup the principle server in domain and the mirroring server in another domain

What happens if the principle server down in high availability mode?

if the principle server down the mirroring server will be the new principle server and the application will be connect automatically to the new principle server (mirroring server)

What happened when the application connect to the database in the principle server?

When the Application connect to the principle server and users make any transaction on this database the record will write in log puffer memory in principle server then write it in log file in database then the log puffer send the record to the log puffer memory to the mirroring server then the log puffer write this record in log file in database. Then the mirror server send to the principle server massage to know the principle the transaction is succeed then the principle tell the application the transaction is succeed.

Operation modes

You can setup the mirroring server in 3 modes

  1. High availability.

In high availability you need 3 servers (principle server, mirroring server, witness server) so in this operation mode the application connect on the principle server then the transaction write in log file then the principle server send the record to the mirror server in log file the mirror send to the principle (the record is commit) then the principle send to the application the transaction is committed

  1. High safety.

In high safety mode we don’t need to the witness server we will need in this section to the principle server and the mirror server only so there’s no automatic failover in high safety mode. And the operation will be same in the high availability mode [application connect on the principle server then the transaction write in log file then the principle server send the record to the mirror server in log file the mirror send to the principle (the record is commit) then the principle send to the application the transaction is committed ]

Remarks: the difference between high availability mode and high safety mode is Automatic failover in high availability will found Automatic failover but in high safety will not found Automatic failover. So if the principle server down you have problem because you will make manually start the mirroring server to be principle server. Not like in high availability mode this operation make automatically because this operation mode have automatic failover.

  1. High performance.

In high performance mode you need 2 server (principle server , mirror server) like high safety mode . So the difference between the high performance mode and high safety mode is in high performance the application send the transaction to the principle server in log file then the principle send the record to the mirror server and send to the application the transaction is committed so the principle server don’t wait the mirror server like (high safety mode and high availability mode)

 

Operation mode

servers

Automatic failover

Principle wait the mirror

High availability

3 servers

Yes

Yes

High safety

2 servers

No

Yes

High performance

2 servers

No

No

 In the finale I explain what is mirroring? , what is the operation mode in mirroring? , what is the difference between operation mode in mirroring? , remember I tell you high safety and high performance not need witness server but you can create witness server in this operation mode but it will make problems whit you so don’t make witness server in high safety mode and high performance mode .

Mirroring requirements:

1-    The database and file location should be same.

2-    Collection and master code page should be same in the principle and mirror server.

3-    Database name should be same in the principle and mirror server.

4-     You cannot mirror more the 10 databases in 32 bit servers you can in 64 bit server but not recommended.

5-     You cannot use attach/de attach you can use backup and restore.

6-     Ports in mirroring should be opening in firewall or close the firewall.

7-     Services account In SQL and SQL agent should be same in all servers.

8-     The mirroring not support the cross database transaction & distributed transaction log

9-     SQL server number should be same but you can setup principle server on SQL Server 2008 service pack 1 and the mirror on SQL Server services pack two

Advantages of database mirroring  :

1-     Does not require special hardware (such as shared storage, heart-beat connection) and cluster ware, thus potentially has lower infrastructure cost

2-     Database mirroring supports full-text catalogs

3-     Hardware and software upgrade that’s very easy.

Remark: If you want upgrade the mirror server from SQL server 2008 R2 to denial you must pass the mirroring in this section then after upgrade start the mirroring again

4-     Increases the data protection (disaster recovery).

5-     Increases the database availability if you use the Sync mode.

6-     Cost of database mirroring is less than clustering.

7-     It’s robust and efficient than log shipping and replication.

8-     Failover is fast compare to cluster

9-     Mirror server can be used to host databases for other applications not like clustering.

Disadvantage of database mirroring:

1-     Mirroring doesn’t support file stream.

2-     Mirror server is not available for database read only.

3-     Mirror server working in database level not in server level not like clustering (in clustering failover  you make this in server level on all database in this server in logins in jobs like this)

Mirroring enhancement in SQL Server 2008 from 2005:

Reference: [http://www.sqlserver-training.com/database-mirroring-enhancements-in-sql-server-2008-from-2005/-]

1)   Database mirroring automatic page repair.

  • If a page on the principle or mirror server is corrupt, it is automatically replaced with the corresponding copy on its partner
  • Some page types cannot be automatically repaired:
    • File header pages
    • Database boot page
    • Allocation pages

2)   Compressed Data flow

  •  Data Flow between the principle and mirror server is now compressed to improve performance.

 3)   Manual Failover

  • Manual failover no longer require a database restart

4)   Log performance

  • log-send buffers
  • Page read-ahead
  • Write-ahead on the incoming log stream on the mirror server

Part 2 >>>https://mostafaelmasry.wordpress.com/2011/12/22/mirroring-in-sql-server-part-2/