Wednesday, November 30, 2011

SQL Server Fix: Database Mirroring Principal Disconnected In Recovery

Issue: In SQL Server Mirroring (Principal Disconnected / In Recovery). 

For example "MSSQLFIX_A" is the Principal, "MSSQLFIX_B" is the Mirror and "MSSQLFIX_C" is the Witness you have 3 levels of redundancy. 

1.  If suppose MSSQLFIX_B fails, the quorum is between MSSQLFIX_A & MSSQLFIX_C 
2.  If MSSQLFIX_C fails, the quorum is between MSSQLFIX_A and MSSQLFIX_B. 
3.  If both MSSQLFIX_B & MSSQLFIX_C fail, this leaves MSSQLFIX_A in a (Principal Disconnected / In Recovery) state. 

Resolution: If the quorum is lost between the three servers/computers then this problem will occur. You can recover the database by using any one of the option from the below two. 

Option:1 
The quickest way to recover from this is to run the following script on MSSQLFIX_A. 

USE Master
GO
RESTORE DATABASE [DatabaseName] SET PARTNER OFF
GO 

This will remove mirroring but will recover your database. 

Option:2
Step 1.   Log into the primary database server 

Step 2.   Right-Click on the database that is listed as (Principal, Disconnected / In Recovery) and select Properties.

Step 3.   Click on the "Mirroring" page and then click the "Failover" button. 

Step 4.   The database will now be listed as (Mirror, Synchronized / Restoring) and will be accessible from the other SQL Server.



step by step tutorial. step by step guide. Step by Step Installation. Step-by-step procedure. Database Mirroring step by step. Step by Step Guide to. sql server step by step. sql server step by step ebook. microsoft sql server step by step ebook. sql server step by step tutorial. step by step installation guide. microsoft sql server 2008 step by step. Prerequisites. Restrictions. and Recommendations for Database Mirroring. Prerequisites and Recommendations for Database Mirroring. SQL Server Database Mirroring Pre-requisites and guidelines. Prerequisites for Database Mirroring. Database Mirroring in SQL Server 2008. Prerequisites: Configuring database mirroring or database. Introduction to Database Mirroring. Setting Up Database Mirroring. Database Mirroring Witness. Database Mirroring Sessions. Configure availability by using SQL Server database mirroring. Setting Up Database Mirroring. Database Mirroring Best Practices and Performance Considerations. Things to consider when setting up database mirroring in SQL Server 2012. Database Mirroring and Other Features and Components. Database Mirroring Components In SQL Server 2012. Database Mirroring Components In SQL Server 2008 R2.

Prerequisites for Log Shipping In SQL Server

About Log-Shipping:
Log shipping is a form of high availability that continuously restores transaction log backups created on a primary (source) server to a standby (target) server. It involves two copies of a single database that typically reside on different computers/servers. At any given time, only one copy of the database is currently available to clients. This copy is known as the primary database and the other copy of the database is known as the secondary database. 

Here are the prerequisites for configuring Log Shipping in SQL Server 2008.

SQL Server Edition:  SQL Server 2008 Enterprise Edition, or SQL Server 2008 Work-group Edition, or SQL Server 2005 Standard Edition must be installed on all server instances involved in log shipping.

Case Sensitivity: The servers involved in log shipping should have the same case sensitivity settings.

Network Configuration: Enable Remote connection protocol TCP/IP and Named Pipes or else you can enable only TCP/IP protocol by using Configuration manager from start menu.




Login: The SQL Services in both the primary and secondary server should be the same with same password preferably a domain account.

Recovery Mode: Log shipping must be setup at the database level. The log Shipped database should be in Full Recovery or Bulk logged recovery model,  so that T-logs can be applied, else you cannot configure log shipping.  If you want to provide high availability for multiple databases on a single instance of SQL Server, you must setup log-shipping separately for each database.

Use the below command to change the recovery model or else you can change in the SSMS by right clicking the DB properties.

Use Master
GO
Alter Database [DatabaseName] Set Recovery 'Recovery Model Name'



Shared Folder: Shared folder should be created in Primary server to hold the tran log backups.

SQL Server Agent: SQL Server Agent service must be running on both source and destination servers. Log shipping is implemented as a collection of jobs like backup, copy, and restore. If SQL Server Agent service isn’t running, none of the jobs will execute.

