Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

SQL Server Error 1477: Fix Mirroring Safety Levels

· 6 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

SQL Server Error 1477 occurs when there is a mismatch between the mirroring safety level of the principal database and the mirror database, or when you attempt to change the safety level to a setting that is not supported by the current mirroring state. To resolve this, you must ensure both the principal and mirror databases are set to the same safety level—either synchronous (HIGH_SAFETY) or asynchronous (HIGH_PERFORMANCE_NO_DATA_LOSS)—using the ALTER DATABASE command on the principal server.

What You'll Need

  • Administrative access to both the Principal and Mirror SQL Server instances.
  • SQL Server Management Studio (SSMS) installed on a workstation with connectivity to both servers.
  • The exact names of the databases involved in the mirroring partnership.
  • Permission to execute ALTER DATABASE commands (sysadmin or db_owner roles).

Step-by-Step

  1. Identify the Current Safety Levels: Before applying changes, determine which server is the principal and which is the mirror. Open a new query window in SSMS and execute a query against the sys.database_mirroring system view. Check the mirroring_safety_level column. A value of 1 typically indicates high safety (synchronous), while 0 indicates high performance (asynchronous).
  2. Verify Network Connectivity: Since changing safety levels requires communication between the two instances, ensure that the mirroring endpoints are started and that there are no firewall blocks on the TCP ports used for mirroring. If the servers cannot communicate, the command to change the safety level will hang or time out.
  3. Connect to the Principal Server: All configuration changes for database mirroring must be initiated from the Principal instance. Connect to the Principal server using SSMS.
  4. Execute the Safety Level Change: Depending on your requirements for data loss and performance, run one of the following T-SQL commands. Note that labels and syntax may vary slightly depending on the version of SQL Server you are using, but the core command remains consistent.
    • For Synchronous Mode (High Safety): This ensures that a transaction is committed on the mirror before it is confirmed on the principal. Use: ALTER DATABASE [YourDatabaseName] SET PARTNER SAFETY LEVEL = SYNCHRONOUS;
    • For Asynchronous Mode (High Performance): This allows the principal to commit transactions without waiting for the mirror, which improves performance but risks minor data loss during a failover. Use: ALTER DATABASE [YourDatabaseName] SET PARTNER SAFETY LEVEL = ASYNCHRONOUS;
  5. Confirm the Change on the Principal: Re-run the query against sys.database_mirroring to ensure the mirroring_safety_level has updated to the desired value.
  6. Verify Synchronization on the Mirror: Connect to the Mirror server and check the database status. The database should transition from a 'Restoring' or 'Synchronizing' state to 'Synchronized' (if using synchronous mode).
  7. Test the Mirroring State: Use the Mirroring Monitor in SSMS by right-clicking the database on the principal server and selecting Tasks > Launch Database Mirroring Monitor. Confirm that the status shows as "Synchronized" or "Synchronizing" without any active error messages.

Common Mistakes

One of the most frequent mistakes is attempting to run the ALTER DATABASE command on the Mirror server. Database mirroring is a principal-driven architecture; the mirror is essentially a passive recipient of logs. Any attempt to change the safety level on the mirror instance will result in an error because the mirror database is in a non-operational (restoring) state.

Another common error is ignoring the impact of synchronous mirroring on application latency. When switching to SYNCHRONOUS mode, every write operation must be acknowledged by the mirror. If the network latency between the two servers is high, your application's write performance will drop significantly. Users often encounter Error 1477 when they try to force a safety level that the current network infrastructure cannot support effectively, leading to timeouts that look like configuration errors.

Finally, some administrators forget to check the status of the mirroring endpoints. If the endpoints are stopped or disabled, the principal cannot communicate the safety level change to the mirror. This leads to a state where the principal thinks the change is requested, but the mirror never receives the instruction, maintaining the mismatch that triggers Error 1477.

Tips

To avoid future occurrences of Error 1477, always document the intended safety level for each environment. Production environments typically require SYNCHRONOUS mode to guarantee zero data loss, while disaster recovery sites located in different geographical regions should use ASYNCHRONOUS mode to prevent network latency from slowing down the primary application.

When performing maintenance or migrating databases, it is often easier to set the safety level to ASYNCHRONOUS during the initial synchronization phase. Once the mirror is fully caught up and the initial bulk data transfer is complete, you can switch to SYNCHRONOUS mode for final production stability. This prevents the principal from hanging while trying to send massive amounts of initial log data synchronously.

Use the Database Mirroring Monitor frequently during the setup phase. The monitor provides a visual representation of the synchronization state and will alert you immediately if the safety levels are mismatched or if the session is disconnected.

Troubleshooting

If the ALTER DATABASE command fails or the error persists, start with the simplest check: restart the SQL Server Agent and the SQL Server service on both the principal and mirror instances. This clears any hung sessions that might be blocking the configuration change.

If the service restart does not work, check the SQL Server Error Logs on both servers. Look for messages related to "Database Mirroring" or "Endpoint." If you see messages indicating that the mirror cannot connect to the principal, verify that the service accounts used by the SQL Server instances have the necessary permissions to connect to the endpoints. You may need to grant CONNECT permissions to the service account on the endpoint: GRANT CONNECT ON ENDPOINT::[EndpointName] TO [ServiceAccount];

In cases where the mirroring partnership is completely stuck and Error 1477 prevents any changes, you may need to remove the mirroring partnership entirely and re-establish it. To do this, execute ALTER DATABASE [YourDatabaseName] SET PARTNER OFF; on the principal. This will break the link. You can then restore a fresh backup of the principal to the mirror server using WITH NORECOVERY and restart the mirroring process from scratch. Warning: Breaking the partnership will stop all data redundancy until the mirror is re-established.

Frequently Asked Questions

What is the difference between synchronous and asynchronous safety levels?

Synchronous safety (HIGH_SAFETY) ensures that transactions are committed on both the principal and mirror before the application receives a success message, guaranteeing no data loss. Asynchronous safety (HIGH_PERFORMANCE_NO_DATA_LOSS) commits transactions on the principal first and sends them to the mirror independently, which is faster but may result in small amounts of data loss during an unplanned failover.

Can I change the safety level without taking the database offline?

Yes, changing the mirroring safety level is an online operation. You do not need to take the database offline or disconnect users; however, you may notice a brief spike in latency or a momentary pause in transaction processing while the change is propagated to the mirror.

Why does Error 1477 happen during a failover?

This typically happens if a manual failover was attempted while the databases were in asynchronous mode. SQL Server requires the databases to be in synchronous mode to perform a failover with zero data loss. If they are asynchronous, you must perform a "forced service' failover, which acknowledges that some data loss may occur.

Does the safety level affect the backup process?

The safety level does not directly change how backups are taken on the principal. However, you can take backups on the mirror server regardless of the safety level, provided the mirror is in the correct state. This is often used to offload backup overhead from the principal server.

Will changing the safety level trigger a full re-synchronization?

No, changing the safety level from synchronous to asynchronous (or vice versa) does not trigger a full re-synchronization of the data. It only changes how the transaction log records are acknowledged between the two instances.

How do I check the mirroring status via T-SQL?

You can use the command SELECT mirroring_state_desc, mirroring_safety_level_desc FROM sys.database_mirroring WHERE database_id = DB_ID('YourDatabaseName'); to see the current state and safety level of your mirrored database.