Smart Systems for Home

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

SQL Server Error 1426: Fix ALTER DATABASE SET WITNESS

· 5 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 1426 occurs when you try to run ALTER DATABASE ... SET WITNESS without first setting the database to FULL recovery model and taking a full backup. The fix is to switch the database to FULL recovery, back it up, then issue the witness command. This guide walks you through that sequence step by step, explains why the error appears, and covers what to do if the command still fails.

What You'll Need

  • SQL Server Management Studio (SSMS) or another client that can run T-SQL, such as Azure Data Studio.
  • An account with ALTER DATABASE permission on the target database, or membership in the db_owner role or sysadmin role.
  • A database mirroring endpoint already configured on the principal, mirror, and witness server instances.
  • The network address of the witness server (for example, TCP://witnessserver:5022).
  • Sufficient disk space for a full database backup.

Step-by-Step

  1. Confirm the database is in FULL recovery model. Run SELECT name, recovery_model_desc FROM sys.databases WHERE name = 'YourDatabase';. If the result is SIMPLE or BULK_LOGGED, error 1426 is expected. You must change it to FULL before proceeding.
  2. Switch to FULL recovery model. Execute ALTER DATABASE YourDatabase SET RECOVERY FULL;. This change takes effect immediately and does not require a restart.
  3. Take a full database backup. Run BACKUP DATABASE YourDatabase TO DISK = 'C:\Backups\YourDatabase_Full.bak' WITH INIT;. The witness command requires that a full backup exists after the recovery model change. Without it, the ALTER DATABASE statement will still fail.
  4. Verify the mirroring endpoint is running. On each server instance, check SELECT name, state_desc FROM sys.database_mirroring_endpoints;. The state should be STARTED. If it is STOPPED, start it with ALTER ENDPOINT Mirroring STATE = STARTED;.
  5. Set the witness. Connect to the principal server instance and run ALTER DATABASE YourDatabase SET WITNESS = 'TCP://witnessserver:5022';. Replace the address with the actual witness endpoint. If the witness is on the same machine as the mirror, use the mirror's address instead.
  6. Confirm the witness is configured. Query SELECT database_id, mirroring_witness_name, mirroring_witness_state_desc FROM sys.database_mirroring WHERE database_id = DB_ID('YourDatabase');. The witness state should show CONNECTED.
  7. Test failover (optional but recommended). If the witness is connected, you can manually fail over to the mirror to confirm the configuration works. Use ALTER DATABASE YourDatabase SET PARTNER FAILOVER; from the mirror server.

Common Mistakes

  • Skipping the full backup. Many people change the recovery model but forget the backup. The witness command requires both.
  • Using the wrong endpoint address. The witness address must be reachable from both principal and mirror. A typo or wrong port will cause a connection error, not error 1426, but it will still block setup.
  • Running the command on the wrong instance. The SET WITNESS command must be executed on the principal server, not the mirror or witness.
  • Assuming SIMPLE recovery is fine. Database mirroring requires FULL recovery model. If you switch back to SIMPLE later, mirroring will stop.
  • Ignoring firewall rules. The mirroring endpoint port (default 5022) must be open between all three servers.

Tips

  • Always script the recovery model change and backup together so you do not forget the backup step.
  • Use the same collation and compatibility level on all three instances to avoid subtle issues.
  • If you are setting up mirroring for the first time, configure the endpoints and partners before adding the witness.
  • Keep a log of the exact commands you run; it helps when troubleshooting.
  • Test the witness connection using telnet witnessserver 5022 from both principal and mirror to confirm network reachability.

Troubleshooting

If you still get error 1426 after following the steps, check the following:

  • Verify the backup completed successfully. Query SELECT database_name, backup_finish_date FROM msdb.dbo.backupset WHERE database_name = 'YourDatabase' AND type = 'D' ORDER BY backup_finish_date DESC;. The most recent full backup must be after the recovery model change.
  • Check the recovery model again. Run the query from step 1. If it reverted to SIMPLE, something changed it (perhaps a maintenance plan).
  • Ensure the database is not in a restoring state. If it is, you cannot alter it. Restore it with recovery first.
  • Look at the SQL Server error log. Error 1426 often comes with additional messages that point to the exact missing prerequisite.
  • If the witness command returns a different error (for example, a connection or authentication error), the 1426 is resolved but the witness cannot be reached. Check the endpoint state, firewall, and service account permissions.

Frequently Asked Questions

What exactly does error 1426 mean?

Error 1426 is "Database ... cannot be altered because it is not in FULL recovery mode or a full backup has not been taken." It is a safety check to ensure you can recover the database after mirroring changes.

Can I set the witness without a full backup?

No. The witness command requires both FULL recovery model and a full backup taken after switching to FULL. Without the backup, the command will fail with error 1426.

Does the witness server need a copy of the database?

No. The witness server does not host a copy of the database. It only maintains a connection to the principal and mirror to act as a tie-breaker during failover.

What if my database is already in FULL recovery model?

If it is already FULL, you still need a full backup taken after the last recovery model change. If no such backup exists, take one now, then run the witness command.

Can I use a witness with Azure SQL Database?

No. Database mirroring with a witness is a feature of SQL Server instances, not Azure SQL Database. Azure SQL Database uses different high-availability mechanisms.

How do I remove the witness later?

Run ALTER DATABASE YourDatabase SET WITNESS = OFF; from the principal. This does not affect the recovery model or backups.