Myth: SQL transaction log truncation will make it smaller 误解: SQL事务日志截断将使其变小

The truncation process does not reduce the size of a physical log file

截断过程不会减少物理日志文件的大小

During the truncation process, only the active portion of the online SQL Server transaction log file is scanned. Some parts of the scanned portion are marked as inactive and they will be used as free space to write down new transactions. There isn’t a change in the online transaction log size because the inactive parts remain intact, nothing is deleted or removed

在截断过程中,仅扫描联机SQL Server事务日志文件的活动部分。 扫描部分的某些部分被标记为非活动状态,它们将被用作空闲空间以记下新事务。 联机事务日志大小没有变化,因为不活动的部分保持不变,没有任何内容被删除或删除

Every SQL Server transaction log is made of Virtual Log Files (VLFs). During the truncation process, only the Logical log is scanned. A Logical log is made of active VLFs. A Log Sequence Number (LSN) is used to uniquely identify every transaction in the online transaction log. The MinLSN is the starting point of the oldest active transaction in the online transaction log

每个SQL Server事务日志均由虚拟日志文件(VLF)组成。 在截断过程中,仅扫描逻辑日志。 逻辑日志由活动的VLF组成。 日志序列号(LSN)用于唯一标识联机事务日志中的每个事务。 MinLSN是在线事务日志中最早的活动事务的起点

The online SQL Server transaction log file is circular by internal organization. When logging reaches the end of the transaction log, it starts again from the beginning by overwriting the parts marked as inactive

联机SQL Server事务日志文件由内部组织发出。 当日志记录到达事务日志的末尾时,它会通过覆盖标记为非活动的部分从头开始重新开始

Orange represents the Logical log, blue the truncated part of the online transaction log ready to be overwritten

橙色代表逻辑日志,蓝色代表在线交易日志的截断部分,随时可以覆盖

Myth: Having multiple online SQL Server transaction log files will increase performance

误解:拥有多个联机SQL Server事务日志文件将提高性能

This myth is based on the belief that having multiple online transaction log files will result in parallel writing of transactions into the files and therefore result in performance gain. SQL Server can’t operate with more than one online transaction log file at the time, so any kind of parallel I/O is not possible

这个神话基于这样的信念,即拥有多个联机事务日志文件将导致将事务并行写入文件中,从而提高性能。 SQL Server当时不能使用多个在线事务日志文件,因此任何类型的并行I / O都是不可能的

Having multiple transaction log files is needed only in the situations where the initial SQL Server transaction log can’t record more transactions due to a lack of free space on the disk

仅在初始SQL Server事务日志由于磁盘上的可用空间不足而无法记录更多事务的情况下才需要具有多个事务日志文件

Myth: The SQL Server transaction log won’t grow if the database is in the Simple recovery model

误解:如果数据库处于简单恢复模型中,则SQL Server事务日志将不会增长

However, it happens just in some specific situations – when there is a long running transaction or transaction that creates many changes

但是,它仅在某些特定情况下发生–当长时间运行的事务或产生许多更改的事务

In the Simple recovery model, the online transaction log is cleared automatically. SQL Server automatically reclaims log space to keep space requirements small – but that doesn’t mean it won’t grow. The online transaction log must provide enough information for a database rollback, therefore it must provide enough space for all necessary information. As all transactions must be written into the online transaction log, in case of a large number of changes in a transaction, there might not be enough space in the log, so it must be expanded

在简单恢复模型中,将自动清除联机事务日志。 SQL Server自动回收日志空间以减小空间需求–但这并不意味着它不会增长。 联机事务日志必须为数据库回滚提供足够的信息,因此它必须为所有必要的信息提供足够的空间。 由于所有事务都必须写入在线事务日志中,因此如果事务中发生大量更改,则日志中可能没有足够的空间,因此必须对其进行扩展

Myth: A SQL Server transaction log backup will be the same size as the online transaction log itself

