資料庫鏡像 (SQL Server)Database Mirroring (SQL Server)

本主題的適用對象: 是SQL Server沒有Azure SQL Database沒有Azure SQL 資料倉儲沒有Parallel Data WarehouseTHIS TOPIC APPLIES TO: yesSQL ServernoAzure SQL DatabasenoAzure SQL Data Warehouse noParallel Data Warehouse

注意

未來的 Microsoft SQL Server 版本將移除這項功能。This feature will be removed in a future version of Microsoft SQL Server. 請避免在新的開發工作中使用這項功能,並規劃修改目前使用這項功能的應用程式。Avoid using this feature in new development work, and plan to modify applications that currently use this feature. 請改用 AlwaysOn 可用性群組Always On availability groups Use AlwaysOn 可用性群組Always On availability groups instead.

「資料庫鏡像」 (Database Mirroring) 是增加 SQL ServerSQL Server 資料庫可用性的方案。Database mirroring is a solution for increasing the availability of a SQL ServerSQL Server database. 鏡像是以每個資料庫為基準實作,只適用於使用完整復原模式的資料庫。Mirroring is implemented on a per-database basis and works only with databases that use the full recovery model.

重要

如需資料庫鏡像支援、限制、必要條件、設定夥伴伺服器之建議及部署資料庫鏡像之建議的資訊,請參閱 資料庫鏡像的必要條件、限制和建議事項For information about support for database mirroring, restrictions, prerequisites, recommendations for configuring partner servers, and recommendations for deploying database mirroring, see Prerequisites, Restrictions, and Recommendations for Database Mirroring.

資料庫鏡像的優點Benefits of Database Mirroring

資料庫鏡像是一種簡單的策略,提供了下列優點:Database mirroring is a simple strategy that offers the following benefits:

  • 提高資料庫的可用性。Increases availability of a database.

    萬一發生損毀時,在具有自動容錯移轉的高安全性模式下,容錯移轉便會迅速將資料庫的待命副本變成線上狀態 (無資料遺失)。In the event of a disaster, in high-safety mode with automatic failover, failover quickly brings the standby copy of the database online (without data loss). 在其他作業模式下,資料庫管理員則可選擇對資料庫的待命副本進行強制服務 (可能發生資料遺失)。In the other operating modes, the database administrator has the alternative of forcing service (with possible data loss) to the standby copy of the database. 如需詳細資訊,請參閱本主題稍後的 角色切換For more information, see Role Switching, later in this topic.

  • 增加資料保護。Increases data protection.

    資料庫鏡像可提供完整或近乎完整的資料備援性,端視作業模式是高安全性模式或高效能模式而定。Database mirroring provides complete or almost complete redundancy of the data, depending on whether the operating mode is high-safety or high-performance. 如需詳細資訊,請參閱本主題稍後的 作業模式For more information, see Operating Modes, later in this topic.

    SQL Server 2008 EnterpriseSQL Server 2008 Enterprise 或更新版本上執行的資料庫鏡像夥伴會自動嘗試解決阻礙讀取資料頁面的特定錯誤類型。A database mirroring partner running on SQL Server 2008 EnterpriseSQL Server 2008 Enterprise or later versions automatically tries to resolve certain types of errors that prevent reading a data page. 無法讀取頁面的夥伴會向其他夥伴要求全新副本。The partner that is unable to read a page requests a fresh copy from the other partner. 如果這個要求成功,無法讀取的頁面就會使用副本取代,這通常會解決錯誤。If this request succeeds, the unreadable page is replaced by the copy, which usually resolves the error. 如需詳細資訊,請參閱本主題稍後的 自動修復頁面 (可用性群組:資料庫鏡像)For more information, see Automatic Page Repair (Availability Groups: Database Mirroring).

  • 提升實際執行的資料庫在升級期間的可用性。Improves the availability of the production database during upgrades.

    若要將鏡像資料庫的停機時間減至最少,您可以循序升級裝載容錯移轉夥伴的 SQL ServerSQL Server 執行個體。To minimize downtime for a mirrored database, you can sequentially upgrade the instances of SQL ServerSQL Server that are hosting the failover partners. 這只需要承擔單一容錯移轉的停機時間。This will incur the downtime of only a single failover. 這種升級形式就稱為 「輪流升級」This form of upgrade is known as a rolling upgrade. 如需詳細資訊,請參閱 升級鏡像執行個體For more information, see Upgrading Mirrored Instances.

