Sql Server 做了Mirror镜像,在Principal 服务器上做 日志收缩出现异常。
步骤:
1 建库 testdb
2 建表 tb2 —— char(800) 是为了占数据页
create table tb2(id int,content char(800))
3 插入数据 — 一定要会快速造数据
insert into [dbo].[tb2]SELECT TOP 1000 ROW_NUMBER() OVER(ORDER BY A.object_id) , 'AAA'FROM sys.objects ACROSS JOIN sys.objects BCROSS JOIN(SELECT TOP 11 OBJECT_ID FROM sys.objects) C
4 创建索引
create index ix_tb2on tb2(id)
5 数据库全备份
6 数据库日志备份 ——将日志截断
7再写入数据, 重复step3
8 收缩日志
USE [testdb]GODBCC SHRINKFILE (N'testdb_log' , 0, TRUNCATEONLY)GO
9 报异常如下:——原因:后续的插入操作,VLN 的status是2 活动/可恢复
Cannot shrink log file 2 (testdb_log) because the logical log file located at the end of the file is in use.(1 row affected)DBCC execution completed. If DBCC printed error messages, contact your system administrator.
10 再次日志备份 ,step6
11 再次收缩日志,成功收缩
(1 row affected)DBCC execution completed. If
DBCC printed error messages, contact your system administrator.