Permission: You must be a sysadmin on each server instance to enable log shipping. The backup and restore directories in your log shipping configuration must Read/Write permission required for SQL Service account of Primary and Secondary servers so that transaction log backup, Copy and restore to be successful.


Prerequisites for Log Shipping. Log Shipping Deployment. Log Shipping Requirements . Log Shipping 'skipping' all logs and not restoring. An Overview of Log Shipping in SQL Server 2005. An Overview of Log Shipping in SQL Server 2008 r2. An Overview of Log Shipping in SQL Server 2012. sql server 2000 log shipping multiple servers. prerequisites for replication. SQL Server Log Shipping to a Different Domain or Workgroup. Ship's Log Requirements. Prerequisites for Migrating from Log Shipping to AlwaysOn, step by step tutorial. step by step guide. Step by Step Installation. Step-by-step procedure. log shipping step by step. Step by Step Guide to. sql server step by step. sql server step by step ebook. microsoft sql server step by step ebook. sql server step by step tutorial. step by step installation guide. microsoft sql server 2008 step by step

Monday, November 28, 2011

Maximum Capacity Specifications for SQL Server

Here is the list of must know maximum sizes in SQL Server 2005.

I have tried my best to include most of the important things to know the maximum size in SQL Server 2005 and if I have missed any please leave a comment and I will be very glad to include them here.


Maximum Capacity Specifications for SQL Server. Max size varchar(max) in SQL Server 2000. Maximum size for a SQL Server Query. Maximum size for a SQL Server table. Maximum size for a SQL Server object. Maximum size for a SQL Server data. Find Max Length of column value. Find Maximum Length of String. Maximum size for "ntext" type in sql server. Maximum Allowable Length of Characters for. SQL Server ignoring maximum file size on transaction log. maximum database size of sql server 2012. maximum database size of sql server 2008. maximum database size of sql server 2005. SQL SERVER 2000 MAX SIZE LIMIT. Maximum Capacity Specifications for SQL Server

Saturday, November 26, 2011

Most Important Queries To Remember For Database Mirroring Administration

In this post I covered only most important scripts for mirroring administration. In my future posts I will cover some major issues of Mirroring and its resolutions/workarounds/fixes. 

How to manually fail over a database mirroring session?
1.       Connect to the principal server.
2.       Set the database context to the master database.
3.       ALTER DATABASE <database_name> SET PARTNER FAILOVER

How to Force Service in a Database Mirroring Session?
1.       Connect to the mirror server.
2.       Issue the following statement.
3.      
ALTER DATABASE <database_name> SET PARTNER FORCE_SERVICE_ALLOW_DATA_LOSS  

How to Resume a Database Mirroring Session?
1.       Connect to either partner.
2.       Issue the following T-SQL statement.
3.      
ALTER DATABASE <database_name> SET PARTNER RESUME 


How to pause a database mirroring session?
1.       Connect to either partner.
2.       Issue the following T-SQL statement.
3.      
ALTER DATABASE <database_name> SET PARTNER SUSPEND 


How to turn ON transaction safety?
1.       Connect to the principal server.
2.       Issue the following T-SQL statement.
3.      
ALTER DATABASE <database_name> SET PARTNER SAFETY FULL

How to turn OFF transaction safety?
1.       Connect to the principal server.
2.       Issue the following statement.
3.      
ALTER DATABASE <database_name> SET PARTNER SAFETY OFF
 
How to remove Database Mirroring?
1.       Connect to either partner.
2.       Issue the following T-SQL statement.
3.       ALTER DATABASE <database_name> SET PARTNER OFF


How to Remove the Witness from a Database Mirroring Session?
1.       Connect to either partner.
2.       Issue the following statement.
3.       ALTER DATABASE <database_name> SET WITNESS OFF



