在 SharePoint Server 中執行使用唯讀資料庫的伺服器陣列Run a farm that uses read-only databases in SharePoint Server

摘要: 了解如何在部分或所有資料庫設為唯讀時,執行唯讀的 SharePoint Server 2016 和 SharePoint 2013 伺服器陣列。Summary: Learn how to run a read-only SharePoint Server 2016 and SharePoint 2013 farm with some or all databases set as read-only.

您可以使用 Microsoft PowerShell 或 SQL Server 工具將 SharePoint Server 資料庫設為唯讀。所使用的工具取決於已部署的環境類型、排程需求以及您組織的服務等級協定而定。You can use Microsoft PowerShell or SQL Server tools to set your SharePoint Server databases to read-only. The tool that you use depends on the kind of environment that you have deployed, your schedule requirements, and service level agreements that you have made with your organization.

開始之前Before you begin

開始這項作業之前,請先檢閱下列如何建立唯讀伺服器陣列之設定的相關資訊:Before you begin this operation, review the following information about the settings that make a read-only farm.

如果下列任一條件為真,則伺服器陣列將被視為唯讀:A farm is considered read-only if one of the following is true:

  • 設定所有內容資料庫為唯讀。All content databases are set to read-only.

  • 設定服務應用程式資料庫為唯讀。Service application databases are set to read-only.

    注意

    當 Search Service 應用程式的資料庫設定為唯讀時,該應用程式無法作用。The Search service application does not function when its databases are set as read-only.

唯讀伺服器陣列中的功能與使用者經驗取決於哪些資料庫設定為唯讀。The functionality and user experience in a read-only farm depends on the databases that are set to read-only.

注意

使用唯讀內容與服務應用程式資料庫的伺服器陣列,很可能屬於損毀修復環境或高可用性的維護、更新或升級環境的一部分。A farm that uses read-only content and service application databases is likely to be part of a disaster recovery environment or a highly available maintenance, update, or upgrade environment.

為使用者準備唯讀經驗Prepare users for the read-only experience

如果您打算向使用者提供存取唯讀網站或伺服器陣列的權限,則您應該要設定使用者能夠在此網站上完成哪些工作,以及使用者介面 (UI) 的行為。If you plan to give users access to a read-only site or farm, you should set expectations for tasks that users can complete on the site and the behavior of the user interface (UI).

使用唯讀內容資料庫的網站Sites that use read-only content databases

使用設定為唯讀內容資料庫網站的使用者經驗具備下列特性:The user experience of a site that uses a content database that is set to read-only is characterized by the following:

  • 首頁上的陳述說明了網站是唯讀的。A statement at the top of the home page states that the site is read-only.

  • 可完整使用不需要寫入內容資料庫的常見工作。Common tasks that do not require writing to the content database are fully available.

  • 需要寫入內容資料庫的常見工作無法使用,因為工作的 UI 不提供使用或因為使用者無法套用變更以完成工作。Common tasks that require writing to the content database are not available either because the UI for the task is not available or because the user cannot apply changes to complete the task.

  • 某些需要寫入內容資料庫的常見工作好像可以使用卻傳回錯誤。Some common tasks that require writing to the content database and that appear to be available return errors.

使用唯讀服務應用程式資料庫的伺服器陣列Farms that use read-only service application databases

使用設定為唯讀的服務應用程式資料庫伺服器陣列的使用者經驗具備下列特性:The user experience on a farm that uses service application databases that are set to read-only is characterized by the following:

  • 可以完整使用不需要寫入服務資料庫的常見工作。Common tasks that do not require writing to the service databases are fully available.

  • 所有需要寫入服務資料庫的常見工作好像可以使用卻傳回錯誤。All common tasks that require writing to the service databases and that appear to be available return errors.

設定內容資料庫為唯讀Set content databases to read-only

在設定內容資料庫為唯讀之前,可能需要確定建立哪個內容資料庫與特定網站集合的關聯。Before you set content databases to read-only, you may need to determine the content database that is associated with a particular site collection.

使用 PowerShell 確定建立內容資料庫與網站集合的關聯To determine the content database that is associated with a site collection by using PowerShell

  1. 確認您具備下列成員身分:Verify that you have the following memberships:

    • SQL Server 執行個體上的 securityadmin 固定伺服器角色。securityadmin fixed server role on the SQL Server instance.

    • 所有要更新之資料庫上的 db_owner 固定資料庫角色。db_owner fixed database role on all databases that are to be updated.

    • 正在執行 PowerShell Cmdlet 之所在伺服器上的系統管理員群組。Administrators group on the server on which you are running the PowerShell cmdlets.

      系統管理員可以使用 Add-SPShellAdmin Cmdlet 授與使用 SharePoint Server Cmdlet 的權限。An administrator can use the Add-SPShellAdmin cmdlet to grant permissions to use SharePoint Server cmdlets.

      注意

      如果您不具備上述權限,請連絡安裝程式系統管理員或 SQL Server 系統管理員要求權限。如需 PowerShell 權限的其他資訊,請參閱 Add-SPShellAdminIf you do not have permissions, contact your Setup administrator or SQL Server administrator to request permissions. For additional information about PowerShell permissions, see Add-SPShellAdmin.

  2. 啟動 SharePoint 管理命令介面。Start the SharePoint Management Shell.

  3. 在 PowerShell 命令提示字元中,輸入下列命令:At the PowerShell command prompt, type the following command:

    Get-SPContentDatabase -Site <Site URL>
    

    其中:Where:

    • <Site URL> 是要了解其相關內容資料庫的網站集合 URL。<Site URL> is the site collection URL for which you want to know the associated content database.

      此命令傳回與此網站相關聯的內容資料庫。The command returns the content database that is associated with the site.

