表的大小一般指表的行數(shù),占用硬盤空間大小就比較復雜了,可以有以下幾個參數(shù):

站在用戶的角度思考問題,與客戶深入溝通,找到武鳴網(wǎng)站設計與武鳴網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗,讓設計與互聯(lián)網(wǎng)技術結合,創(chuàng)造個性化、用戶體驗好的作品,建站類型包括:做網(wǎng)站、網(wǎng)站制作、企業(yè)官網(wǎng)、英文網(wǎng)站、手機端網(wǎng)站、網(wǎng)站推廣、域名注冊、雅安服務器托管、企業(yè)郵箱。業(yè)務覆蓋武鳴地區(qū)。
分配空間,數(shù)據(jù)占用空間及索引占用空間。
執(zhí)行
EXEC alltablecount
即可顯示當前數(shù)據(jù)庫所有表資源占用情況。
執(zhí)行前,請前建立以下表,和兩個存儲過程:
1、先建立表:HY_SPACE
CREATE TABLE [HY_SPACE] (
[name] [nvarchar] (128) COLLATE Chinese_PRC_CI_AS NULL ,
[rows] [char] (11) COLLATE Chinese_PRC_CI_AS NULL ,
[reserved] [varchar] (18) COLLATE Chinese_PRC_CI_AS NULL ,
[data] [varchar] (18) COLLATE Chinese_PRC_CI_AS NULL ,
[index_size] [varchar] (18) COLLATE Chinese_PRC_CI_AS NULL ,
[unused] [varchar] (18) COLLATE Chinese_PRC_CI_AS NULL
) ON [PRIMARY]
GO
2、建立統(tǒng)計存儲過程:
create procedure HYspaceused
@objname nvarchar(776) = null,
@updateusage varchar(5) = false
as
declare @idint
declare @typecharacter(2)
declare@pagesint
declare @dbname sysname
declare @dbsize dec(15,0)
declare @logsize dec(15)
declare @bytesperpagedec(15,0)
declare @pagesperMBdec(15,0)
create table #spt_space
(
rowsint null,
reserveddec(15) null,
datadec(15) null,
indexpdec(15) null,
unuseddec(15) null
)
if @updateusage is not null
begin
select @updateusage=lower(@updateusage)
if @updateusage not in ('true','false')
begin
raiserror(15143,-1,-1,@updateusage)
return(1)
end
end
if @objname IS NOT NULL
begin
select @dbname = parsename(@objname, 3)
if @dbname is not null and @dbname db_name()
begin
raiserror(15250,-1,-1)
return (1)
end
if @dbname is null
select @dbname = db_name()
select @id = null
select @id = id, @type = xtype
from sysobjects
where id = object_id(@objname)
if @id is null
begin
raiserror(15009,-1,-1,@objname,@dbname)
return (1)
end
if not exists (select * from sysindexes
where @id = id and indid 2)
if @type in ('P ','D ','R ','TR','C ','RF')
begin
raiserror(15234,-1,-1)
return (1)
end
else if @type = 'V '
begin
raiserror(15235,-1,-1)
return (1)
end
else if @type in ('PK','UQ')
begin
raiserror(15064,-1,-1)
return (1)
end
else if @type = 'F '
begin
raiserror(15275,-1,-1)
return (1)
end
end
if @updateusage = 'true'
begin
if @objname is null
dbcc updateusage(0) with no_infomsgs
else
dbcc updateusage(0,@objname) with no_infomsgs
print ' '
end
set nocount on
if @id is null
begin
select @dbsize = sum(convert(dec(15),size))
from dbo.sysfiles
where (status 64 = 0)
select @logsize = sum(convert(dec(15),size))
from dbo.sysfiles
where (status 64 0)
select @bytesperpage = low
from master.dbo.spt_values
where number = 1
and type = 'E'
select @pagesperMB = 1048576 / @bytesperpage
select database_name = db_name(),
database_size =
ltrim(str((@dbsize + @logsize) / @pagesperMB,15,2) + ' MB'),
'unallocated space' =
ltrim(str((@dbsize -
(select sum(convert(dec(15),reserved))
from sysindexes
where indid in (0, 1, 255)
)) / @pagesperMB,15,2)+ ' MB')
print ' '
insert into #spt_space (reserved)
select sum(convert(dec(15),reserved))
from sysindexes
where indid in (0, 1, 255)
select @pages = sum(convert(dec(15),dpages))
from sysindexes
where indid 2
select @pages = @pages + isnull(sum(convert(dec(15),used)), 0)
from sysindexes
where indid = 255
update #spt_space
set data = @pages
update #spt_space
set indexp = (select sum(convert(dec(15),used))
from sysindexes
where indid in (0, 1, 255))
- data
update #spt_space
set unused = reserved
- (select sum(convert(dec(15),used))
from sysindexes
where indid in (0, 1, 255))
select reserved = ltrim(str(reserved * d.low / 1024.,15,0) +
' ' + 'KB'),
data = ltrim(str(data * d.low / 1024.,15,0) +
' ' + 'KB'),
index_size = ltrim(str(indexp * d.low / 1024.,15,0) +
' ' + 'KB'),
unused = ltrim(str(unused * d.low / 1024.,15,0) +
' ' + 'KB')
from #spt_space, master.dbo.spt_values d
where d.number = 1
and d.type = 'E'
end
else
begin
insert into #spt_space (reserved)
select sum(reserved)
from sysindexes
where indid in (0, 1, 255)
and id = @id
select @pages = sum(dpages)
from sysindexes
where indid 2
and id = @id
select @pages = @pages + isnull(sum(used), 0)
from sysindexes
where indid = 255
and id = @id
update #spt_space
set data = @pages
update #spt_space
set indexp = (select sum(used)
from sysindexes
where indid in (0, 1, 255)
and id = @id)
- data
update #spt_space
set unused = reserved
- (select sum(used)
from sysindexes
where indid in (0, 1, 255)
and id = @id)
update #spt_space
set rows = i.rows
from sysindexes i
where i.indid 2
and i.id = @id
INSERT INTO HY_SPACE
select name = object_name(@id),
rows = convert(char(11), rows),
reserved = ltrim(str(reserved * d.low / 1024.,15,0) +
' ' + 'KB'),
data = ltrim(str(data * d.low / 1024.,15,0) +
' ' + 'KB'),
index_size = ltrim(str(indexp * d.low / 1024.,15,0) +
' ' + 'KB'),
unused = ltrim(str(unused * d.low / 1024.,15,0) +
' ' + 'KB')
from #spt_space, master.dbo.spt_values d
where d.number = 1
and d.type = 'E'
RETURN
end
return (0)
GO
3、主存儲過程
create procedure alltablecount as
declare @name varchar(100)
TRUNCATE TABLE HY_SPACE
declare tablecur cursor for select name from sysobjects where xtype= 'u '
create table #tablecount(tablename varchar(100),reccount int)
open tablecur
fetch next from tablecur into @name
while @@fetch_status!=-1
begin
exec ('insert into #tablecount select tablename='''+@name+''',reccount=count(1) from '+@name+' ')
EXEC HYspaceused @NAME
fetch next from tablecur into @name
end
close tablecur
deallocate tablecur
select * from #tablecount order by reccount desc
select * from HY_SPACE
GO
SQL
server
磁盤占用率過高怎么解決
sql
數(shù)據(jù)庫占用磁盤IO讀寫過高,
原因:可能是插入數(shù)據(jù)頻繁,并且存在的索引太多
所以建議清除不用的索引
或是對數(shù)據(jù)庫進行重建索引
也可以叫DBCC
操作
這些占用著的內(nèi)存,其實是數(shù)據(jù)緩存.如果內(nèi)存夠大,那就別刪了.刪除后會減低性能和效率.
如果一定要刪,實質上是通過最大值開限制內(nèi)存開銷:
鼠標右鍵實例--屬性--內(nèi)存
設定最大內(nèi)存 即可
SQL Server對服務器內(nèi)存的使用策略是用多少內(nèi)存就占用多少內(nèi)存,只用在服務器內(nèi)存不足時,才會釋放一點占用的內(nèi)存,所以SQL Server 服務器內(nèi)存往往會占用很高。
Sql Server運行時候的緩存:
1.數(shù)據(jù)緩存:執(zhí)行個查詢語句,Sql Server會將相關的數(shù)據(jù)頁(Sql Server操作的數(shù)據(jù)都是以頁為單位的)加載到內(nèi)存中來, 下一次如果再次請求此頁的數(shù)據(jù)的時候,就無需讀取磁盤了,大大提高了速度。
2.執(zhí)行命令緩存:在執(zhí)行存儲過程,自定函數(shù)時,Sql Server需要先二進制編譯再運行,編譯后的結果也會緩存起來, 再次調用時就無需再次編譯。
清除緩存的命令(直接執(zhí)行第四個命令清除所有緩存):
DBCC FREEPROCCACHE --清除存儲過程相關的緩存
DBCC FREESESSIONCACHE --會話緩存
DBCC FREESYSTEMCACHE('All') --系統(tǒng)緩存
DBCC DROPCLEANBUFFERS --所有緩存
注意:清除了緩存,不會釋放SQL Server所占用的內(nèi)存,所以需要通過修改SQL Server內(nèi)存或重啟SQL Server服務器來釋放內(nèi)存。
修改SQL Server內(nèi)存:
優(yōu)化:使用以下語句查找出什么語句占內(nèi)存最高,針對占內(nèi)存高的語句進行優(yōu)化
SELECT SS.SUM_EXECUTION_COUNT,
T.TEXT,
SS.SUM_TOTAL_ELAPSED_TIME AS '總和時間',
SS.SUM_TOTAL_WORKER_TIME AS '執(zhí)行耗時',
SS.SUM_TOTAL_LOGICAL_READS AS '總和邏輯讀數(shù)',
SS.SUM_TOTAL_LOGICAL_WRITES AS '總和邏輯寫'
FROM (SELECT S.PLAN_HANDLE,
SUM(S.EXECUTION_COUNT)SUM_EXECUTION_COUNT,
SUM(S.TOTAL_ELAPSED_TIME)SUM_TOTAL_ELAPSED_TIME,
SUM(S.TOTAL_WORKER_TIME)SUM_TOTAL_WORKER_TIME,
SUM(S.TOTAL_LOGICAL_READS)SUM_TOTAL_LOGICAL_READS,
SUM(S.TOTAL_LOGICAL_WRITES)SUM_TOTAL_LOGICAL_WRITES
FROM SYS.DM_EXEC_QUERY_STATS S
GROUP BY S.PLAN_HANDLE
) AS SS
CROSS APPLY SYS.dm_exec_sql_text(SS.PLAN_HANDLE)T
ORDER BY SUM_TOTAL_LOGICAL_READS DESC
轉自:
時間充足就斷線停止寫入數(shù)據(jù)庫,做個全備份。
刪除數(shù)據(jù)庫,刪除數(shù)據(jù)庫文件。
整理下磁盤。
重建同名數(shù)據(jù)庫,恢復數(shù)據(jù)庫。
這時候的空間是最緊湊的,可以試試建聚集索引。
最根本的方法是加硬盤,可能你的數(shù)據(jù)操作規(guī)律就是會產(chǎn)生很多碎片的,必須要有雙倍的空間才行。
簡單回答:
因為它的設計是為了提供最高效快速的數(shù)據(jù)服務。它會盡可能利用(占用)電腦的內(nèi)存、CPU資源來做數(shù)據(jù)服務。
1、SQL Server是數(shù)據(jù)庫系統(tǒng),它的設計目標就是以當前設備硬件的最大的資源來為其它或自已提供最高效快速的數(shù)據(jù)查詢、存儲、運算支持。
2、所以,它在運行過程中,默認情況下,會占用較大的內(nèi)存,會用較高的CPU性能,因為它可不管你的想法是什么,它的想法就是時刻準備著,查詢、存儲、運算數(shù)據(jù)。它會將它認為最常用的數(shù)據(jù)調入內(nèi)存中,以加快查詢速度,會不停的想法兒優(yōu)化算法,優(yōu)化物理存儲位置,以做到盡可能的最快的速度提供操作者想要的數(shù)據(jù)。
3、SQL Server對內(nèi)存的占用是可以調定與調整的,在起動 “企業(yè)管理器”或“SQL Server Management Studio”在里面點擊樹狀結構的根目錄,點屬性,到里面相關的參數(shù)處可設定數(shù)據(jù)庫的內(nèi)存占用。提示的是,過小的內(nèi)存占用會引發(fā)SQL Server的運行故障。
4、個人電腦,安裝它用于調試、編程學習、或某些特定軟件數(shù)據(jù)支持,不用時,可以去控制面版的“服務”中,關閉“SQLServer”相關服務,即可讓它不再占用系統(tǒng)資源,但這并不是太方便,而且只適用于對電腦比較熟悉的朋友。
文章題目:sqlserver占硬盤,sql server內(nèi)存占用高解決辦法
分享URL:http://chinadenli.net/article15/dsihedi.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供軟件開發(fā)、網(wǎng)站制作、小程序開發(fā)、Google、網(wǎng)站導航、動態(tài)網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)