sql server, databases, Remove the Witness from a Database Mirroring, how to remove Database Mirroring in sql server, how to remove mirroring in sql server, mssqlfix.com, how to turn OFF transaction safety in mirroring, How to Force Service in a Database Mirroring Session, manual fail over in mirroring, automate fail over in mirroring, Setting Up Database Mirroring Using Certificates with examples. Use Certificates for a Database Mirroring Endpoint . Configure a Database Mirroring Session. Setting up database mirroring with certificates. Certificate Expiration on Database Mirroring and Recreating. How to replace expired certificates used in database mirroring. Implementing Database Mirroring in SQL Server 2008 R2. Implementing Database Mirroring in SQL Server 2012. Run SQL Server 2008 database mirroring with certificates. How to Allow Database Mirroring to Use Certificates for Inbound. How to Remove Database Mirroring. Sample script for configuring SQL Server database mirroring. Database Mirroring Setup Overview. step by step tutorial. step by step guide. Step by Step Installation. Step-by-step procedure. Database Mirroring step by step. Step by Step Guide to. sql server step by step. sql server step by step ebook. microsoft sql server step by step ebook. sql server step by step tutorial. step by step installation guide. microsoft sql server 2008 step by step

Wednesday, November 23, 2011

Setting Up Database Mirroring Using Certificates

You have to follow these 4 steps for each partner (Principal, Mirror, and Witness) for configuring database mirroring through using Certificates.
1.    First you need to create a database Master Key, in the master database.
2.    In the master database, create an encrypted certificate on the SQL Server Instance.
3.    Then you have to create an endpoint for the SQL server instance using its certificate.
4.    Back up the certificate and securely copy the backup file it to the other systems.

You must complete these above 4 steps for each partner and the witness, if there is a witness server.  

Step1. Run below script for creating encryption key, certificate and end-points on Principal Server.....

 1.1   On the master database, create the database master key, if needed through below script.
 
                USE MASTER
                GO
                CREATE MASTER KEY ENCRYPTION BY PASSWORD = 'Password'
                GO

1.2   Make a certificate for this Principal server.

                USE MASTER
                GO
                CREATE CERTIFICATE Principal_Cert
                      WITH SUBJECT = 'Principal Certificate';
                GO

1.3   Create a mirroring endpoint for server instance using the certificate.

                 CREATE ENDPOINT End_Mirroring
                    STATE = STARTED
                    AS TCP (LISTENER_PORT = 5022, LISTENER_IP = ALL)
                    FOR DATABASE_MIRRORING
                    (
                        AUTHENTICATION = CERTIFICATE Principal_Cert,
                        ENCRYPTION = REQUIRED ALGORITHM RC4,
                        ROLE = ALL
                    )
                GO

1.4   Back up the certificate and copy it to the Mirror Server, in order to configure inbound connections on the other servers.

                USE MASTER 
                GO 
                BACKUP CERTIFICATE Principal_Cert     
                TO FILE = 'C:\Certificate\Principal_Cert.cer' 
                GO


Step 2. Run below script for creating encryption key, certificate and end-points on Mirror Server.....

2.1   On the master database, create the database master key, if needed through below script.

                USE MASTER
                GO
                CREATE MASTER KEY ENCRYPTION BY PASSWORD = 'Password'
                GO

2.2   Make a certificate for this Mirror server.  

                USE MASTER 
                GO 
                CREATE CERTIFICATE Mirror_Cert 
                WITH SUBJECT = 'Mirror Certificate';
                GO

2.3   Create a mirroring endpoint for server instance using the certificate. 

                CREATE ENDPOINT End_Mirroring 
                STATE = STARTED 
                AS TCP (LISTENER_PORT = 5023, LISTENER_IP = ALL) 
                FOR DATABASE_MIRRORING 
                ( 
                AUTHENTICATION = CERTIFICATE Mirror_Cert, 
                ENCRYPTION = REQUIRED ALGORITHM RC4, 
                ROLE = ALL 
                ) 
                GO

2.4   Back up the certificate and copy it to the Principal Server, in order to configure inbound connections on the other servers.

                USE MASTER 
                GO 
                BACKUP CERTIFICATE Mirror_Cert 
                    TO FILE = 'C:\Certificate\Mirror_Cert.cer' 
                GO

Step 3. Run below script for creating encryption key, certificate and end-points on Witness Server..... 

3.1   On the master database, create the database master key, if needed through below script.

                USE MASTER
                GO
                CREATE MASTER KEY ENCRYPTION BY PASSWORD = 'Password' 
                GO