資料庫鏡像詞彙和定義Database Mirroring Terms and Definitions

自動容錯移轉automatic failover
如果主體伺服器變得無法使用,鏡像伺服器接替主體伺服器的角色,並使其資料庫副本連接成為主體資料庫的程序。The process by which, when the principal server becomes unavailable, the mirror server to take over the role of principal server and brings its copy of the database online as the principal database.

容錯移轉夥伴failover partners
充當鏡像資料庫之角色切換夥伴的兩個伺服器執行個體 (主體伺服器或鏡像伺服器)。The two server instances (the principal server or the mirror server) that act as role-switching partners for a mirrored database.

強制的服務forced service
資料庫擁有者在主體伺服器失敗時所起始的容錯移轉,它會將服務傳送至鏡像資料庫 (處於未知狀態)。A failover initiated by the database owner upon the failure of the principal server that transfers service to the mirror database while it is in an unknown state.

高效能模式High-performance mode
資料庫鏡像工作階段會以非同步方式作業,而且僅使用主體伺服器和鏡像伺服器。The database mirroring session operates asynchronously and uses only the principal server and mirror server. 唯一的角色切換形式是強制的服務 (可能造成資料遺失)。The only form of role switching is forced service (with possible data loss).

高安全性模式High-safety mode
資料庫鏡像工作階段會以同步方式作業,並選擇性地使用見證以及主體伺服器和鏡像伺服器。The database mirroring session operates synchronously and, optionally, uses a witness, as well as the principal server and mirror server.

手動容錯移轉manual failover
資料庫擁有者在主體伺服器仍然在執行時所起始的容錯移轉,它會將服務從主體資料庫傳送至鏡像資料庫 (它們都處於已同步處理狀態)。A failover initiated by the database owner, while the principal server is still running, that transfers service from the principal database to the mirror database while they are in a synchronized state.

鏡像資料庫mirror database
通常會與主體資料庫完全同步處理的資料庫副本。The copy of the database that is typically fully synchronized with the principal database.

鏡像伺服器mirror server
在資料庫鏡像組態中,指鏡像資料庫所在的伺服器執行個體。In a database mirroring configuration, the server instance on which the mirror database resides.

主體資料庫principal database
資料庫鏡像中的一種可讀寫資料庫,該資料庫的交易記錄檔記錄會套用至資料庫的唯讀副本 (鏡像資料庫)。In database mirroring, a read-write database whose transaction log records are applied to a read-only copy of the database (a mirror database).

主體伺服器principal server
資料庫鏡像中的夥伴,它的資料庫目前是主體資料庫。In database mirroring, the partner whose database is currently the principal database.

重做佇列redo queue
在鏡像伺服器磁碟上等待且接收的交易記錄檔記錄。Received transaction log records that are waiting on the disk of a mirror server.

角色 (role)role
主體伺服器和鏡像伺服器會執行互補的主體與鏡像角色。The principal server and mirror server perform complementary principal and mirror roles. 另外,也可以選擇由第三個伺服器執行個體扮演見證的角色。Optionally, the role of witness is performed by a third server instance.

角色切換role switching
由鏡像接管主體角色。The taking over of the principal role by the mirror.

傳送佇列send queue
已經在主體伺服器的記錄檔磁碟上累積的未傳送交易記錄檔記錄。Unsent transaction log records that have accumulated on the log disk of the principal server.

工作階段 (session)session
在資料庫鏡像期間,於主體伺服器、鏡像伺服器與見證伺服器 (如果存在的話) 之間所發生的關係。The relationship that occurs during database mirroring among the principal server, mirror server, and witness server (if present).

當鏡像工作階段開始或繼續之後,將主體伺服器上所累積的主體資料庫記錄檔記錄傳送到鏡像伺服器的程序,這個程序會盡快將這些記錄檔記錄寫入磁碟,以便能趕上主體伺服器。After a mirroring session starts or resumes, the process by which log records of the principal database that have accumulated on the principal server are sent to the mirror server, which writes these log records to disk as quickly as possible to catch up with the principal server.

交易安全性Transaction safety
鏡像特有的資料庫屬性,用來決定資料庫鏡像工作階段是以同步或非同步方式作業。A mirroring-specific database property that determines whether a database mirroring session operates synchronously or asynchronously. 有兩個安全性層級:FULL 和 OFF。There are two safety levels: FULL and OFF.