误解: SQL Server事务日志备份的大小将与联机事务日志本身的大小相同

The online transaction log must have enough information to rollback active transactions, so some space is reserved for eventual rollbacks. If a rollback occurs, SQL Server doesn’t want to expand the online transaction log because if the expanding fails, the SQL Server database can become inconsistent or go into the Suspect mode. That’s why the online transaction log has some reserved space and is usually bigger than the SQL Server transaction log backup

联机事务日志必须具有足够的信息来回滚活动事务,因此保留一些空间以供最终回滚。 如果发生回滚,则SQL Server不想扩展联机事务日志,因为如果扩展失败,则SQL Server数据库可能会变得不一致或进入“可疑”模式。 这就是为什么联机事务日志具有一些保留空间并且通常大于SQL Server事务日志备份的原因

Moreover, a transaction log backup contains only the transactions made after the last transaction log backup. If the online transaction log contains the transactions that have already been backed up, they will not be present in the new SQL Server transaction log backup, therefore the transaction log backup will be smaller for that amount of space

此外,事务日志备份仅包含上次事务日志备份之后进行的事务。 如果联机事务日志包含已备份的事务,则它们将不会出现在新SQL Server事务日志备份中,因此,在该空间量下,事务日志备份将较小。

Myth: A full or differential database backup clears the online transaction log

误解:完整或差异数据库备份会清除联机事务日志

The inactive parts of the online SQL Server transaction log are marked for clearing only when a transaction log backup is created

联机SQL Server事务日志的非活动部分被标记为仅在创建事务日志备份时才清除

Full and differential database backups don’t contain much SQL Server transaction log information, only the transactions necessary to recover the database into a consistent state. These transactions are not a backup of the online transaction log, therefore these transactions are not marked for overwriting in the online transaction log

完整和差异数据库备份不包含很多SQL Server事务日志信息,仅包含将数据库恢复到一致状态所需的事务。 这些事务不是联机事务日志的备份,因此这些事务未在联机事务日志中标记为覆盖

Myth: The TRUNCATE TABLE and DROP TABLE commands are not logged into the online transaction log

误解: TRUNCATE TABLE和DROP TABLE命令未登录到在线事务日志中

The exact deleted values are not logged in the online SQL Server transaction log, only the IDs of the pages that held the truncated records are logged. These pages are marked for overwriting in the database data file and the truncated data will be gone for good when the new transactions are written to these pages

确切的删除值不会记录在联机SQL Server事务日志中,仅记录保存了截断记录的页面的ID。 这些页面在数据库数据文件中标记为要覆盖,并且将新事务写入这些页面时,被截断的数据将永久消失

This myth is also based on the fact that these commands take little time to execute, they are almost instantaneous

这个神话还基于以下事实:这些命令几乎不需要执行时间,它们几乎是瞬时的。

Myth: My SQL Server is too busy, I don’t want to make SQL Server transaction log backups

误解:我SQL Server太忙了,我不想进行SQL Server事务日志备份

One of the biggest performance intensive operations in SQL Server is an auto-grow event of the online transaction log file. By not making transaction log backups often enough, the online transaction log will become full and will have to grow. The default growth size is 10%. The busier the database is, the quicker the online transaction log will grow if transaction log backups are not created

SQL Server中最大的性能密集型操作之一是联机事务日志文件的自动增长事件。 由于没有足够频繁地进行事务日志备份,因此联机事务日志将变满并且必须增长。 默认增长大小为10%。 数据库越忙,如果未创建事务日志备份,则在线事务日志将越快增长

Creating a SQL Server transaction log backup doesn’t block the online transaction log, but an auto-growth event does. It can block all activity in the online transaction log

创建SQL Server事务日志备份不会阻止联机事务日志,但是会自动增长事件。 它可以阻止在线交易日志中的所有活动

Myth: A SQL Server transaction log backup isn’t needed for a point in time restore. A full database backup is enough

