Sql-Server-2016
是時候從可用性組中刪除數據庫了嗎?哪個?
在修補作為可用性組一部分的我的一台伺服器時,作為輔助伺服器,我遇到了一些問題 - 真正的問題是可用性組中的一個虛擬伺服器的主機 - 短暫的磁碟空間不足一兩分鐘。
對於這個問題,問題是什麼並不重要。
事實是:
- 我在可用性組上有 2 台機器,失去了輔助機器。
- 可用性組參與複製,我收到以下錯誤消息:
複製的事務正在等待下一次日誌備份或鏡像夥伴趕上
通過啟動以下跟踪標誌解決了這個問題:
DBCC TRACEON(1448,-1)
- 我找到了一些關於我的可用性組的資訊,根據以下腳本,我可以看到一台伺服器已關閉:
從 sys.dm_hadr_cluster_members 中選擇 *
SELECT gs.primary_replica as 'Primary Server', DB_NAME(dd.database_id) as 'Database Name', secondary_recovery_health_desc as 'Secondary Server Health Status', synchronization_state_desc as 'Synchronization State', database_state_desc as 'Database State', --suspend_reason_desc as 'Suspended Reason', --last_sent_time as 'Last Data Send Time', --last_received_time as 'Last Data Received TIme', --last_hardened_time as 'Last Hardened Time', --last_redone_time as 'Last Redone Time', --log_send_queue_size as 'Log Send Queue Size', --log_send_rate as 'Log Send Rate', --redo_queue_size as 'Redo Queue Size', --redo_rate as 'Rate of Redo', --filestream_send_rate as 'Filestream Send Rate', last_commit_time as 'Last Commit Time', low_water_mark_for_ghosts as 'Low Water Mark for Ghosts' FROM sys.dm_hadr_availability_group_states as gs left outer JOIN sys.dm_hadr_database_replica_states as dd ON gs.group_id = dd.group_id ORDER BY gs.primary_replica DESC, DB_NAME(dd.database_id) DESC
這個問題上的 always On 腳本也沒有告訴我太多
問題:
我在事務日誌中落後了多少,趕上了一個永遠不會回來的副本?
我需要資訊來解決這個問題:
我應該從可用性組中刪除數據庫嗎?
或者我應該建構一個新伺服器,將其添加到可用性組,等待日誌趕上?
在這種情況下,我決定從可用性組中刪除數據庫。為此,我使用了以下腳本:
-- https://blog.pythian.com/list-of-sql-server-databases-in-an-availability-group/ -- How do we know that this instance is part of Availability Group(s): SELECT AG.name AS [Name], ISNULL(agstates.primary_replica, '') AS [PrimaryReplicaServerName], ISNULL(arstates.role, 3) AS [LocalReplicaRole] FROM master.sys.availability_groups AS AG LEFT OUTER JOIN master.sys.dm_hadr_availability_group_states as agstates ON AG.group_id = agstates.group_id INNER JOIN master.sys.availability_replicas AS AR ON AG.group_id = AR.group_id INNER JOIN master.sys.dm_hadr_availability_replica_states AS arstates ON AR.replica_id = arstates.replica_id AND arstates.is_local = 1 ORDER BY [Name] ASC -- https://blog.pythian.com/list-of-sql-server-databases-in-an-availability-group/ -- How do we get some information about the databases in the Availability Group: SELECT AG.name AS [AvailabilityGroupName], ISNULL(agstates.primary_replica, '') AS [PrimaryReplicaServerName], ISNULL(arstates.role, 3) AS [LocalReplicaRole], dbcs.database_name AS [DatabaseName], ISNULL(dbrs.synchronization_state, 0) AS [SynchronizationState], ISNULL(dbrs.is_suspended, 0) AS [IsSuspended], ISNULL(dbcs.is_database_joined, 0) AS [IsJoined], remove_database='USE [master]' + char(13) + 'ALTER AVAILABILITY GROUP ' + quotename(AG.name ) + char(13) + 'REMOVE DATABASE ' + quotename(dbcs.database_name) + char(13) FROM master.sys.availability_groups AS AG LEFT OUTER JOIN master.sys.dm_hadr_availability_group_states as agstates ON AG.group_id = agstates.group_id INNER JOIN master.sys.availability_replicas AS AR ON AG.group_id = AR.group_id INNER JOIN master.sys.dm_hadr_availability_replica_states AS arstates ON AR.replica_id = arstates.replica_id AND arstates.is_local = 1 INNER JOIN master.sys.dm_hadr_database_replica_cluster_states AS dbcs ON arstates.replica_id = dbcs.replica_id LEFT OUTER JOIN master.sys.dm_hadr_database_replica_states AS dbrs ON dbcs.replica_id = dbrs.replica_id AND dbcs.group_database_id = dbrs.group_database_id ORDER BY AG.name ASC, dbcs.database_name