giip
SES Proposal
SQL Server参照のみログファイルトランザクション監視RDS

How to Check Transaction Log Usage on RDS for SQL Server

公開日 2026-08-13 · 更新日 2026-08-13 · 最終検証日 2026-08-13

結論

To check transaction log usage, use `DBCC SQLPERF(LOGSPACE)` for the whole instance, or `sys.dm_db_log_space_usage` (SQL Server 2012 and later) for a specific database. If usage does not go down, check `log_reuse_wait_desc` in `sys.databases` — the reason the log cannot be reused appears in this single column. All the check SQL here is read-only and can also be run on Amazon RDS.

この文書の適用条件

対象製品SQL Server / Amazon RDS for SQL Server / Azure SQL Managed Instance
確認バージョンSQL Server 2008 and later (`sys.dm_db_log_space_usage` requires SQL Server 2012 or later)
適用環境On-premises, EC2, Amazon RDS, Azure
必要権限`DBCC SQLPERF(LOGSPACE)` and `sys.dm_db_log_space_usage` require VIEW SERVER STATE. `sys.databases` follows metadata visibility rules
実行影響Read-only (does not change data, settings, or log contents)
再起動Not required
最終検証日2026-08-13

そのまま実行できるコマンド

Log usage for all databases on the instance (DBCC SQLPERF)参照のみ
対象
SQL Server 2008 and later / Amazon RDS for SQL Server
権限
VIEW SERVER STATE
変更作業
None (read-only)
Production実行
Safe to run
-- 対象: SQL Server 2008 以降 / Amazon RDS for SQL Server
-- 権限: VIEW SERVER STATE
-- 変更作業: なし(参照のみ)
-- Production 実行: 可能
DBCC SQLPERF(LOGSPACE);

Returns one row per database on the instance, showing the current log file size (MB) and usage (%). Use this first to identify which database's log is filling up.

Breakdown of log usage for the connected database (SQL Server 2012 and later)参照のみ
対象
SQL Server 2012 and later / Amazon RDS for SQL Server
権限
VIEW SERVER STATE
変更作業
None (read-only)
Production実行
Safe to run
-- 対象: SQL Server 2012 以降 / Amazon RDS for SQL Server
-- 権限: VIEW SERVER STATE
-- 変更作業: なし(参照のみ)
-- Production 実行: 可能
USE [SampleDB];
GO
SELECT
    DB_NAME(database_id)                                AS database_name,
    total_log_size_in_bytes / 1024 / 1024               AS total_log_size_mb,
    used_log_space_in_bytes / 1024 / 1024               AS used_log_space_mb,
    used_log_space_in_percent                           AS used_log_space_pct,
    log_space_in_bytes_since_last_backup / 1024 / 1024  AS log_since_last_backup_mb
FROM sys.dm_db_log_space_usage;

This dynamic management view returns only the one currently connected database. To check multiple databases, switch with `USE`, or get the overall picture first with `DBCC SQLPERF(LOGSPACE)`. `log_space_in_bytes_since_last_backup` is the amount of log generated since the last log backup.

Checking why a log is not being released (log_reuse_wait_desc)参照のみ
対象
SQL Server 2008 and later / Amazon RDS for SQL Server
権限
Metadata visibility on `sys.databases` (equivalent to VIEW ANY DATABASE)
変更作業
None (read-only)
Production実行
Safe to run
-- 対象: SQL Server 2008 以降 / Amazon RDS for SQL Server
-- 権限: sys.databases のメタデータ可視性
-- 変更作業: なし(参照のみ)
-- Production 実行: 可能
SELECT
    d.name                  AS database_name,
    d.state_desc            AS database_state,
    d.recovery_model_desc   AS recovery_model,
    d.log_reuse_wait        AS log_reuse_wait_id,
    d.log_reuse_wait_desc   AS log_reuse_wait_desc,
    d.is_cdc_enabled        AS is_cdc_enabled,
    d.is_published          AS is_published,
    d.is_subscribed         AS is_subscribed
FROM sys.databases AS d
WHERE d.database_id > 4        -- システムデータベースを除外
ORDER BY d.name;

