制作了数据库的副本,但副本的大小更大

时间:2011-06-27 19:48:55

标签: sql-server-2008

我右键单击了数据库 - > tasks - >复制数据库并创建副本。

我注意到副本的大小(mb)大约两倍。为什么?

2 个答案:

答案 0 :(得分:2)

我猜测MDF将是相似的(相同数据),但由于记录数据量,LDF更大。按数据库运行:

SELECT size/128.0 AS MB, name, physical_name FROM sys.database_files

另外,恢复模型是什么?如果新的是FULL,则LDF将增长,直到发生日志备份(我怀疑“旧的”已被截断等),请检查:

SELECT recovery_model_desc, name FROM sys.databases

答案 1 :(得分:0)

我尝试使用此向导,数据和日志文件的大小完全相同。我想知道源数据库自复制后是否已缩小(可能是由后台作业,维护计划或其他用户完成),或者您使用的是任何压缩产品(在SQL内或Windows中)。此外,如果您可以确定哪些物体占用更多空间,它可能会对事物有所了解。请注意两个注释位置,您必须对旧数据库名称和新数据库名称进行硬编码。

DECLARE 
    @old_db SYSNAME = N'old_db_name',
    @new_db SYSNAME = N'new_db_name';

WITH [old] AS
(
    SELECT 
        t = OBJECT_SCHEMA_NAME([object_id], DB_ID(@old_db)) 
            + '.' + OBJECT_NAME([object_id], DB_ID(@old_db)),
        r = row_count,
        s = used_page_count
    FROM old_db_name.sys.dm_db_partition_stats -- change this line!
    WHERE index_id IN (0,1)
    AND OBJECT_SCHEMA_NAME([object_id], DB_ID(@old_db)) <> 'sys'
),
[new] AS
(
    SELECT 
        t = OBJECT_SCHEMA_NAME([object_id], DB_ID(@new_db)) 
            + '.' + OBJECT_NAME([object_id], DB_ID(@new_db)),
        r = row_count,
        s = used_page_count
    FROM new_db_name.sys.dm_db_partition_stats -- change this line!
    WHERE index_id IN (0,1)
    AND OBJECT_SCHEMA_NAME([object_id], DB_ID(@new_db)) <> 'sys'
)
SELECT
    [old].t, [new].t,
    [old_rc] = SUM([old].r), [old_kb] = SUM([old].s*8),
    [new_rc] = SUM([new].r), [new_kb] = SUM([new].s*8),
    spot = CASE WHEN COALESCE(SUM([old].r), -1) <> COALESCE(SUM([new].r), -1)
        OR COALESCE(SUM([old].s*8), -1) <> COALESCE(SUM([new].s*8), -1) THEN
            ' <----------' ELSE '' END
FROM
    [old] FULL OUTER JOIN [new]
    ON [old].t = [new].t
GROUP BY [old].t, [new].t
ORDER BY [old].t, [new].t;