如需詳細資訊,請參閱<Get-SPContentDatabase>。For more information, see Get-SPContentDatabase.

注意

建議您在執行命令列管理工作時使用 Windows PowerShell。Stsadm 命令列工具已過時,但為與舊版產品相容,仍會隨附提供。We recommend that you use Microsoft PowerShell when performing command-line administrative tasks. The Stsadm command-line tool has been deprecated, but is included to support compatibility with previous product versions.

您可以遵循這些步驟透過 SQL Server Management Studio 將讀/寫內容資料庫設定為唯讀。還可以使用 Transact-SQL ALTER DATABASE 陳述式將內容資料庫設定為唯讀。如需詳細資訊,請參閱< ALTER DATABASE (Transact-SQL)>。You can follow these steps to set read/write content databases to be read-only by using SQL Server Management Studio. You can also use the Transact-SQL ALTER DATABASE statement to set content databases to be read-only. For more information, see ALTER DATABASE (Transact-SQL).

重要

請勿對容錯移轉環境中的記錄傳送資料庫或鏡像資料庫執行此程序。如果容錯移轉環境中的資料庫是記錄傳送或鏡像資料庫並被設為唯讀,不但無法執行更新,備份也會是無效的。Do not perform this procedure on databases in a failover environment that were log-shipped or mirrored. If a database in a failover environment that is either log-shipped or mirrored is set as read-only then no updates are performed and the backup is not valid.

使用 SQL Server 將內容資料庫設為唯讀To set content databases to read-only by using SQL Server

  1. 確認執行此程序的使用者帳戶為每個資料庫之 db_owner 固定資料庫角色的成員。Verify that the user account that is performing this procedure is a member of the db_owner fixed database role in each database.

  2. 啟動 SQL Server Management Studio。Start SQL Server Management Studio.

  3. 以滑鼠右鍵按一下您要設為唯讀的內容資料庫,然後按一下 [內容]*Right-click the content database that you want to make read-only, and then click *Properties.

  4. 選取 [選項]**** 頁面,然後在 [其他選項]**** 清單中,捲動至 [狀態]**** 區段。Select the Options page, and, in the Other options list, scroll to the State section.

  5. 在 [資料庫唯讀]**** 列中,按一下 [False]**** 旁的箭頭,選取 [True]*,然後按一下 [確定]In the **Database Read-Only* row, click the arrow next to False, select True, and then click OK.

  6. 對所有其他內容資料庫重複此程序。Repeat for all other content databases.

    注意

    在設定資料庫為唯讀後,將會停止所有連線 (但設定唯讀標幟的連線除外)。設定了唯讀標幟後,將會啟用其他連線。When a database is set to read-only, all connections except the one that is setting the read-only flag are stopped. After the read-only flag is set, other connections are enabled.

如果與唯讀內容資料庫相關聯的網站集合鎖定狀態以前為 [無]、[禁止新增] 或 [唯讀],則網站集合會自動設定為唯讀。如果網站集合的鎖定狀態以前為 [禁止存取],則在資料庫鎖定狀態變更時,會仍然保持 [禁止存取] 狀態。The site collection that is associated with a read-only content database is automatically set to read-only if the locking status of the site collection was previously None, No Additions, or Read-Only. If the locking status of the site collection was previously No Access, it remains No Access when the database locking status is changed.

設定服務應用程式資料庫為唯讀Set service application databases to read-only

可以將任何服務應用程式資料庫設定為唯讀。但是,若將某些服務應用程式的資料庫 (例如與 Search 及 Project Server 相關聯的那些資料庫) 設定為唯讀,則部分應用程式將無法作用。It is possible to set any service application database to read-only. However, some service applications do not function when their databases are set to read-only, such as those that are associated with Search and Project Server.

使用 SQL Server 將服務應用程式資料庫設為唯讀To set service application databases to read-only by using SQL Server

  1. 確認執行此程序的使用者帳戶為每個資料庫之 db_owner 固定資料庫角色的成員。Verify that the user account that is performing this procedure is a member of the db_owner fixed database role in each database.

  2. 啟動 SQL Server Management Studio。Start SQL Server Management Studio.

  3. 以滑鼠右鍵按一下您要設為唯讀的資料庫,然後按一下 [內容]*Right-click the database that you want to make read-only, and then click *Properties.

  4. 選取 [選項]**** 頁面,然後在 [其他選項]**** 清單中,捲動至 [狀態]**** 區段。Select the Options page, and, in the Other options list, scroll to the State section.

  5. 在 [資料庫唯讀]**** 列中,按一下 [False]**** 旁的箭頭,選取 [True]*,然後按一下 [確定]In the **Database Read-Only* row, click the arrow next to False, select True, and then click OK.

  6. 根據需要對其他服務應用程式資料庫重複此作業。Repeat for other service application databases as appropriate.

    注意

    在設定資料庫為唯讀後,將會停止所有連線 (但設定唯讀標幟的連線除外)。設定了唯讀標幟後,將會啟用其他連線。When a database is set to read-only, all connections except the one that is setting the read-only flag are stopped. After the read-only flag is set, other connections are enabled.