This is the most important column in this article. The main values mean: NOTHING = nothing is blocking reuse. CHECKPOINT = checkpoint not yet complete (usually temporary). LOG_BACKUP = waiting for a log backup under the full/bulk-logged recovery model. ACTIVE_TRANSACTION = an open transaction exists. REPLICATION = transactional replication or CDC is holding unread log. AVAILABILITY_REPLICA = synchronization to an availability group secondary is lagging. DATABASE_MIRRORING = mirroring is suspended or lagging. ACTIVE_BACKUP_OR_RESTORE = a backup or restore is in progress. You may also see DATABASE_SNAPSHOT_CREATION, LOG_SCAN, OLDEST_PAGE, XTP_CHECKPOINT, and others.

Log file size, free space, and autogrowth settings参照のみ
対象
SQL Server 2008 and later / Amazon RDS for SQL Server
権限
Connection permission to the target DB
変更作業
None (read-only)
Production実行
Safe to run
-- 対象: SQL Server 2008 以降 / Amazon RDS for SQL Server
-- 権限: 対象DBへの接続権限
-- 変更作業: なし(参照のみ)
-- Production 実行: 可能
USE [SampleDB];
GO
SELECT
    DB_NAME()                                   AS database_name,
    f.file_id,
    f.name                                      AS logical_name,
    f.type_desc,
    f.size * 8 / 1024                           AS current_size_mb,
    CASE
        WHEN f.max_size IN (-1, 268435456) THEN NULL   -- 無制限扱い
        ELSE f.max_size * 8 / 1024
    END                                         AS max_size_mb,
    CASE
        WHEN f.is_percent_growth = 1 THEN CAST(f.growth AS varchar(10)) + ' %'
        ELSE CAST(f.growth * 8 / 1024 AS varchar(10)) + ' MB'
    END                                         AS autogrowth,
    (f.size - CAST(FILEPROPERTY(f.name, 'SpaceUsed') AS bigint)) * 8 / 1024 AS free_space_mb
FROM sys.database_files AS f
WHERE f.type_desc = 'LOG';

If `max_size` on a log file is -1 (or 268435456), it is treated as unlimited. When autogrowth is set as a "%", the growth increment balloons as the file gets larger, so a fixed MB value is easier to manage.

結果の読み方

意味確認するポイント
Database NameThe database name returned by `DBCC SQLPERF(LOGSPACE)`Identify which database's log is filling up
Log Size (MB)Current size of the log fileIf larger than expected, autogrowth has likely fired repeatedly in the past
Log Space Used (%)Log usage percentageIf it stays high or does not drop, check `log_reuse_wait_desc`
used_log_space_in_percentUsage percentage returned by `sys.dm_db_log_space_usage`Sample every few minutes and watch whether it drops; if it does not, release is being blocked
log_space_in_bytes_since_last_backupAmount of log generated since the last log backupIf it keeps growing, a log backup may not be happening
recovery_model_descRecovery model (FULL / BULK_LOGGED / SIMPLE)If FULL but there is no log backup, the log will not be released
log_reuse_wait_descReason the log cannot be reusedA value other than NOTHING that persists points to the root cause
is_cdc_enabled / is_publishedWhether CDC / replication is enabledWhen `log_reuse_wait_desc = REPLICATION`, use this to tell which one is responsible

こういう状況で使います

  • Only the log file keeps growing, and storage free space keeps shrinking
  • Writes fail with error 9002, "The transaction log for the database is full"
  • Shrinking the log only causes it to grow back to its original size almost immediately
  • Log usage does not drop even though automated backups are configured on Amazon RDS

考えられる原因(可能性の高い順)

  1. 01

    Recovery model is FULL but no log backups are being taken (LOG_BACKUP)

    Under the full recovery model, log space is not reused until a log backup is taken. The most common cause of this symptom is setting the recovery model to FULL without ever setting up a log backup routine.

  2. 02

    A transaction has been open for a long time (ACTIVE_TRANSACTION)

    Log records after the oldest uncommitted transaction cannot be truncated. This happens when an application leaves a `BEGIN TRAN` open, or a batch job has crashed and is mid-rollback.

  3. 03

    Replication or CDC is holding unread log (REPLICATION)

    If the Log Reader Agent for transactional replication, or the CDC capture job, has stopped, log that has not yet been read stays unreleased.

  4. 04

    Availability group / mirroring synchronization lag (AVAILABILITY_REPLICA / DATABASE_MIRRORING)

    Log is retained until it has been sent to and applied on the secondary. A stopped secondary or network lag causes log to accumulate.

  5. 05

    A long-running backup or restore is in progress (ACTIVE_BACKUP_OR_RESTORE)

    The log cannot be truncated while a large database backup is running. Check whether the issue resolves once the backup completes.

  6. 06

    A large update within a single transaction

    Running a bulk delete or update of tens of millions of rows as one transaction requires log space for the whole operation until it commits. Log size depends on how transactions are scoped.