WitnessWitness
只能搭配高安全性模式使用的一種 SQL Server 選擇性執行個體,可讓鏡像伺服器辨別何時要起始自動容錯移轉。For use only with high-safety mode, an optional instance of SQL Server that enables the mirror server to recognize when to initiate an automatic failover. 與兩個容錯移轉夥伴不同的是,見證並不是為資料庫服務。Unlike the two failover partners, the witness does not serve the database. 支援自動容錯移轉是見證的唯一角色。Supporting automatic failover is the only role of the witness.

資料庫鏡像概觀Overview of Database Mirroring

資料庫鏡像會維護單一資料庫的兩份副本,而這兩份副本必須位於不同的 SQL Server Database EngineSQL Server Database Engine伺服器執行個體上。Database mirroring maintains two copies of a single database that must reside on different server instances of SQL Server Database EngineSQL Server Database Engine. 這些伺服器執行個體通常位於不同位置的電腦上。Typically, these server instances reside on computers in different locations. 在資料庫上啟動資料庫鏡像,起始這些伺服器執行個體之間的關係,稱為 「資料庫鏡像工作階段」(database mirroring session)。Starting database mirroring on a database, initiates a relationship, known as a database mirroring session, between these server instances.

其中一個伺服器執行個體會提供資料庫給用戶端 (「主體伺服器」)。One server instance serves the database to clients (the principal server). 另一個執行個體則當做熱或暖待命伺服器 (「鏡像伺服器」),端視鏡像工作階段的組態而定。The other instance acts as a hot or warm standby server (the mirror server), depending on the configuration and state of the mirroring session. 同步處理資料庫鏡像工作階段時,資料庫鏡像會提供熱待命伺服器來支援快速容錯移轉,因而不會遺失任何已認可的交易資料。When a database mirroring session is synchronized, database mirroring provides a hot standby server that supports rapid failover without a loss of data from committed transactions. 當工作階段無法同步處理時,鏡像伺服器通常會當做暖待命伺服器使用 (可能發生資料遺失)。When the session is not synchronized, the mirror server is typically available as a warm standby server (with possible data loss).

主體和鏡像伺服器會在 「資料庫鏡像工作階段」 內互相通訊,並如同 「夥伴」般彼此合作。The principal and mirror servers communicate and cooperate as partners in a database mirroring session. 這兩個夥伴在工作階段中扮演互補的角色: 「主體角色」 (Principal Role) 和 「鏡像角色」(Mirror Role)。The two partners perform complementary roles in the session: the principal role and the mirror role. 在任何時間內,一定有一個夥伴扮演主體角色,而另一個夥伴就扮演鏡像角色。At any given time, one partner performs the principal role, and the other partner performs the mirror role. 我們會以每個夥伴所 「擁有」 的目前角色來描述它們,Each partner is described as owning its current role. 擁有主體角色的夥伴稱為 「主體伺服器」,其資料庫副本就是目前的主體資料庫;The partner that owns the principal role is known as the principal server, and its copy of the database is the current principal database. 而擁有鏡像角色的夥伴則稱為 「鏡像伺服器」,其資料庫副本就是目前的鏡像資料庫。The partner that owns the mirror role is known as the mirror server, and its copy of the database is the current mirror database. 在實際執行環境中部署資料庫鏡像時,主體資料庫就是 「實際執行的資料庫」When database mirroring is deployed in a production environment, the principal database is the production database.

資料庫鏡像涉及將主體資料庫上發生的每一項插入、更新和刪除作業,儘快 「重做」 到鏡像資料庫上。Database mirroring involves redoing every insert, update, and delete operation that occurs on the principal database onto the mirror database as quickly as possible. 完成重做的方式是將使用中交易記錄檔記錄的資料流傳送到鏡像伺服器,再由鏡像伺服器盡快依序將記錄套用到鏡像資料庫。Redoing is accomplished by sending a stream of active transaction log records to the mirror server, which applies log records to the mirror database, in sequence, as quickly as possible. 與在邏輯層級運作的複寫不同,資料庫鏡像是在實體記錄層級運作。Unlike replication, which works at the logical level, database mirroring works at the level of the physical log record. SQL Server 2008SQL Server 2008開始,主體伺服器會先壓縮交易記錄檔記錄的資料流,然後再將它傳送至鏡像伺服器。Beginning in SQL Server 2008SQL Server 2008, the principal server compresses the stream of transaction log records before sending it to the mirror server. 這個記錄檔壓縮作業會在所有鏡像工作階段中進行。This log compression occurs in all mirroring sessions.

