it-swarm.dev

Jak sprawdzić wzrost bazy danych

Chciałbym wiedzieć, jak sprawdzić wzrost całej bazy danych i poszczególnych plików danych.

Co również zasugerować klientowi, jeśli baza danych szybko rośnie?

5
user1032394

Możesz wysłać zapytanie do domyślnego śledzenia, aby uzyskać informacje o ostatnich zdarzeniach wzrostowych.

DECLARE @path nvarchar(260) = (
    SELECT REVERSE(SUBSTRING(REVERSE(path), CHARINDEX('\', REVERSE(path)), 260)) +'log.trc'
    FROM    sys.traces
    WHERE   is_default = 1)

SELECT gt.DatabaseID,
       gt.FileName,
       COUNT(*) AS NumberOfEvents,
       CASE WHEN te.name LIKE'%Grow' THEN 1 ELSE 0 END AS is_growth_event
FROM  sys.fn_trace_gettable(@path, DEFAULT) gt
JOIN sys.trace_events te ON gt.EventClass = te.trace_event_id
WHERE   te.name in ('Data File Auto Grow','Log File Auto Grow','Data File Auto Shrink','Log File Auto Shrink')
GROUP BY gt.DatabaseID,
       gt.FileName,
       te.name

Możesz także użyć Powiadomienia o zdarzeniach , aby otrzymywać powiadomienia w DATA_FILE_AUTO_GROW, LOG_FILE_AUTO_GROW Bez konieczności odpytywania śladu.

6
Martin Smith

Prostym sposobem jest posiadanie tabeli dzienników, aktualizowanej co noc. Wystarczy utworzyć tabelę i zapisany proces, jak poniżej, i mieć zadanie, które uruchamia ją co noc.

Przykład tutaj uruchamia zapytanie o rozmiar dwa razy dla dwóch różnych baz danych na tym samym serwerze. Następnie możesz uzyskać prosty raport przedstawiający trendy wzrostu w czasie i cotygodniowo dla największych i najszybciej rosnących tabel.

Zapisane Proc:

CREATE PROCEDURE [Job].[proc_TableSizeINSERT]

AS
BEGIN

set nocount on

declare @dt smalldatetime
set @dt = getutcdate()

    INSERT INTO [CommunicatorV4DataWarehouse].[dbo].[tb_TableSize]
               ([DB]
               ,[table_id]
               ,[table_name]
               ,[rows]
               ,[total_space_MB]
               ,[data_space_MB]
               ,[index_space_MB]
               ,[unused_space_MB]
               ,[query_date])

    SELECT
            'V4' as DB,
            table_id = [object_id],
            table_name = [name],
            rows = [rowCount],
            total_space_MB = reservedpages * 8/1000,
            data_space_MB = pages * 8/1000,
            index_space_MB = (CASE WHEN usedpages > pages THEN (usedpages - pages) ELSE 0 END) * 8/1000,
            unused_space_MB = (CASE WHEN reservedpages > usedpages THEN (reservedpages - usedpages) ELSE 0 END) * 8/1000,
            query_date = @dt
    from (
        SELECT  o.[Name], [object_id],
            reservedpages = SUM (reserved_page_count),
            usedpages = SUM (used_page_count),
            pages = SUM (
                CASE
                    WHEN (index_id < 2) THEN (in_row_data_page_count + lob_used_page_count + row_overflow_used_page_count)
                    ELSE lob_used_page_count + row_overflow_used_page_count
                END
                ),
            [rowCount] = SUM (
                CASE
                    WHEN (index_id < 2) THEN row_count
                    ELSE 0
                END
                )
        FROM CommunicatorV4.sys.dm_db_partition_stats s inner join CommunicatorV4..sysobjects o on s.[object_id] = o.id
        where type = 'U'
        group by [object_id], o.[name]
    ) DBData


    INSERT INTO [CommunicatorV4DataWarehouse].[dbo].[tb_TableSize]
               ([DB]
               ,[table_id]
               ,[table_name]
               ,[rows]
               ,[total_space_MB]
               ,[data_space_MB]
               ,[index_space_MB]
               ,[unused_space_MB]
               ,[query_date])

    SELECT
            'DW' as DB,
            table_id = [object_id],
            table_name = [name],
            rows = [rowCount],
            total_space_MB = reservedpages * 8/1000,
            data_space_MB = pages * 8/1000,
            index_space_MB = (CASE WHEN usedpages > pages THEN (usedpages - pages) ELSE 0 END) * 8/1000,
            unused_space_MB = (CASE WHEN reservedpages > usedpages THEN (reservedpages - usedpages) ELSE 0 END) * 8/1000,
            query_date = @dt
    from (
        SELECT  o.[Name], [object_id],
            reservedpages = SUM (reserved_page_count),
            usedpages = SUM (used_page_count),
            pages = SUM (
                CASE
                    WHEN (index_id < 2) THEN (in_row_data_page_count + lob_used_page_count + row_overflow_used_page_count)
                    ELSE lob_used_page_count + row_overflow_used_page_count
                END
                ),
            [rowCount] = SUM (
                CASE
                    WHEN (index_id < 2) THEN row_count
                    ELSE 0
                END
                )
        FROM CommunicatorV4DataWarehouse.sys.dm_db_partition_stats s inner join CommunicatorV4DataWarehouse..sysobjects o on s.[object_id] = o.id
        where type = 'U'
        group by [object_id], o.[name]
    ) DBData

--truncate table CommunicatorV4DataWarehouse.dbo.tb_TableSize

END


CREATE TABLE [dbo].[tb_TableSize](
    [Id] [int] IDENTITY(1000,1) NOT NULL,
    [DB] [varchar](2) NOT NULL,
    [table_id] [int] NOT NULL,
    [table_name] [sysname] NOT NULL,
    [rows] [int] NULL,
    [total_space_MB] [int] NULL,
    [data_space_MB] [int] NULL,
    [index_space_MB] [int] NULL,
    [unused_space_MB] [int] NULL,
    [query_date] [smalldatetime] NULL,
 CONSTRAINT [PK_tb_TableSize] PRIMARY KEY CLUSTERED 
(
    [Id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
4
Steve Henderson

Czy tego szukasz? (więcej informacji tutaj: http://msdn.Microsoft.com/en-us/library/ms188233.aspx ):

SELECT 
name AS FileName, 
size*1.0/128 AS FileSizeinMB,
'MaximumSizeinMB' = 
    CASE max_size 
       WHEN 0 THEN 'No growth is allowed.'
       WHEN -1 THEN 'Autogrowth is on.'
       WHEN 268435456 
          THEN 'Log file will grow to a maximum size of 2 TB.'
       ELSE CAST (max_size*1.0/128 AS nvarchar(30))
    END,
growth AS 'GrowthValue',
'GrowthIncrement' = 
    CASE 
       WHEN growth = 0 THEN 'File size is fixed and will not grow.'
       WHEN growth > 0 AND is_percent_growth = 0 
          THEN 'Growth value is in units of 8-KB pages.'
       ELSE 'Growth value is a percentage.'
    END
FROM sys.database_files
1
misha

Jeśli szukasz historycznej wielkości bazy danych i regularnie wykonujesz pełne kopie zapasowe, możesz ją znaleźć, wysyłając zapytanie do sysbackupset w msdb.

Przykład tego można znaleźć tutaj: http://theadeptdba.blogspot.com/2013/01/how-fast-is-my-sql-server-database.html

1
Jeff