误解:时间点还原不需要SQL Server事务日志备份。 完整的数据库备份就足够了

This myth comes from using the RESTORE command with STOPAT clause to restore from a full database backup. The STOPAT clause specifies a point in time for the RESTORE LOG command, and it works well when it’s used with a transaction log backup. The fact that it can be used with a full database backup makes you believe that transaction log backups are not needed to recover to a specific point in time

这个神话来自将RESTORE命令和STOPAT子句一起使用来从完整的数据库备份中还原。 STOPAT子句为RESTORE LOG命令指定一个时间点,当它与事务日志备份一起使用时,它可以很好地工作。 它可以与完整的数据库备份一起使用,这一事实使您相信不需要将事务日志备份恢复到特定的时间点

An example of T-SQL code for restoring the AdventureWorks database to December 31st 2013 10:59 PM

用于将AdventureWorks数据库还原到2013年12月31日晚上10:59的T-SQL代码示例

RESTORE DATABASE AdventureWorks FROM DISK = 'D:\AdventureWorks.bak'
WITH NORECOVERY
GO
RESTORE LOG AdventureWorks FROM DISK = 'D:\AdventureWorks.bak'
WITH RECOVERY,
STOPAT = 'Dec 31, 2013 10:59:00 PM'
GO

Although the SQL Server database cannot be restored to a point in time, SQL Server doesn’t clearly identify the problem, and it allows you to use the STOPAT clause without a transaction log backup specified

尽管无法将SQL Server数据库还原到某个时间点,但是SQL Server不能清楚地确定问题所在,它允许您使用STOPAT子句而无需指定事务日志备份

RESTORE DATABASE successfully processed 24436 pages in 5.498 seconds (34.722 MB/sec). This backup set contains records that were logged before the designated point in time. The database is being left in the restoring state so that more roll forward can be performed. RESTORE LOG successfully processed 4 pages in 0.088 seconds (0.338 MB/sec).

RESTORE DATABASE在5.498秒(34.722 MB /秒)中成功处理了24436页。 该备份集包含在指定时间点之前记录的记录。 数据库处于恢复状态,以便可以执行更多前滚。 RESTORE LOG在0.088秒(0.338 MB /秒)内成功处理了4页。

Myth: SQL Server transaction log backups are not needed for successful disaster recovery if the full database backup is taken daily

误解:如果每天进行完整的数据库备份,则无需SQL Server事务日志备份即可成功进行灾难恢复

It also depends on how much data you can lose. If you can afford to lose up to 24 hours of data, then you don’t need transaction log backups and you should use the Simple recovery model

它还取决于您可能丢失多少数据。 如果您有能力丢失多达24小时的数据,则不需要事务日志备份,而应使用简单恢复模型

If the information you can lose is measured in minutes and hours, regular transaction log backups are necessary, as the maximum you will lose is the time between to transaction log backups

如果以分钟和小时为单位衡量您可能丢失的信息,则必须进行定期的事务日志备份,因为您丢失的最大时间是两次事务日志备份之间的时间

Myth: The SQL Server transaction log shrinking will make free space in the online transaction log so I don’t need to create transaction log backups

误解: SQL Server事务日志的缩小将在联机事务日志中释放可用空间,因此我无需创建事务日志备份

The shrink operation is not a good maintenance practice because it doesn’t solve the transaction log size issue permanently. After the initial shrinking, the transaction log will grow again. As the auto-growth event is one of the most intensive SQL Server operations, it should be avoided. The recommended method to keep the size of the online transaction log is to create transaction log backups regularly. Or, switching to the Simple recovery model, if you can tolerate data loss

收缩操作不是良好的维护习惯,因为它不能永久解决事务日志大小问题。 初始收缩后,事务日志将再次增长。 由于自动增长事件是SQL Server最密集的操作之一,因此应避免使用它。 保持联机事务日志大小的建议方法是定期创建事务日志备份。 或者,如果可以忍受数据丢失,则切换到简单恢复模型