注意

給定的伺服器執行個體可參與具有相同或不同夥伴的多個並行資料庫鏡像工作階段。A given server instance can participate in multiple concurrent database mirroring sessions with the same or different partners. 伺服器執行個體可以在某些工作階段中是夥伴,在其他工作階段中是見證。A server instance can be a partner in some sessions and a witness in other sessions. 鏡像伺服器執行個體必須執行相同版本的 SQL ServerSQL ServerThe mirror server instance must be running the same edition of SQL ServerSQL Server.

本節內容:In This Section:

作業模式Operating Modes

資料庫鏡像工作階段可與同步或非同步作業一起執行。A database mirroring session runs with either synchronous or asynchronous operation. 在非同步作業下,交易不會等待鏡像伺服器將記錄寫入磁碟,即逕行認可,藉以達到最大效能。Under asynchronous operation, the transactions commit without waiting for the mirror server to write the log to disk, which maximizes performance. 在同步作業下,交易將同時在兩個夥伴上進行認可,代價是會增加交易延遲性。Under synchronous operation, a transaction is committed on both partners, but at the cost of increased transaction latency.

鏡像作業模式共有兩種。There are two mirroring operating modes. 其中一種模式 (「高安全性模式」) 可支援同步作業。One of them, high-safety mode supports synchronous operation. 在高安全性模式下,當工作階段開始時,鏡像伺服器會儘快將鏡像資料庫與主體資料庫進行同步處理。Under high-safety mode, when a session starts, the mirror server synchronizes the mirror database together with the principal database as quickly as possible. 一旦資料庫同步處理完成之後,交易將同時在兩個夥伴上進行認可,代價是會增加交易延遲性。As soon as the databases are synchronized, a transaction is committed on both partners, at the cost of increased transaction latency.

第二種作業模式 (「高效能模式」) 則以非同步方式執行。The second operating mode, high-performance mode, runs asynchronously. 鏡像伺服器會盡量跟上主體伺服器所傳送的記錄。The mirror server tries to keep up with the log records sent by the principal server. 鏡像資料庫可能會稍微落後主體資料庫。The mirror database might lag somewhat behind the principal database. 然而,在資料庫之間的間距通常很小。However, typically, the gap between the databases is small. 但是,若主體伺服器的工作負載很大,或鏡像伺服器的系統超載時,此差距就會變大。However, the gap can become significant if the principal server is under a heavy work load or the system of the mirror server is overloaded.

在高效能模式中,當主體伺服器傳送記錄到鏡像伺服器時,主體伺服器會立即傳送確認給用戶端。In high-performance mode, as soon as the principal server sends a log record to the mirror server, the principal server sends a confirmation to the client. 它不會等候鏡像伺服器的收條。It does not wait for an acknowledgement from the mirror server. 這表示交易不會等待鏡像伺服器將記錄寫入磁碟,即逕行認可。This means that transactions commit without waiting for the mirror server to write the log to disk. 這種非同步作業可以讓主體伺服器在執行時將交易延遲性降到最低,但必須承擔可能遺失資料的風險。Such asynchronous operation enables the principal server to run with minimum transaction latency, at the potential risk of some data loss.

所有的資料庫鏡像工作階段都只能支援一部主體伺服器和一部鏡像伺服器。All database mirroring sessions support only one principal server and one mirror server. 這種組態顯示在下圖中。This configuration is shown in the following illustration.

資料庫鏡像工作階段中的夥伴Partners in a database mirroring session

具有自動容錯移轉的高安全性模式需要第三個伺服器執行個體,稱為「見證」。High-safety mode with automatic failover requires a third server instance, known as a witness. 與兩位夥伴不同的是,見證並不是為資料庫服務。Unlike the two partners, the witness does not serve the database. 見證會藉由確認主體伺服器是否已啟動而且可以正常運作,支援自動容錯移轉。The witness supports automatic failover by verifying whether the principal server is up and functioning. 只有當鏡像和見證與主體伺服器中斷連接後仍然保持相互連接時,鏡像伺服器才會開始進行自動容錯移轉。The mirror server initiates automatic failover only if the mirror and the witness remain connected to each other after both have been disconnected from the principal server.