確認手順

  1. 1

    Get log usage for all databases

    参照のみ

    Run `DBCC SQLPERF(LOGSPACE)` to identify databases with high usage.

  2. 2

    Check `log_reuse_wait_desc`

    参照のみ

    Query `sys.databases` and see whether the value persists as something other than NOTHING. This largely determines the category of the cause.

  3. 3

    Cross-check the recovery model against log backup history

    参照のみ

    If `recovery_model_desc` is FULL, filter `msdb.dbo.backupset` on `type = 'L'` (log backup) to check the time of the most recent log backup.

  4. 4

    Find any open transactions

    参照のみ

    If `log_reuse_wait_desc = ACTIVE_TRANSACTION`, identify the oldest transaction using `sys.dm_tran_active_transactions` or similar.

  5. 5

    Check the state of CDC / replication

    参照のみ

    If `log_reuse_wait_desc = REPLICATION`, check whether the CDC capture job and the Log Reader Agent are running.

  6. 6

    Re-sample every few minutes and watch the trend

    参照のみ

    A transient CHECKPOINT or LOG_SCAN value will return to NOTHING on the next sample. Do not judge based on a single reading.

対応方法

すぐに実施できる低リスクの対応

  • Resolve the underlying cause first

    Resolving whatever `log_reuse_wait_desc` points to — an open transaction, a stopped CDC job, a lagging secondary — lets usage drop on the next log truncation. Do this before touching the file itself.

  • Check whether log backups are actually happening

    参照のみ

    On-premises or on EC2, check whether the log backup job is succeeding. On Amazon RDS, backups are managed by RDS itself, so check that the backup retention setting is consistent with the recovery model.

  • Free up space temporarily

    In an emergency where writes have stopped, check the log file's autogrowth ceiling and available disk space, and if necessary revisit the log file's max size and growth settings. Changing these settings affects file size.

事前検討が必要な変更

  • Split large updates into batches

    Split bulk deletes/updates into transactions of a few thousand to tens of thousands of rows and commit frequently. This caps the amount of log a single transaction holds.

  • Revisit autogrowth settings

    Change a "%" growth setting to a fixed MB value, and set an initial size large enough to absorb the expected peak. Fewer growth events also reduces virtual log file (VLF) fragmentation.

  • Align the recovery model with business requirements

    If point-in-time recovery is not needed, SIMPLE is an option. However, SIMPLE rules out point-in-time recovery, so business sign-off is required. On Amazon RDS, also confirm consistency with automated backups.

  • Continuously monitor log usage

    参照のみ

    Periodically sample usage and `log_reuse_wait_desc`, and set up an alert for when a value other than NOTHING persists for a set duration.

再起動・サービス影響を伴う変更

  • Shrink the log file

    Do this only after resolving the cause, solely to reclaim space that ballooned. Shrinking while the cause remains just leads to re-growth, and each growth event stalls writes. See the related article for the procedure and cautions.

  • Forcibly terminate an open session

    `KILL` rolls back an uncommitted transaction. The rollback itself needs time and log space, so confirm the scope of impact and get business sign-off first.

!注意事項

  • On Amazon RDS for SQL Server, backups are managed by RDS. Running `BACKUP LOG` directly is not a supported operational pattern, so check log backup status by confirming that the backup retention setting matches the recovery model. Availability and behavior vary by engine version and option, so always verify on the target environment.
  • Even when `log_reuse_wait_desc` is not NOTHING, values like CHECKPOINT or LOG_SCAN are transient. Do not conclude there is a problem from a single reading.
  • Changing the recovery model from FULL to SIMPLE breaks the log chain, ruling out point-in-time recovery. Reverting requires taking a fresh full backup.
  • Shrinking a file to free up space does not help if the underlying cause remains — it will simply grow again. Shrinking is not a substitute for resolving the cause.
  • While error 9002 is occurring, write transactions are failing. Communicate the business impact in parallel with investigating the cause, not after.

バージョン・環境による違い

SQL Server 2008 / 2008 R2`sys.dm_db_log_space_usage` is not available. Check using `DBCC SQLPERF(LOGSPACE)` and `log_reuse_wait_desc` in `sys.databases`.
SQL Server 2012 and later`sys.dm_db_log_space_usage` is available, giving a byte-level breakdown and the amount of log generated since the last log backup.
Amazon RDS for SQL ServerThe read-only DMVs and catalog views work as-is. Backup and restore follow RDS-specific procedures, so runbooks that assume direct `BACKUP LOG` usage do not apply as written.

