Witness Server Setup in Log Shipping: A Comprehensive Guide
Introduction
In SQL Server, Log Shipping is a high-availability and disaster recovery feature that automatically sends transaction log backups from a primary database to one or more secondary databases. While Log Shipping provides a robust solution for data redundancy, it lacks built-in support for automatic failover. To address this limitation, a Witness Server can be introduced to monitor the health of the primary and secondary servers, facilitating automatic failover in certain scenarios.(MSSQLTips)
Understanding Log Shipping and Witness Server
- Log Shipping: Involves three primary components:
- Primary Server: The source server where the original database resides.
- Secondary Server(s): One or more destination servers where transaction log backups are applied.
- Shared Folder: A network share accessible by both primary and secondary servers for storing transaction log backups.(axial-sql.com)
- Witness Server: An additional SQL Server instance that monitors the health of the primary and secondary servers. In case of a failure, the witness server can facilitate automatic failover to ensure continued database availability.(MSSQLTips)
Prerequisites for Configuring a Witness Server
Before setting up a Witness Server for Log Shipping, ensure the following:
- SQL Server Editions: All participating servers (primary, secondary, and witness) should be running compatible editions of SQL Server.
- Database Recovery Model: The primary database must be in Full or Bulk-Logged recovery model.
- Network Configuration: All servers should be on the same network and have proper connectivity.
- Shared Folder: A shared folder accessible by all servers for storing transaction log backups.
- SQL Server Agent: The SQL Server Agent service must be running on all servers.
- Permissions: Appropriate permissions should be set for SQL Server Agent accounts to access the shared folder and perform necessary operations.(MSSQLTips, SQL Solutions)
Step-by-Step Guide to Configuring a Witness Server in Log Shipping
Step 1: Prepare the Primary and Secondary Servers
- Primary Server:
- Ensure the database is in Full or Bulk-Logged recovery model.
- Create a full database backup and a transaction log backup.
- Restore the full backup and transaction log backup on the secondary server with the NORECOVERY option.(SQL Solutions)
- Secondary Server:
- Restore the backups from the primary server as mentioned above.
- Ensure the secondary database is in Standby or NORECOVERY mode.
Step 2: Configure Log Shipping
- On the Primary Server:
- Right-click on the database and select Properties.
- Navigate to the Transaction Log Shipping page.
- Check the option Enable this as a primary database in a log shipping configuration.
- Click on Backup Settings to configure the transaction log backup schedule and destination.
- Click on Add to configure the secondary server(s).(axial-sql.com, MSSQLTips, DZone)
- On the Secondary Server:
- In the Initialize Secondary Database tab, choose the appropriate option based on how you want to initialize the secondary database.
- In the Copy Files tab, specify the shared folder where transaction log backups will be copied.
- In the Restore Transaction Log tab, configure the restore schedule and options.(SQL Solutions, MSSQLTips)
Step 3: Set Up the Witness Server
- Install SQL Server:
- Install a compatible edition of SQL Server on the witness server machine.(axial-sql.com)
- Configure Endpoint:
- On the witness server, create a database mirroring endpoint using the following SQL command:(Microsoft Learn)
CREATE ENDPOINT Endpoint_Mirroring STATE = STARTED AS TCP (LISTENER_PORT = 7022) FOR DATABASE_MIRRORING (ROLE = WITNESS); GO
- On the witness server, create a database mirroring endpoint using the following SQL command:(Microsoft Learn)
- Configure Logins:
- On the witness server, create logins for the principal and mirror server instances.
- Grant connect permissions on the mirroring endpoint to these logins.(Microsoft Learn)
- Configure Service Accounts:
- Ensure that the SQL Server service accounts on all servers (primary, secondary, and witness) have appropriate permissions and are part of the same domain or trusted domains.
Step 4: Configure Automatic Failover
- On the Principal Server:
- Alter the database to set the witness:
ALTER DATABASE [YourDatabase] SET WITNESS = 'TCP://WitnessServerName:7022'; GO
- Alter the database to set the witness:
- On the Mirror Server:
- Alter the database to set the witness:(Microsoft Learn)
ALTER DATABASE [YourDatabase] SET WITNESS = 'TCP://WitnessServerName:7022'; GO
- Alter the database to set the witness:(Microsoft Learn)
Step 5: Verify Configuration
- Check Database Status:
- On the principal server, run the following command to check the database status:(axial-sql.com)
SELECT database_id, name, state_desc FROM sys.databases WHERE name = 'YourDatabase';
- On the principal server, run the following command to check the database status:(axial-sql.com)
- Check Mirroring Status:
- Run the following command to check the mirroring status:
SELECT database_id, database_name, mirroring_guid, role_desc, state_desc FROM sys.database_mirroring WHERE database_name = 'YourDatabase';
- Run the following command to check the mirroring status:
Step 6: Test Automatic Failover
- Simulate Failure:
- Stop the SQL Server service on the principal server to simulate a failure.(SQL Shack)
- Monitor Failover:
- Monitor the witness server and