下圖顯示包括見證的組態。The following illustration shows a configuration that includes a witness.

包含旁觀的鏡像工作階段A mirroring session that includes a witness

如需詳細資訊,請參閱本主題稍後的 角色切換For more information, see Role Switching, later in this topic.

注意

建立新的鏡像工作階段或將見證加入至現有鏡像組態時,會要求所有涉及的伺服器執行個體都執行相同版本的 SQL ServerSQL ServerEstablishing a new mirroring session or adding a witness to an existing mirroring configuration requires that all involved server instances run the same version of SQL ServerSQL Server. 不過,當您升級為 SQL Server 2008SQL Server 2008 或更新版本時,這些相關執行個體的版本可能會不同。However, when you are upgrading to SQL Server 2008SQL Server 2008 or a later version, the versions of the involved instances can vary. 如需詳細資訊,請參閱 升級鏡像執行個體For more information, see Upgrading Mirrored Instances.

交易安全性與作業模式Transaction Safety and Operating Modes

作業模式為同步或非同步作業需視其交易安全性設定而定。Whether an operating mode is asynchronous or synchronous depends on the transaction safety setting. 如果您以獨佔模式使用 Transact-SQLSQL Server Management Studio 來設定資料庫鏡像,系統便會在您選取作業模式時自動設定交易安全性設定。If you exclusively use Transact-SQLSQL Server Management Studio to configure database mirroring, transaction safety settings are configured automatically when you select the operation mode.

如果使用 Transact-SQLTransact-SQL 來設定資料庫鏡像,您就必須了解設定交易安全性的方式。If you use Transact-SQLTransact-SQL to configure database mirroring, you must understand how to set transaction safety. 交易安全性是由 ALTER DATABASE 陳述式的 SAFETY 屬性所控制。Transaction safety is controlled by the SAFETY property of the ALTER DATABASE statement. 在要進行鏡像的資料庫上,SAFETY 不是 FULL 就是 OFF。On a database that is being mirrored, SAFETY is either FULL or OFF.

  • 如果 SAFETY 選項設為 FULL,在初始同步處理階段之後的資料庫鏡像便為同步作業。If the SAFETY option is set to FULL, database mirroring operation is synchronous, after the initial synchronizing phase. 如果見證是在高安全性模式下設定,工作階段就會支援自動容錯移轉。If a witness is set in high-safety mode, the session supports automatic failover.

  • 如果 SAFETY 選項設為 OFF,資料庫鏡像便為非同步作業。If the SAFETY option is set to OFF, database mirroring operation is asynchronous. 工作階段將以高效能模式執行,而且 WITNESS 選項也應該設為 OFF。The session runs in high-performance mode, and the WITNESS option should also be OFF.

    如需詳細資訊,請參閱 Database Mirroring Operating ModesFor more information, see Database Mirroring Operating Modes.

角色切換Role Switching

在資料庫鏡像工作階段的內容中,主體與鏡像角色通常可以用一種稱為 「角色切換」的程序交換。Within the context of a database mirroring session, the principal and mirror roles are typically interchangeable in a process known as role switching. 角色切換包括將主體角色傳送給鏡像伺服器。Role switching involves transferring the principal role to the mirror server. 在角色切換中,鏡像伺服器將充當主體伺服器的 「容錯移轉夥伴」In role switching, the mirror server acts as the failover partner for the principal server. 發生角色切換時,鏡像伺服器將接替主體角色,並使其資料庫副本變成線上狀態以做為主體資料庫。When a role switch occurs, the mirror server takes over the principal role and brings its copy of the database online as the new principal database. 先前的主體伺服器 (如果有的話) 將會擔任鏡像角色,而其資料庫則會變成新的鏡像資料庫。The former principal server, if available, assumes the mirror role, and its database becomes the new mirror database. 原則上,各角色可以重複來回切換。Potentially, the roles can switch back and forth repeatedly.

角色切換有下列三種形式。The following three forms of role switching exist.

  • Automatic failoverAutomatic failover

    這種形式需要使用高安全性模式而且鏡像伺服器和見證必須存在。This requires high-safety mode and the presence of the mirror server and a witness. 資料庫必須已同步處理,而見證也必須連接到鏡像伺服器。The database must already be synchronized, and the witness must be connected to the mirror server.

    見證角色是用來驗證特定的夥伴伺服器是否已啟動而且可以正常運作。The role of the witness is to verify whether a given partner server is up and functioning. 如果鏡像伺服器與主體伺服器的連接中斷,但見證仍與主體伺服器連接,鏡像伺服器就不會起始容錯移轉。If the mirror server loses its connection to the principal server but the witness is still connected to the principal server, the mirror server does not initiate a failover. 如需詳細資訊,請參閱 資料庫鏡像見證For more information, see Database Mirroring Witness.

  • Manual failoverManual failover

    這種形式需要使用高安全性模式。This requires high-safety mode. 夥伴必須互相連接,而且資料庫也必須已完成同步處理。The partners must be connected to each other, and the database must already be synchronized.

  • 強制服務 (可能發生資料遺失)Forced service (with possible data loss)

    在高效能模式與不含自動容錯移轉的高安全性模式中,如果主體伺服器已經故障,但鏡像伺服器仍然可用,就可以使用強制服務。Under high-performance mode and high-safety mode without automatic failover, forcing service is possible if the principal server has failed and the mirror server is available.

    重要

    高效能模式是在沒有見證的情況下執行的模式。High-performance mode is intended to run without a witness. 但是如果有見證存在,該見證就必須連接到鏡像伺服器,才能使用強制服務。But if a witness exists, forcing service requires that the witness is connected to the mirror server.

    在任何角色切換案例中,一旦新主體資料庫變成線上狀態之後,用戶端應用程式就可以重新連接到該資料庫來快速復原。In any role-switching scenario, as soon as the new principal database comes online, the client applications can recover quickly by reconnecting to the database.

並行工作階段Concurrent Sessions

給定的伺服器執行個體可以參與具有相同或不同伺服器執行個體的多個並行資料庫鏡像工作階段 (每個鏡像資料庫一個)。A given server instance can participate in multiple, concurrent database mirroring sessions (once per mirrored database) with the same or different server instances. 通常,伺服器執行個體在所有資料庫鏡像工作階段中會專門當做夥伴或見證服務。Often, a server instance serves exclusively as a partner or a witness in all of its database mirroring sessions. 不過,由於每個工作階段獨立於其他工作階段,所以伺服器執行個體可以在某些工作階段中當做夥伴,而在其他工作階段中當做見證。However, because each session is independent of the other sessions, a server instance can act as a partner in some sessions and as a witness in other sessions. 例如,請考慮下列在三個伺服器執行個體 (SSInstance_1SSInstance_2SSInstance_3) 中的四個工作階段。For example, consider the following four sessions among three server instances (SSInstance_1, SSInstance_2, and SSInstance_3). 每個伺服器執行個體會在某些工作階段中當做夥伴服務,而在其他工作階段中當做見證服務:Each server instance serves as a partner in some sessions and as a witness in others:

伺服器執行個體Server instance 資料庫 A 的工作階段Session for database A 資料庫 B 的工作階段Session for database B 資料庫 C 的工作階段Session for database C 資料庫 D 的工作階段Session for database D
SSInstance_1 WitnessWitness PartnerPartner PartnerPartner PartnerPartner
SSInstance_2 PartnerPartner WitnessWitness PartnerPartner PartnerPartner
SSInstance_3 PartnerPartner PartnerPartner WitnessWitness WitnessWitness

下圖說明兩個伺服器執行個體以夥伴伺服器的角色,共同參與兩個鏡像工作階段。The following figure illustrates two server instances that are participating as partners together in two mirroring sessions. 其中一個工作階段用於名為 Db_1的資料庫,另一個工作階段則用於名為 Db_2的資料庫。One session is for a database named Db_1, and the other session is for a database named Db_2.

兩個並行工作階段中的兩個伺服器執行個體Two server instances in two concurrent sessions

資料庫彼此之間無關。Each of the databases is independent of the others. 例如,一個伺服器執行個體最初可能同時是兩個資料庫的鏡像伺服器。For example, a server instance might initially be the mirror server for two databases. 如果其中一個資料庫發生容錯移轉,該伺服器執行個體會變成容錯移轉資料庫的主體伺服器,但同時維持另一個資料庫的鏡像伺服器身分。If one of those databases fails over, the server instance becomes the principal server for the failed-over database while remaining the mirror server for the other database.

