AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / dba / 问题 / 49615
Accepted
Jeremy Holovacs
Jeremy Holovacs
Asked: 2013-09-11 08:47:53 +0800 CST2013-09-11 08:47:53 +0800 CST 2013-09-11 08:47:53 +0800 CST

无法缩小事务日志 [重复]

  • 772
这个问题在这里已经有了答案:
为什么事务日志不断增长或空间不足? (4 个回答)
7年前关闭。

这里有点让人头疼。

我有一个数据少于 1GB 的数据库,但有一个 40GB 的日志文件。事务日志每天备份,这个数据库上没有很多活动;大约每周一次,它会记录新的工资单信息,然后将这些数据重复用于报告目的。数据库设置为自动收缩。

运行sp_spaceused @updateusage = true产生以下信息:

database_name   database_size   unallocated space
PayrollImports  39412.06 MB 105.00 MB

reserved    data    index_size  unused
321728 KB   278640 KB   42816 KB    272 KB

运行DBCC shrinkfile (N'PayrollImports_log', 1 , notruncate)产生以下结果:

DbId    FileId  CurrentSize MinimumSize UsedPages   EstimatedPages
19  2   4991088 3456    4991088 3456

UsedPages... the和 the之间的差异EstimatedPages令人费解,但我继续DBCC shrinkfile (N'PayrollImports_log', 1 , truncateonly)并得到:

DbId    FileId  CurrentSize MinimumSize UsedPages   EstimatedPages
19  2   4991088 3456    4991088 3456

在这一点上什么都没有改变。日志文件仍然是 40GB。所以我想,也许我有一些公开交易。运行dbcc opentran应验证:

No active open transactions.
DBCC execution completed. If DBCC printed error messages, contact your system administrator.

废话。好吧,也许我的索引是零散的。我将对它们进行碎片整理sp_msForEachTable 'DBCC indexdefrag([PayrollImports], ''?'')'并尝试再次缩小:

DbId    FileId  CurrentSize MinimumSize UsedPages   EstimatedPages
19  2   4991088 3456    4991088 3456

仍然没有任何改变。好的,我用 重新索引怎么样sp_msForEachTable 'DBCC dbreindex([?])'?

DBCC execution completed. If DBCC printed error messages, contact your system administrator.
DBCC execution completed. If DBCC printed error messages, contact your system administrator.
DBCC execution completed. If DBCC printed error messages, contact your system administrator.
DBCC execution completed. If DBCC printed error messages, contact your system administrator.
DBCC execution completed. If DBCC printed error messages, contact your system administrator.
DBCC execution completed. If DBCC printed error messages, contact your system administrator.
DBCC execution completed. If DBCC printed error messages, contact your system administrator.
DBCC execution completed. If DBCC printed error messages, contact your system administrator.
DBCC execution completed. If DBCC printed error messages, contact your system administrator.
DBCC execution completed. If DBCC printed error messages, contact your system administrator.
DBCC execution completed. If DBCC printed error messages, contact your system administrator.

...现在我们得到:

DbId    FileId  CurrentSize MinimumSize UsedPages   EstimatedPages
19  2   4991088 3456    4991088 3456

没变。好吧,怎么样sp_msForEachTable 'ALTER INDEX ALL ON [PayrollImports].[?] REBUILD WITH (FILLFACTOR = 10)'?

立即,这失败了:

Cannot find the object "(One of my tables)" because it does not exist or you do not have permissions.

嗯?它在那里,好的。我做了一个select top 10 * from (My table),它空了。嗯,这根本不对。这是一个应该有超过 200 行的查找表。这可能是数据损坏问题吗?我从我的开发环境中收集数据,重新插入。

但我没有想法。我不能缩小这个东西。我还能尝试什么?为什么我的 UsedPages 比我的 EstimatedPages 高得难以置信?这里发生了什么?

sql-server sql-server-2005
  • 1 1 个回答
  • 1785 Views