Witness Server Setup in Log Shipping: A Comprehensive Guide
Introduction
SQL Server’s Log Shipping is a high-availability and disaster recovery feature that allows for the automatic transfer of transaction log backups from a primary database to one or more secondary databases. While Log Shipping provides data redundancy, it lacks built-in support for automatic failover. Introducing a Witness Server can address this limitation by monitoring the health of the primary and secondary servers, facilitating automatic failover in certain scenarios.
Understanding Log Shipping and Witness Server
- Log Shipping: Involves three primary components:
- Primary Server: The source server where the original database resides.
- Secondary Server(s): One or more destination servers where transaction log backups are applied.
- Shared Folder: A network share accessible by both primary and secondary servers for storing transaction log backups.
- Witness Server: An additional SQL Server instance that monitors the health of the primary and secondary servers. In case of a failure, the witness server can facilitate automatic failover to ensure continued database availability.
Prerequisites for Configuring a Witness Server
Before setting up a Witness Server for Log Shipping, ensure the following:
- SQL Server Editions: All participating servers (primary, secondary, and witness) should be running compatible editions of SQL Server.
- Database Recovery Model: The primary database must be in Full or Bulk-Logged recovery model.
- Network Configuration: All servers should be on the same network and have proper connectivity.
- Shared Folder: A shared folder accessible by all servers for storing transaction log backups.
- SQL Server Agent: The SQL Server Agent service must be running on all servers.
- Permissions: Appropriate permissions should be set for SQL Server Agent accounts to access the shared folder and perform necessary operations.
Step-by-Step Guide to Configuring a Witness Server in Log Shipping
Step 1: Prepare the Primary and Secondary Servers
- Primary Server:
- Ensure the database is in Full or Bulk-Logged recovery model.
- Create a full database backup and a transaction log backup.
- Restore the full backup and transaction log backup on the secondary server with the NORECOVERY option.
- Secondary Server:
- Restore the backups from the primary server as mentioned above.
- Ensure the secondary database is in Standby or NORECOVERY mode.
Step 2: Configure Log Shipping
- On the Primary Server:
- Right-click on the database and select Properties.
- Navigate to the Transaction Log Shipping page.
- Check the option Enable this as a primary database in a log shipping configuration.
- Click on Backup Settings to configure the transaction log backup schedule and destination.
- Click on Add to configure the secondary server(s).(Made Simple MSSQL)
- On the Secondary Server:
- In the Initialize Secondary Database tab, choose the appropriate option based on how you want to initialize the secondary database.
- In the Copy Files tab, specify the shared folder where transaction log backups will be copied.
- In the Restore Transaction Log tab, configure the restore schedule and options.
Step 3: Set Up the Witness Server
- Install SQL Server:
- Install a compatible edition of SQL Server on the witness server machine.
- Configure Endpoint:
- On the witness server, create a database mirroring endpoint using the following SQL command:
CREATE ENDPOINT Endpoint_Mirroring STATE = STARTED AS TCP (LISTENER_PORT = 7022) FOR DATABASE_MIRRORING (ROLE = WITNESS); GO
- On the witness server, create a database mirroring endpoint using the following SQL command:
- Configure Logins:
- On the witness server, create logins for the principal and mirror server instances.
- Grant connect permissions on the mirroring endpoint to these logins.
- Configure Service Accounts:
- Ensure that the SQL Server service accounts on all servers (primary, secondary, and witness) have appropriate permissions and are part of the same domain or trusted domains.
Step 4: Configure Automatic Failover
- On the Principal Server:
- Alter the database to set the witness:
ALTER DATABASE [YourDatabase] SET WITNESS = 'TCP://WitnessServerName:7022'; GO
- Alter the database to set the witness:
- On the Mirror Server:
- Alter the database to set the witness:(SQL Solutions)
ALTER DATABASE [YourDatabase] SET WITNESS = 'TCP://WitnessServerName:7022'; GO
- Alter the database to set the witness:(SQL Solutions)
Step 5: Verify Configuration
- Check Database Status:
- On the principal server, run the following command to check the database status:
SELECT database_id, name, state_desc FROM sys.databases WHERE name = 'YourDatabase';
- On the principal server, run the following command to check the database status:
- Check Mirroring Status:
- Run the following command to check the mirroring status:
SELECT database_id, database_name, mirroring_guid, role_desc, state_desc FROM sys.database_mirroring WHERE database_name = 'YourDatabase';
- Run the following command to check the mirroring status:
Step 6: Test Automatic Failover
- Simulate Failure:
- Stop the SQL Server service on the principal server to simulate a failure.
- Monitor Failover:
- Monitor the witness server and secondary server to ensure that the failover occurs as