另舉一例,假設有一個伺服器執行個體做為兩個以上資料庫的主體伺服器,並在具有自動容錯移轉的高安全性模式下執行;如果這個伺服器執行個體故障了,則所有資料庫都會自動容錯移轉到其各自的鏡像資料庫。As another example, consider a server instance that is the principal server for two or more databases running in high-safety mode with automatic failover, If the server instance fails, all of the databases automatically failover to their respective mirror databases.

將伺服器執行個體設定為同時以夥伴與見證來運作時,請確定資料庫鏡像端點支援這兩個角色 (如需詳細資訊,請參閱 資料庫鏡像端點 (SQL Server)) 中的四個工作階段。When setting up a server instance to operate both as a partner and a witness, be sure that the database mirroring endpoint supports both roles (for more information, see The Database Mirroring Endpoint (SQL Server)). 另外,也請確定系統具有足夠資源,以減少資源競爭問題。Also, ensure that the system has sufficient resources to reduce resource contention.

注意

由於鏡像資料庫彼此獨立,因此資料庫不能當做群組來容錯移轉。Because mirrored databases are independent of each other, databases cannot fail over as a group.

用戶端連接Client Connections

資料庫鏡像工作階段的用戶端連接支援是由 MicrosoftMicrosoft .NET Data Provider for SQL ServerSQL Server提供。Client-connection support for database mirroring sessions is provided by the MicrosoftMicrosoft .NET Data Provider for SQL ServerSQL Server. 如需詳細資訊,請參閱本主題稍後的 將用戶端連接至資料庫鏡像工作階段 (SQL Server)For more information, see Connect Clients to a Database Mirroring Session (SQL Server).

暫停工作階段對主體交易記錄的影響Impact of Pausing a Session on the Principal Transaction Log

資料庫擁有者可以隨時暫停工作階段。At any time, the database owner can pause a session. 暫停會保留工作階段狀態,同時移除鏡像。Pausing preserves the session state while removing mirroring. 工作階段暫停時,主體伺服器不會將任何新的記錄傳送到鏡像伺服器。When a session is paused, the principal server does not send any new log records to the mirror server. 這些記錄全都保持使用中狀態,並累積到主體資料庫的交易記錄中。All of these records remain active and accumulate in the transaction log of the principal database. 只要資料庫鏡像工作階段保持暫停狀態,交易記錄便無法截斷。As long as a database mirroring session remains paused, the transaction log cannot be truncated. 因此,如果資料庫鏡像工作階段暫停太久,就會填滿記錄。Therefore, if the database mirroring session is paused for too long, the log can fill up.

如需詳細資訊,請參閱本主題稍後的 暫停與繼續資料庫鏡像 (SQL Server)For more information, see Pausing and Resuming Database Mirroring (SQL Server).

設定資料庫鏡像工作階段Setting Up Database Mirroring Session

資料庫擁有者或系統管理員必須先建立鏡像資料庫、設定端點與登入,而在某些情況下,還必須建立並設定憑證,之後才可以開始鏡像工作階段。Before a mirroring session can begin, the database owner or system administrator must create the mirror database, set up endpoints and logins, and, in some cases, create and set up certificates. 如需詳細資訊,請參閱本主題稍後的 設定資料庫鏡像 (SQL Server)For more information, see Setting Up Database Mirroring (SQL Server).

與其他 Database Engine 功能的互通性和共存性Interoperability and Coexistence with Other Database Engine Features

資料庫鏡像可與 SQL ServerSQL Server的下列功能或元件搭配使用。Database mirroring can be used with the following features or components of SQL ServerSQL Server.

本節內容In This Section

資料庫鏡像的必要條件、限制和建議事項Prerequisites, Restrictions, and Recommendations for Database Mirroring
描述設定資料庫鏡像的必要條件和建議事項。Describes the prerequisites and recommendations for setting up database mirroring.

Database Mirroring Operating ModesDatabase Mirroring Operating Modes
包含有關資料庫鏡像工作階段的同步與非同步作業模式,以及在資料庫鏡像工作階段期間切換夥伴角色的資訊。Contains information about the synchronous and asynchronous operating modes for database mirroring sessions, and about switching partner roles during a database mirroring session.