これで解決しない場合に確認すること

  • Start time of the oldest transaction

    If ACTIVE_TRANSACTION persists, identify which session has had a transaction open, and since when.

  • Status of the CDC capture job and Log Reader Agent

    If REPLICATION persists, check whether the capture side has stopped, or whether data is backing up on the distribution database side.

  • Number of virtual log files (VLFs)

    Check the VLF count with `DBCC LOGINFO` (or `sys.dm_db_log_info` depending on version). An extremely high count slows down recovery and log processing.

  • Free space and IOPS on the storage side

    When log growth is failing, the cause may lie with storage rather than the database itself.

この文書の根拠と限界

製品の公式ドキュメントに基づく説明

A general procedure based on the public specifications of SQL Server's `DBCC SQLPERF(LOGSPACE)`, `sys.dm_db_log_space_usage`, `sys.databases` (`log_reuse_wait_desc`), and `sys.database_files`. Amazon RDS-specific behavior can vary by environment and engine version, so this assumes verification on the target environment.

よくある質問

Can this be run in production?

All four SQL statements in this article are read-only and change neither data nor settings. They can be run as-is in production. Shrinking the log file or changing the recovery model are separate actions that require checking their impact beforehand.

Does this work on AWS RDS?

Yes. `DBCC SQLPERF(LOGSPACE)`, `sys.dm_db_log_space_usage`, and `sys.databases` can all be queried on Amazon RDS for SQL Server. However, since running `BACKUP LOG` directly is not a supported pattern on RDS, check log backup status through the backup retention setting instead.

What permissions are required?

`DBCC SQLPERF(LOGSPACE)` and `sys.dm_db_log_space_usage` require VIEW SERVER STATE. `sys.databases` follows metadata visibility rules, so databases you lack permission on will not appear in the results.

Does shrinking the log solve the problem?

No. Shrinking only reduces the size; it does not address why the log is not being released. Unless you resolve whatever `log_reuse_wait_desc` points to, the log will grow again after shrinking.

Should I choose FULL or SIMPLE?

It depends on business requirements. If you need to recover to an arbitrary point in time during an incident, FULL combined with a log backup routine is required. If recovering to the most recent daily backup is sufficient, SIMPLE is an option, but business sign-off is needed since point-in-time recovery becomes impossible.

How should I interpret the results?

High usage by itself is not abnormal. Treat it as worth investigating when usage does not drop across repeated samples a few minutes apart, and `log_reuse_wait_desc` stays fixed at something other than NOTHING — investigate whatever that value indicates.

この文書がカバーする質問

  • I want to know why my SQL Server transaction log is not shrinking
  • I want to look up the meaning of log_reuse_wait_desc values
  • How do log backups work on RDS for SQL Server

リスク表示の意味

  • 参照のみデータと設定を変更しません。
  • 影響は限定的ですが、権限と負荷の確認が必要です。
  • 性能・ロック・コストに影響する可能性があります。
  • 障害・データ損失・復旧作業が発生する可能性があります。
  • 専門家レビュー必須本番適用前に別途レビューが必須です。

GIIPの対応範囲

Checking log usage itself is done the moment you run the SQL above once. The hard part is doing this continuously across multiple instances and catching the exact moment `log_reuse_wait_desc` changes to something other than NOTHING. At GIIP, AI agents periodically pull state from multiple databases on AWS and Azure, escalating only threshold-crossing changes to a human. For events like log bloat — where "by the time you notice, writes have already stopped" — detecting the change matters more than the value itself for response time.

執筆・技術検証

GIIP プロダクション運用チーム

大規模Webサービス、SQL Server、Oracle、AWS、Azureの設計・移行・運用に約30年従事。x12largeクラスのAWS RDS for SQL Server環境12セット、約12万テーブルのOracle環境、約3TBのTiDBからAurora MySQLへの移行を経験。現在も複数のクラウドデータベースと約30のWebサービスを、AIエージェントと人間の専門家が継続的に監視・運用しています。

関連するナレッジ

関連サービス

Request emergency response for log bloat

同じ確認を複数の環境で継続する必要がある場合は、運用体制ごと相談できます。

Request emergency response for log bloat

ナレッジベース一覧へ