Witness Server Setup in Log Shipping: A Comprehensive Guide
Introduction
SQL Server’s Log Shipping is a high-availability and disaster recovery feature that allows for the automatic transfer of transaction log backups from a primary database to one or more secondary databases. While Log Shipping provides data redundancy, it lacks built-in support for automatic failover. Introducing a Witness Server can address this limitation by monitoring the health of the primary and secondary servers, facilitating automatic failover in certain scenarios.
Understanding Log Shipping and Witness Server
- Log Shipping: Involves three primary components:
- Primary Server: The source server where the original database resides.
- Secondary Server(s): One or more destination servers where transaction log backups are applied.
- Shared Folder: A network share accessible by both primary and secondary servers for storing transaction log backups.
- Witness Server: An additional SQL Server instance that monitors the health of the primary and secondary servers. In case of a failure, the witness server can facilitate automatic failover to ensure continued database availability.
Prerequisites for Configuring a Witness Server
Before setting up a Witness Server for Log Shipping, ensure the following:
- SQL Server Editions: All participating servers (primary, secondary, and witness) should be running compatible editions of SQL Server.
- Database Recovery Model: The primary database must be in Full or Bulk-Logged recovery model.
- Network Configuration: All servers should be on the same network and have proper connectivity.
- Shared Folder: A shared folder accessible by all servers for storing transaction log backups.
- SQL Server Agent: The SQL Server Agent service must be running on all servers.
- Permissions: Appropriate permissions should be set for SQL Server Agent accounts to access the shared folder and perform necessary operations.
Step-by-Step Guide to Configuring a Witness Server in Log Shipping
Step 1: Prepare the Primary and Secondary Servers
- Primary Server:
- Ensure the database is in Full or Bulk-Logged recovery model.
- Create a full database backup and a transaction log backup.
- Restore the full backup and transaction log backup on the secondary server with the NORECOVERY option.
- Secondary Server:
- Restore the backups from the primary server as mentioned above.
- Ensure the secondary database is in Standby or NORECOVERY mode.
Step 2: Configure Log Shipping
- On the Primary Server:
- Right-click on the database and select Properties.
- Navigate to the Transaction Log Shipping page.
- Check the option Enable this as a primary database in a log shipping configuration.
- Click on Backup Settings to configure the transaction log backup schedule and destination.
- Click on Add to configure the secondary server(s).(Made Simple MSSQL)
- On the Secondary Server:
- In the Initialize Secondary Database tab, choose the appropriate option based on how you want to initialize the secondary database.
- In the Copy Files tab, specify the shared folder where transaction log backups will be copied.
- In the Restore Transaction Log tab, configure the restore schedule and options.
Step 3: Set Up the Witness Server
- Install SQL Server:
- Install a compatible edition of SQL Server on the witness server machine.
- Configure Endpoint:
- On the witness server, create a database mirroring endpoint using the following SQL command:
CREATE ENDPOINT Endpoint_Mirroring STATE = STARTED AS TCP (LISTENER_PORT = 7022) FOR DATABASE_MIRRORING (ROLE = WITNESS); GO
- On the witness server, create a database mirroring endpoint using the following SQL command:
- Configure Logins:
- On the witness server, create logins for the principal and mirror server instances.
- Grant connect permissions on the mirroring endpoint to these logins.
- Configure Service Accounts:
- Ensure that the SQL Server service accounts on all servers (primary, secondary, and witness) have appropriate permissions and are part of the same domain or trusted domains.
Step 4: Configure Automatic Failover
- On the Principal Server:
- Alter the database to set the witness:
ALTER DATABASE [YourDatabase] SET WITNESS = 'TCP://WitnessServerName:7022'; GO
- Alter the database to set the witness:
- On the Mirror Server:
- Alter the database to set the witness:(SQL Solutions)
ALTER DATABASE [YourDatabase] SET WITNESS = 'TCP://WitnessServerName:7022'; GO
- Alter the database to set the witness:(SQL Solutions)
Step 5: Verify Configuration
- Check Database Status:
- On the principal server, run the following command to check the database status:
SELECT database_id, name, state_desc FROM sys.databases WHERE name = 'YourDatabase';
- On the principal server, run the following command to check the database status:
- Check Mirroring Status:
- Run the following command to check the mirroring status:
SELECT database_id, database_name, mirroring_guid, role_desc, state_desc FROM sys.database_mirroring WHERE database_name = 'YourDatabase';
- Run the following command to check the mirroring status:
Step 6: Test Automatic Failover
- Simulate Failure:
- Stop the SQL Server service on the principal server to simulate a failure.
- Monitor Failover:
- Monitor the witness server and secondary server to ensure that the failover occurs as