3.2   Make a certificate for this Witness server.  

                USE MASTER
                GO
                CREATE CERTIFICATE Witness_Cert
                    WITH SUBJECT = 'Witness Certificate';
                GO

3.3   Create a mirroring endpoint for server instance using the certificate. 

                CREATE ENDPOINT End_Mirroring 
                    STATE = STARTED 
                    AS TCP (LISTENER_PORT = 5023, LISTENER_IP = ALL) 
                    FOR DATABASE_MIRRORING 
                    ( 
                        AUTHENTICATION = CERTIFICATE Witness_Cert, 
                        ENCRYPTION = REQUIRED ALGORITHM RC4, 
                        ROLE = ALL 
                    ) 
                GO

3.4   Back up the certificate and copy it to the Principal and Mirror Server, in order to configure inbound connections on the other servers.

                USE MASTER
                GO 
                BACKUP CERTIFICATE Witness_Cert 
                    TO FILE = 'C:\Certificate\Witness_Cert.cer' 
                GO

Step 4. Run below script in Principal Instance for creating login, user and associate certificate with user on Principal Server. 

Now copy the Mirror_Cert.cer and Witness_Cert.cer on to the Principal Instance.

4.1   We are creating a SQL Login here, for Windows logins, use the Grant Login instead of Create Login...

                USE MASTER
                GO
                CREATE LOGIN Mirror_login WITH PASSWORD = 'Password'
                GO

                USE MASTER
                GO
                CREATE LOGIN Witness_login WITH PASSWORD = 'Password'
                GO

4.2   Create a user for that login.

                USE MASTER
                GO
                CREATE USER Mirror_User FOR LOGIN Mirror_login
                GO

                USE MASTER
                GO
                CREATE USER Witness_User FOR LOGIN Witness_login
                GO

4.3   Associate the certificate with the user.
                USE MASTER
                GO
                CREATE CERTIFICATE Mirror_Cert
                    AUTHORIZATION Mirror_User
                    FROM FILE = 'C:\Certificate\Mirror_Cert.cer'
                GO

                USE MASTER
                GO
                CREATE CERTIFICATE Witness_Cert
                    AUTHORIZATION Witness_User
                    FROM FILE = 'C:\Certificate\Witness_Cert.cer'
                GO

4.4   Grant CONNECT permission on the login for the remote mirroring endpoint.

                USE MASTER
                GO
                GRANT CONNECT ON ENDPOINT::End_Mirroring TO [Mirror_login] 
                GO

                USE MASTER
                GO
                GRANT CONNECT ON ENDPOINT::End_Mirroring TO [Witness_login] 
                GO

Step 5. Run below script in Mirror Instance for create login, user and associate certificate with user.

Now copy the Principal_Cert.cer and Witness_Cert.cer on to the Mirror Instance.

5.1   We are creating a SQL Login here. For Windows logins, use the Grant Login instead of Create Login...

                USE MASTER
                GO
                CREATE LOGIN Principal_login WITH PASSWORD = 'Password'
                GO

                USE MASTER 
                GO
                CREATE LOGIN Witness_login WITH PASSWORD = 'Password'
                GO

5.2   Create a user for that login.

                USE MASTER 
                GO
                CREATE USER Principal_User FOR LOGIN Principal_login
                GO

                USE MASTER 
                GO
                CREATE USER Witness_User FOR LOGIN Witness_login
                GO

5.3   Associate the certificate with the user.

                USE MASTER 
                GO
                CREATE CERTIFICATE Principal_Cert
                    AUTHORIZATION Principal_User
                    FROM FILE = 'C:\Certificate\Principal_Cert.cer'
                GO

                USE MASTER 
                GO
                CREATE CERTIFICATE Witness_Cert
                    AUTHORIZATION Witness_User
                    FROM FILE = 'C:\Certificate\Witness_Cert.cer'
                GO

5.4   Grant CONNECT permission on the login for the remote mirroring endpoint.

                USE MASTER 
                GO
                GRANT CONNECT ON ENDPOINT::End_Mirroring TO [Principal_login]
                GO

                USE MASTER 
                GO
                GRANT CONNECT ON ENDPOINT::End_Mirroring TO [Witness_login]
                GO