1 个回答

  • Voted
  1. Best Answer
    Mike Fal
    2013-09-11T09:09:05+08:002013-09-11T09:09:05+08:00

    DBCC LOGINFO在数据库的上下文中检查您的输出。这将向您显示日志文件中所有 VLF 的状态。您的收缩操作不会将日志文件减少到最后一个活动文件(状态=2)之后。由于 VLF 以顺序、循环方式使用,因此您需要运行事务日志备份足够多次,直到您的活动 VLF 位于文件中您想要收缩到的物理点。

    虽然您说数据库不是很活跃,但每天一次的事务日志备份似乎非常罕见,并且根据针对该数据库运行的事务类型,可能有助于该数据库的持续增长。我建议至少每小时运行一次日志备份。如果您不需要在数据库中进行这种恢复,而只需要恢复到过去 24 小时内的某个时间,我建议您将数据库转换为SIMPLE模式并每天进行一次完整备份。

    Mike Walsh在这里提供了详细的解释。

    您的重新索引对实际缩小或允许文件缩小几乎没有作用,实际上可能会阻碍它。这是因为重新索引会在您的日志中创建额外的事务,这些事务将在您运行日志备份之前一直处于活动状态。

    此外,一些最佳实践建议:

    • 关闭自动收缩。由于多种原因,这是一种非常糟糕的做法。通过启用此“功能”,您可能会为自己制造更多问题。
    • 永远不要使用truncate_only. 这基本上使您的日志无法用于恢复。此时您最好使用SIMPLE模式和完整备份。
    • 5

相关问题

  • 我需要为每种类型的查询使用单独的索引,还是一个多列索引可以工作?

  • 什么时候应该使用唯一约束而不是唯一索引?

  • 死锁的主要原因是什么,可以预防吗?

  • 如何确定是否需要或需要索引

  • 从 SQL Server 2008 降级到 2005

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何让sqlplus的输出出现在一行中?

    • 3 个回答
  • Marko Smith

    选择具有最大日期或最晚日期的日期

    • 3 个回答
  • Marko Smith

    如何列出 PostgreSQL 中的所有模式?

    • 4 个回答
  • Marko Smith

    授予用户对所有表的访问权限

    • 5 个回答
  • Marko Smith

    列出指定表的所有列

    • 5 个回答
  • Marko Smith

    如何在不修改我自己的 tnsnames.ora 的情况下使用 sqlplus 连接到位于另一台主机上的 Oracle 数据库

    • 4 个回答
  • Marko Smith

    你如何mysqldump特定的表?

    • 4 个回答
  • Marko Smith

    使用 psql 列出数据库权限

    • 10 个回答
  • Marko Smith

    如何从 PostgreSQL 中的选择查询中将值插入表中?

    • 4 个回答
  • Marko Smith

    如何使用 psql 列出所有数据库和表?

    • 7 个回答
  • Martin Hope
    Stéphane 如何列出 PostgreSQL 中的所有模式? 2013-04-16 11:19:16 +0800 CST
  • Martin Hope
    Mike Walsh 为什么事务日志不断增长或空间不足? 2012-12-05 18:11:22 +0800 CST
  • Martin Hope
    Stephane Rolland 列出指定表的所有列 2012-08-14 04:44:44 +0800 CST
  • Martin Hope
    haxney MySQL 能否合理地对数十亿行执行查询? 2012-07-03 11:36:13 +0800 CST
  • Martin Hope
    qazwsx 如何监控大型 .sql 文件的导入进度? 2012-05-03 08:54:41 +0800 CST
  • Martin Hope
    markdorison 你如何mysqldump特定的表? 2011-12-17 12:39:37 +0800 CST
  • Martin Hope
    pedrosanta 使用 psql 列出数据库权限 2011-08-04 11:01:21 +0800 CST
  • Martin Hope
    Jonas 如何使用 psql 对 SQL 查询进行计时? 2011-06-04 02:22:54 +0800 CST
  • Martin Hope
    Jonas 如何从 PostgreSQL 中的选择查询中将值插入表中? 2011-05-28 00:33:05 +0800 CST
  • Martin Hope
    Jonas 如何使用 psql 列出所有数据库和表? 2011-02-18 00:45:49 +0800 CST

热门标签

sql-server mysql postgresql sql-server-2014 sql-server-2016 oracle sql-server-2008 database-design query-performance sql-server-2017

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve