小编给大家分享一下Sqlserver镜像切换操作并检查镜像同步情况的示例分析,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!
主节点上:
ALTER DATABASE [dbname] SET SAFETY FULL
ALTER DATABASE [dbname] SET PARTN免费主机域名ER FAILOVER
切换完毕到从节点,新的主节点上:
ALTER DATABASE [dbname] SET SAFETY OFF
检查镜像同步情况:
SET NOCOUNT ON
DECLARE @db_name varchar(100)
DECLARE @dblist TABLE([db_name] varchar(100))
DECLARE @a TABLE(
database_name SYSNAME
,[role] INT
,mirroring_state INT
,witness_status INT
,log免费主机域名_generation_rate INT
,unsent_log INT
,send_rate INT
,unrestored_log INT
,recovery_rate INT
,transaction_delay INT
,transactions_per_sec INT
,average_delay INT
,time_recorded DATETIME
,time_behind DATETIME
,local_time DATETIME
)
–导出镜像数据库名列表
insert into @dblist
select a.name
from sys.sysdatabases a (nolock)
join sys.database_mirroring b (nolock) on a.dbid=b.database_id
where mirroring_guid is not null
EXEC msdb.dbo.sp_dbmmonitorupdate
EXEC msdb.dbo.sp_dbmmonitorupdate –若server是初次执行这个sp,可能不会产生数据,所以需要再执行一次
–每个镜像数据库的相关记录通过循环全部导入表变量
while exists(select * from @dblist)
begin
set @db_name=(select top 1 [db_name] from @dblist)
delete @dblist where [db_name]=@db_name
INSERT INTO @a
EXEC msdb.dbo.sp_dbmmonitorresults @db_name
,0 –返回行数:-1行;-前条;-最近两小时行数;
,0 –0表示不调用sp_dbmmonitorupdate,表示调用
end
SELECT database_name
,CASE [role] WHEN 1 THEN ‘主体数据库’
WHEN 2 THEN ‘镜像数据库’
ELSE NULL END AS ‘db_role’
,CASE mirroring_state WHEN 0 THEN ‘已挂起’
WHEN 1 THEN ‘已断开’
WHEN 2 THEN ‘正在同步’
WHEN 3 THEN ‘挂起故障转移’
WHEN 4 THEN ‘已同步’
ELSE NULL END AS mirroring_state
,CASE witness_status WHEN 0 THEN ‘未知’
WHEN 1 THEN ‘已连接’
WHEN 2 THEN ‘已断开’
ELSE NULL END AS witness_status
,unsent_log AS ‘unsent_log[kb]’
,unrestored_log AS ‘unrestored_log[kb]’
,send_rate AS ‘send_rate[kb/s]’
,recovery_rate AS ‘recovery_rate[kb/s]’
,transaction_delay AS ‘transaction_delay/ms’
,transactions_per_sec
,average_delay
,time_recorded
,time_behind
,local_time
FROM @a
以上是“Sqlserver镜像切换操作并检查镜像同步情况的示例分析”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注云技术行业资讯频道!
这篇文章主要介绍“分析数据库都做了哪些操作”,在日常操作中,相信很多人在分析数据库都做了哪些操作问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”分析数据库都做了哪些操作”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!由于不将数据…