Step 6. Run below script in Witness Instance for create login, user and associate certificate with user.

Now copy the Principal_Cert.cer and Mirror_Cert.cer on to the Witness Instance.

6.1   We are creating a SQL Login here. For Windows logins, use the Grant Login instead of Create Login...

                USE MASTER 
                GO
                CREATE LOGIN Principal_login WITH PASSWORD = 'Password'
                GO

                USE MASTER 
                GO
                CREATE LOGIN Mirror_login WITH PASSWORD = 'Password'
                GO

6.2   Create a user for that login.

                USE MASTER 
                GO
                CREATE USER Principal_User FOR LOGIN Witness_login
                GO

                USE MASTER 
                GO
                CREATE USER Mirror_User FOR LOGIN Witness_login
                GO

6.3   Associate the certificate with the user.

                USE MASTER 
                GO
                CREATE CERTIFICATE Principal_Cert
                    AUTHORIZATION Principal_User
                    FROM FILE = 'C:\Certificate\Principal_Cert.cer'
                GO

                USE MASTER 
                GO
                CREATE CERTIFICATE Mirror_Cert
                    AUTHORIZATION Mirror_User
                    FROM FILE = 'C:\Certificate\Mirror_Cert.cer'
                GO

6.4   Grant CONNECT permission on the login for the remote mirroring endpoint.

                USE MASTER 
                GO
                GRANT CONNECT ON ENDPOINT::End_Mirroring TO [Principal_login]
                GO

                USE MASTER 
                GO
                GRANT CONNECT ON ENDPOINT::End_Mirroring TO [Mirror_login]
                GO

Step 7. Create the Mirrored Database on the Mirror Server using backups from the Principal Server.

7.1   Run below script against the Principal Instance

                USE MASTER
                GO
                BACKUP DATABASE AdventureWorks
                    TO DISK = 'C:\Backups\AdventureWorks_Full_01012011.bak'
                GO
                BACKUP LOG AdventureWorks
                    TO DISK = 'C:\Backups\AdventureWorks_Log_01012011.trn'
                GO

7.2   Copy AdventureWorks_Full_01012011.bak and AdventureWorks_Log_01012011.trn to the Mirror Server.

7.3   Execute this below script against the Mirror Instance.

                USE MASTER 
                GO
                RESTORE DATABASE AdventureWorks
                    FROM DISK = 'D:\Backups\AdventureWorks_FullBackup.bak'
                    WITH NORECOVERY
                GO
                RESTORE LOG AdventureWorks
                    FROM DISK = 'D:\Backups\AdventureWorks_LogBackup.trn'
                    WITH NORECOVERY
                GO

Step 8. Configuring the Mirroring Partners 

8.1   Change the server name as per yours and run the below script on Mirror server.

                ALTER DATABASE AdventureWorks
                    SET PARTNER = 'TCP://your_principal_server_name:5022'
                GO


8.2   Change the server name as per yours and run the below script on principal server
                ALTER DATABASE AdventureWorks 
                   SET PARTNER = 'TCP://your mirror server name:5023' 
                GO 
                
                ALTER DATABASE AdventureWorks 
                   SET WITNESS = 'TCP://your witness server name:5024' 
                GO

NOTE: When you copying a certificate to another system or server, use a secure copy method. Be extremely careful to keep all of your certificates secure and safe.

Setting Up Database Mirroring Using Certificates with examples. Use Certificates for a Database Mirroring Endpoint . Configure a Database Mirroring Session. Setting up database mirroring with certificates. Certificate Expiration on Database Mirroring and Recreating. How to replace expired certificates used in database mirroring. Implementing Database Mirroring in SQL Server 2008 R2. Implementing Database Mirroring in SQL Server 2012. Run SQL Server 2008 database mirroring with certificates. How to Allow Database Mirroring to Use Certificates for Inbound. How to Remove Database Mirroring. Sample script for configuring SQL Server database mirroring. Database Mirroring Setup Overview. step by step tutorial. step by step guide. Step by Step Installation. Step-by-step procedure. Database Mirroring step by step. Step by Step Guide to. sql server step by step. sql server step by step ebook. microsoft sql server step by step ebook. sql server step by step tutorial. step by step installation guide. microsoft sql server 2008 step by step