国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 數(shù)據(jù)庫(kù) > SQL Server > 正文

教你如何縮小SQL Server數(shù)據(jù)庫(kù)日志文件

2024-08-31 00:49:47
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

問(wèn)題:數(shù)據(jù)庫(kù)實(shí)際大小為600mb, 日志文件實(shí)際大小為33mb, 但日志文件占用空間為2.8gb!試了多種方式,shirnk database, truncate log file, 都沒(méi)辦法將文件縮小。無(wú)論如何,這應(yīng)該算sql server的一個(gè)bug吧。

解決方法:

后來(lái)找到下面的代碼,就可以將日志文件縮小到自己想要的大小了。把代碼copy到查詢(xún)分析器里,,然后修改其中的3個(gè)參數(shù)(數(shù)據(jù)庫(kù)名,日志文件名,和目標(biāo)日志文件的大小),運(yùn)行即可。

以下為引用的內(nèi)容:

-----
set nocount on
declare @logicalfilename sysname,
        @maxminutes int,
        @newsize int


use     marias           
 -- 要操作的數(shù)據(jù)庫(kù)名
select  @logicalfilename = 'marias_log' 
-- 日志文件名
@maxminutes = 10,              
-- limit on time allowed to wrap log.
        @newsize = 100                 
-- 你想設(shè)定的日志文件的大小(m)

-- setup / initialize
declare @originalsize int
select @originalsize = size
  from sysfiles
  where name = @logicalfilename
select 'original size of ' + db_name() + ' log is ' +
        convert(varchar(30),@originalsize) + ' 8k pages or ' +
        convert(varchar(30),(@originalsize*8/1024)) + 'mb'
  from sysfiles
  where name = @logicalfilename
create table dummytrans
  (dummycolumn char (8000) not null)


declare @counter   int,
        @starttime datetime,
        @trunclog  varchar(255)
select  @starttime = getdate(),
        @trunclog = 'backup log '
+ db_name() + ' with truncate_only'

dbcc shrinkfile (@logicalfilename, @newsize)
exec (@trunclog)
-- wrap the log if necessary.
while     @maxminutes > datediff
(mi, @starttime, getdate()) -- time has not expired
      and @originalsize = (select size
from sysfiles where name = @logicalfilename) 
      and (@originalsize * 8 /1024) > @newsize 
  begin -- outer loop.
    select @counter = 0
    while  ((@counter < @originalsize / 16)
 and (@counter < 50000))
      begin -- update
        insert dummytrans values ('fill log') 
        delete dummytrans
        select @counter = @counter + 1
      end  
    exec (@trunclog) 
  end  
select 'final size of ' + db_name() + ' log is ' +
        convert(varchar(30),size) + ' 8k pages or ' +
        convert(varchar(30),(size*8/1024)) + 'mb'
  from sysfiles
  where name = @logicalfilename
drop table dummytrans
set nocount off

發(fā)表評(píng)論 共有條評(píng)論
用戶(hù)名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 乌拉特后旗| 西乌珠穆沁旗| 威信县| 盐津县| 高淳县| 赤壁市| 年辖:市辖区| 雅江县| 江北区| 晋中市| 南部县| 广东省| 安图县| 德州市| 桃源县| 宣恩县| 即墨市| 潢川县| 宜城市| 鄂伦春自治旗| 遂宁市| 当涂县| 道孚县| 化隆| 乌什县| 咸宁市| 黑水县| 宁蒗| 黄陵县| 常宁市| 和平县| 竹山县| 黔东| 于田县| 房山区| 加查县| 建阳市| 广水市| 衡阳市| 东方市| 西林县|