翻译自: https://www.sqlshack.com/10-important-sql-server-transaction-log-myths/

10个最重要SQL Server事务日志神话相关推荐

  1. 了解SQL Server事务日志备份和完整备份的日志序列号

    This article explores the SQL Server Transaction log backups and log sequence number (LSN) in combin ...

  2. 什么是SQL Server事务日志中的虚拟日志文件?

    什么是SQL Server事务日志文件? (What is a SQL Server transaction log file?) SQL Server事务日志文件是每个SQL Server数据库的组 ...

  3. SQL Server事务日志备份,截断和缩减操作

    In this article, we will cover SQL Server Transaction log backups, truncate and shrink operations wi ...

  4. SQL Server事务日志管理的阶梯,第5级:在完全恢复模式下管理日志

    SQL Server事务日志管理的阶梯,第5级:在完全恢复模式下管理日志 在本节中,我们将回顾在完全恢复模式下进行日志备份的原因和方法,以及如何使用这些日志备份文件与完整的数据库备份一起执行数据库恢复 ...

  5. SQL Server 事务日志

    https://docs.microsoft.com/en-us/sql/relational-databases/logs/the-transaction-log-sql-server?view=s ...

  6. Sql Server事务日志

    本文导读:SQL Server中的数据库都是由一或多个数据文件以及一或多个事务日志文件组成的.SQL Server事务日志主要是用来记录所有事务对数据库所做的修改,SQL SERVER利用事务日志来确 ...

  7. 如何使用损坏或删除SQL Server事务日志文件重建数据库

    This is the last article, but not the least one, in the SQL Server Transaction Log series. In this s ...

  8. 读取SQL Server事务日志

    介绍 (Introduction) There has always been some debate as to whether or not there are real benefits to ...

  9. SQL Server事务日志体系结构

    This article will cover SQL Server transaction log architecture including file topography, basic ove ...

最新文章

  1. 2020年智能车竞赛暑期工作计划一览表各
  2. java异步处理同步化_java 异步查询转同步多种实现方式:循环等待,CountDownLatch,Spring Even...
  3. k8s与CICD--将drone部署到kubernetes中,实现agent动态收缩
  4. mysql的使用优化问题吗_如何对 mysql 进行优化的问题
  5. 使用 nvm 安装 nodejs 和 npm
  6. jsp 内置对象 登录 cookie + session
  7. SQLServr添加数据列
  8. java中a 和 a_Java中a=a++ 和 a=++a(轉)
  9. java万年历算法_寿星万年历---java算法实现
  10. 计算机操作系统(第四版)课后习题答案(完整版)
  11. #相关系数r值比较(matlab)
  12. anaconda安装完怎么打开_录像机怎么样安装在机柜上,看完就明白
  13. Tomcat端口配置(详细)
  14. General Trainning Strategy in Caffe
  15. sudo rosdep init找不到命令或失败解决办法
  16. CSS揭秘:6.复杂的背景图案(下)
  17. 播放器可以完成:开机自动打开指定网页,自动运行浏览器打开指定的网页。
  18. Solidworks篮球建模
  19. commit your changes or stash them before you can merge 解决方法
  20. 代码详解:手把手教你建立自己的视频分类模型

热门文章

  1. 冯诺依曼体系结构_极简体系结构之一:冯诺依曼体系结构
  2. MFC初步教程(一)
  3. 使用 guard 的正确姿势
  4. AI技术人才成长路线十大方向
  5. php中header用法
  6. JavaScript基础(3)-JS中的面向对象、定时器、BOM、位置信息
  7. python- 属性 静态方法,类方法
  8. 云计算学习(5-1)云平台产品介绍-华为的FusionCloud产品
  9. 网友写的验证码生成方案,可防止绝大多数机械识别。
  10. MongoError: E11000 duplicate key error collection: blog.users index: email_1 dup key