简体   繁体   English

SQL Server清理数据库,事务日志?

[英]SQL server cleaning up databases, transaction logs?

I have a SQL Server 2005 database from which I'm removing several large tables to an archive database. 我有一个SQL Server 2005数据库,将从该数据库中删除几个大表到存档数据库。 The original database should shrink considerably. 原始数据库应大大缩小。

To make the archive database, I was going to restore a copy of the original and just remove the current tables from that. 为了创建存档数据库,我将还原原始数据库的副本,然后从中删除当前表。

Is this the best way to go about it? 这是最好的方法吗? What should I do with logs/shrinking to make sure the final sizes are as small as possible? 我该如何处理原木/收缩以确保最终尺寸尽可能小? The archive database may grow a little, but the original continues its normal growth. 存档数据库可能会增长一点,但是原始数据库会继续正常增长。

That seems like an ok way to do it. 这似乎是一种好的方法。 Set the recovery model to simple, then truncate and shrink the log files. 将恢复模型设置为简单,然后截断并收缩日志文件。 This will make it as small as possible. 这将使其尽可能小。

See here for a good way to do it. 请参见此处 ,了解实现此操作的好方法。

Note: This assumes you don't want or need to recover the archive database back to specific points in time. 注意:这是假设您不需要或不需要将存档数据库恢复到特定的时间点。 The reason being that Simple recovery model does not save the transactions in a transaction log. 原因是简单恢复模型不会将事务保存在事务日志中。 So as your archive database changes "a little" (as you said), it won't save the transactions to a log. 因此,随着您的存档数据库“稍有变化”(如您所说),它将不会将事务保存到日志中。

I use this script and this is very useful in developing. 我使用此脚本,这在开发中非常有用。

BACKUP log [CustomerServiceSystem] with truncate_only
go
DBCC SHRINKDATABASE ([CustomerServiceSystem], 10, TRUNCATEONLY)
go
  1. Redesign the db 重新设计数据库
  2. Try one of these sql commands: 请尝试以下sql命令之一:

Or right click into Sql Server Management Studio Object Explorer's database and select Tasks-Shrink. 或右键单击Sql Server Management Studio对象资源管理器的数据库,然后选择“任务收缩”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM