Differences Between Log Shipping, Mirroring, and Replication in SQL Server

Log Shipping

Log Shipping automatically sends transaction log backups from one database (primary database) to another database (secondary database) on a different server. An optional third server, known as the monitor server, records the history and status of backup and restore operations and can raise alerts if these operations fail to occur as scheduled.

Mirroring

Database mirroring is a software solution primarily designed to increase database availability. It maintains two copies of a single database on different server instances of SQL Server Database Engine.

Replication

Replication is a set of technologies for copying and distributing data and database objects from one database to another, then synchronizing between databases to maintain consistency. Using replication, data can be distributed to different locations and to remote or mobile users over local and wide area networks, dial-up connections, wireless connections, and the Internet.

Components

  • Log Shipping: Primary server, secondary server, and monitor server (optional).
  • Mirroring: Principal server, mirror server, and witness server (optional).
  • Replication: Publisher, subscribers, distributor (optional).

Data Transfer

  • Log Shipping: Transaction logs are backed up and transferred to the secondary server.
  • Mirroring: Individual transaction log records are transferred using TCP endpoints.
  • Replication: Changes are tracked/detected (either by triggers or log scanning) and shipped.

Server Limitation

  • Log Shipping: Configurable as one-to-many (one primary server to many secondary servers) or many-to-one (multiple primary databases on different servers to one secondary server).
  • Mirroring: One-to-one (one principal server to one mirror server).
  • Replication: Various topologies including central publisher/distributor with multiple subscribers, central distributor with multiple publishers and subscribers, and mixed topologies.

Types of Failover

  • Log Shipping: Manual.
  • Mirroring: Automatic or manual.
  • Replication: Manual.

Database Access

  • Log Shipping: Secondary database can be used for reporting in STANDBY mode.
  • Mirroring: Mirrored database can only be accessed using a snapshot.
  • Replication: Subscriber database is open to reads and writes.

Recovery Model

  • Log Shipping: Supports both Bulk Logged and Full Recovery Models.
  • Mirroring: Supports only Full Recovery Model.
  • Replication: Supports Full Recovery Model.

Restoring State

  • Log Shipping: Can be completed using either NORECOVERY or STANDBY option.
  • Mirroring: Can be completed using NORECOVERY.
  • Replication: Can be completed using RECOVERY.

Backup/Restore

  • Log Shipping: Can be done manually or through Log Shipping options.
  • Mirroring: Must be done manually by the user.
  • Replication: Create an empty database with the same name.

Monitor/Distributor/Witness

  • Log Shipping: The monitor server should be separate from the primary or secondary servers. If not used, alert jobs are created locally on the primary and secondary servers.
  • Mirroring: The principal server cannot act as both principal and witness server.
  • Replication: The publisher can also be the distributor.

Types of Servers

  • Log Shipping: All servers must be SQL Server.
  • Mirroring: All servers must be SQL Server.
  • Replication: The publisher can be an Oracle Server.

SQL Server Agent Dependency/Jobs

  • Log Shipping: Yes, involves four jobs handled by SQL Server Agent jobs (backup, copy, restore, alert).
  • Mirroring: Independent of SQL Server Agent.
  • Replication: Yes, involves Snapshot Agent, Log Reader Agent, and Distribution Agent (transactional replication), and Merge Agent (merge replication).

Requirements

Log Shipping:

  • Same logical design and collation settings for involved servers.
  • Databases must use Full or Bulk-Logged Recovery Models.
  • SQL Server Agent should start automatically.
  • Sysadmin privileges are required on each server.

Mirroring:

  • No differences in system collation settings.
  • Identical local Windows groups and SQL Server login definitions on both servers.
  • Same external software components installed on both servers.
  • Identical SQL Server software versions on both servers.
  • Identical global assemblies on both servers.
  • Matching certificates and keys for authentication and encryption.

Replication:

  • No differences in system collation settings.
  • Identical local Windows groups and SQL Server login definitions on both servers.
  • Same external software components installed on both servers.
  • CLR assemblies deployed on the publisher must also be deployed on the subscriber.
  • SQL Agent jobs and alerts required on the subscriber server.
  • Matching certificates and keys for authentication and encryption.

Using with Other Features or Components

  • Log Shipping: Can be used with Database Mirroring and Replication.
  • Mirroring: Can be used with Log Shipping, Database Snapshots, and Replication.
  • Replication: Can be used with Log Shipping and Database Mirroring.

DDL Operations

  • Log Shipping: DDL changes are applied automatically.
  • Mirroring: DDL changes are applied automatically.
  • Replication: Only DML changes to published tables are replicated.

Database Limit

  • Log Shipping: No limit.
  • Mirroring: Generally recommended to have up to 10 databases per server.
  • Replication: No limit.

Latency

  • Log Shipping: Data transfer latency >1 minute.
  • Mirroring: No data transfer latency.
  • Replication: Latency can be as low as a few seconds.

Committed/Uncommitted Transactions

  • Log Shipping: Both committed and uncommitted transactions are transferred to the secondary database.
  • Mirroring: Only committed transactions are transferred to the mirror database.
  • Replication: Only committed transactions are transferred to the subscriber database.

Primary Key

  • Log Shipping: Not required.
  • Mirroring: Not required.
  • Replication: All replicated tables must have a primary key.

New Created Database & Stored Procedure

  • Log Shipping: Monitoring and history information stored in msdb, accessed using log shipping stored procedures.
  • Replication: Creates new stored procedures (three per table) and a distribution database. A rowguid column is created.

Individual Articles

  • Log Shipping: No, the whole database must be selected.
  • Mirroring: No, the whole database must be selected.
  • Replication: Yes, including tables, views, stored procedures, and other objects. Filters can restrict columns and rows sent to subscribers.

FILESTREAM

  • Log Shipping: Supports FILESTREAM.
  • Mirroring: Does not support FILESTREAM.
  • Replication: Supports FILESTREAM.

Database Name

  • Log Shipping: Secondary database can have a different name from the primary database.
  • Mirroring: Must have the same name.
  • Replication: Must have the same name.

Database Availability

  • Log Shipping: In standby mode: read-only database. In restoring mode with NORECOVERY: restoring state.
  • Mirroring: In recovery state, no user operations allowed. Can take a snapshot.
  • Replication: Snapshot replication (read-only), other types (databases are available).

Warm/Hot Standby Solution

  • Log Shipping: Provides a warm standby solution with multiple copies of a database and requires manual failover.
  • Mirroring: Provides a hot standby server with automatic failover when synchronized, otherwise a warm standby server with possible data loss.
  • Replication: Provides a warm standby solution with multiple copies of a database and requires manual failover.

System Data Transferred

  • Log Shipping: Mostly.
  • Mirroring: Yes.
  • Replication: No.

System Databases

  • Mirroring: Cannot mirror Master, msdb, tempdb, or model databases.

Mode or Types

Log Shipping:

  • Standby mode (read-only): disconnect users when restoring backups.
  • No recovery mode (restoring state): user cannot access the secondary database.

Mirroring:

  • High-safety mode: supports synchronous operation.
  • High-performance mode: runs asynchronously.
  • High-safety mode with automatic failover.

Replication:

  • Snapshot replication.
  • Transactional replication.
  • Transactional publication with updatable subscriptions.
  • Merge publication.
  • Pull/push subscription.

No comments:

Post a Comment