資料庫鏡像見證Database Mirroring Witness
說明資料庫鏡像中見證的角色、如何在多個鏡像工作階段中使用單一見證、見證的軟體和硬體建議以及自動容錯移轉中見證的角色。Describes the role of a witness in database mirroring, how to use a single witness in multiple mirroring sessions, software and hardware recommendations for witnesses, and the role of the witness in automatic failover. 也包括有關加入或移除見證的資訊。It also contains information about adding or removing a witness.

資料庫鏡像工作階段期間的角色切換 (SQL Server)Role Switching During a Database Mirroring Session (SQL Server)
包含有關在資料庫鏡像工作階段期間切換夥伴角色,包括自動容錯移轉、手動容錯移轉,以及強制服務 (資料可能會遺失) 的資訊。Contains information about switching partner roles during a database mirroring session, including automatic failover, manual failover, and forced service (with possible data loss). 同時包含有關評估角色切換期間服務中斷的資訊。Also, contains information about estimating the interruption of service during role switching.

資料庫鏡像期間可能發生的失敗Possible Failures During Database Mirroring
討論可能導致資料庫鏡像工作階段中發生失敗的實體、作業系統和 SQL ServerSQL Server 問題,包括重大錯誤和軟性錯誤。Discusses physical, operating system, and SQL ServerSQL Server problems, including hard errors and soft errors, that can cause a failure in a database mirroring session. 討論鏡像逾時機制如何回應軟性錯誤。Discusses how the mirroring time-out mechanism responds to soft errors.

資料庫鏡像端點 (SQL Server)The Database Mirroring Endpoint (SQL Server)
討論資料庫鏡像端點的運作方式。Discusses how the database mirroring endpoint functions.

設定資料庫鏡像 (SQL Server)Setting Up Database Mirroring (SQL Server)
包含有關設定資料庫鏡像之必要條件、建議事項及步驟的主題。Contains topics about the prerequisites, recommendations, and steps for setting up database mirroring.

將用戶端連接至資料庫鏡像工作階段 (SQL Server)Connect Clients to a Database Mirroring Session (SQL Server)
包含涵蓋用戶端連接字串屬性以及將用戶端連接和重新連接至鏡像資料庫之演算法的主題。Contains topics covering client connection-string attributes and the algorithms for connecting and reconnecting a client to a mirrored database.

暫停與繼續資料庫鏡像 (SQL Server)Pausing and Resuming Database Mirroring (SQL Server)
討論當資料庫鏡像暫停時會發生什麼事 (包括對交易記錄截斷的影響) 並包含有關如何暫停和繼續資料庫鏡像的說明。Discusses what happens while database mirroring is paused, including the impact on transaction log truncation, and contains descriptions about how to pause and resume database mirroring.

移除資料庫鏡像 (SQL Server)Removing Database Mirroring (SQL Server)
討論移除鏡像的影響,並包含有關如何結束工作階段的說明。Discusses the impact of removing mirroring and contains descriptions about how to end a session

監視資料庫鏡像 (SQL Server)Monitoring Database Mirroring (SQL Server)
包含有關如何使用「資料庫鏡像監視器」或 dbmmonitor 預存程序來監視資料庫鏡像或工作階段的資訊。Contains information about using Database Mirroring Monitor or the dbmmonitor stored procedures to monitor database mirroring or sessions.

相關工作Related Tasks

組態工作Configuration Tasks

使用 SQL Server Management StudioUsing SQL Server Management Studio

系統管理工作Administrative Tasks

Transact-SQLTransact-SQL

另請參閱See Also

資料庫鏡像端點 (SQL Server) The Database Mirroring Endpoint (SQL Server)
自動修復頁面 (可用性群組:資料庫鏡像) Automatic Page Repair (Availability Groups: Database Mirroring)
為資料庫鏡像組態進行疑難排解 (SQL Server) (SQL Server) Troubleshoot Database Mirroring Configuration (SQL Server)
資料庫鏡像:互通性與共存性 (SQL Server) Database Mirroring: Interoperability and Coexistence (SQL Server)
資料庫鏡像的必要條件、限制和建議事項 Prerequisites, Restrictions, and Recommendations for Database Mirroring
AlwaysOn 可用性群組概觀 (SQL Server) Overview of Always On Availability Groups (SQL Server)
關於記錄傳送 (SQL Server)About Log Shipping (SQL Server)